vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Add named release channels and a generic channel file route
24019cb30892b9fc0118697e8b89cd61e9fab576 · Keenan Nemetz · 19d ago · parent 4f8a3da8
Add named release channels and a generic channel file route A channel is a mutable pointer, channels/<name>.md, to one immutable annotated release. The target tag object is recorded so a rewritten tag is detected rather than silently followed. - metadata: channel parse/render/validate, closed-layout and size checks, set/clear writers - CLI: vole release channel set|list|clear; a dangling target is reported - server: maintain/admin path gate and audit for channel.set/clear - index: release_channels table, incremental refresh, per-tag badge query - web: /channels list, /channels/<name> redirect, and /channels/<name>/<path...> serving the target release's tree with OID ETags, Range, revalidation, and octet-stream responses - tests: metadata round trips, index moves, hook role/audit, page/tree/dangling/ private, and the CLI end to end No apt, yum, or other package-manager code is involved: a package layout is a directory in the release tree. Refs: 01M7BPHANWMSW5HK2GT0PY74QZ
cmd/vole/channel.go +214
| @@ -0,0 +1,214 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | // `vole release channel` promotes a release to a stable name. A channel is a | ||
| 4 | // mutable pointer on the metadata branch, never a second tag: moving it is one | ||
| 5 | // commit, and the release it names keeps its bytes. | ||
| 6 | |||
| 7 | import ( | ||
| 8 | "fmt" | ||
| 9 | "os" | ||
| 10 | "strings" | ||
| 11 | "time" | ||
| 12 | |||
| 13 | "rodent.software/vole/client" | ||
| 14 | "rodent.software/vole/metadata" | ||
| 15 | ) | ||
| 16 | |||
| 17 | var releaseChannelGroup = &group{ | ||
| 18 | Name: "release channel", | ||
| 19 | Summary: "a stable name for the release it currently points at", | ||
| 20 | Flags: releaseGroup.Flags, | ||
| 21 | Subs: []subcommand{ | ||
| 22 | {Name: "set", Synopsis: "release channel set <name> <tag> (-m <text> | -F <file|->) [--remote <name>]", Flags: []string{"message", "file", "remote"}, Notes: []string{"Points the channel at an annotated tag. The channel keeps its name; the release it names is immutable. `-m`/`-F` are an optional short description shown on the channel page."}}, | ||
| 23 | {Name: "list", Synopsis: "release channel list [--remote <name>]", Flags: []string{"remote"}, Notes: []string{"Prints every channel, its target tag, and whether the target is still an annotated tag with the recorded object id."}}, | ||
| 24 | {Name: "clear", Synopsis: "release channel clear <name> [--remote <name>]", Flags: []string{"remote"}, Notes: []string{"Removes the pointer. The release it named and its files stay; only the stable name stops resolving."}}, | ||
| 25 | }, | ||
| 26 | Notes: []string{ | ||
| 27 | "A channel serves the target release's attached file tree under\n" + | ||
| 28 | "/<repo>/channels/<name>/<path>, so a package layout is just paths in the\n" + | ||
| 29 | "release. The forge does not know about apt, yum, or any other client.", | ||
| 30 | }, | ||
| 31 | See: []seeAlso{{"Releases", "releases.md"}}, | ||
| 32 | } | ||
| 33 | |||
| 34 | func cmdReleaseChannel(args []string) error { | ||
| 35 | if len(args) == 0 { | ||
| 36 | fmt.Fprint(os.Stderr, renderHelpText(releaseChannelGroup)) | ||
| 37 | return usageErr{msg: "no release channel subcommand given"} | ||
| 38 | } | ||
| 39 | if args[0] == "-h" || args[0] == "--help" || args[0] == "help" { | ||
| 40 | fmt.Print(renderHelpText(releaseChannelGroup)) | ||
| 41 | return nil | ||
| 42 | } | ||
| 43 | switch args[0] { | ||
| 44 | case "set": | ||
| 45 | return cmdReleaseChannelSet(args[1:]) | ||
| 46 | case "list": | ||
| 47 | return cmdReleaseChannelList(args[1:]) | ||
| 48 | case "clear": | ||
| 49 | return cmdReleaseChannelClear(args[1:]) | ||
| 50 | } | ||
| 51 | fmt.Fprint(os.Stderr, renderHelpText(releaseChannelGroup)) | ||
| 52 | return usagef("unknown release channel subcommand %q", args[0]) | ||
| 53 | } | ||
| 54 | |||
| 55 | func cmdReleaseChannelSet(args []string) error { | ||
| 56 | f, err := parseFlags(args, releaseGroup.Flags...) | ||
| 57 | if err != nil { | ||
| 58 | return err | ||
| 59 | } | ||
| 60 | if f.help { | ||
| 61 | fmt.Print(renderHelpText(releaseChannelGroup)) | ||
| 62 | return nil | ||
| 63 | } | ||
| 64 | if err := f.checkAllowed("vole release channel set"); err != nil { | ||
| 65 | return err | ||
| 66 | } | ||
| 67 | if len(f.rest) != 2 { | ||
| 68 | return usagef("usage: vole release channel set <name> <tag> (-m <text> | -F <file|->) [--remote <name>]") | ||
| 69 | } | ||
| 70 | name, tag := f.rest[0], f.rest[1] | ||
| 71 | if err := metadata.ValidChannelName(name); err != nil { | ||
| 72 | return err | ||
| 73 | } | ||
| 74 | description, err := readBody(f) | ||
| 75 | if err != nil { | ||
| 76 | return err | ||
| 77 | } | ||
| 78 | |||
| 79 | c, err := client.NewBranch(f.one("remote"), metadata.Ref) | ||
| 80 | if err != nil { | ||
| 81 | return err | ||
| 82 | } | ||
| 83 | typ, err := c.Repo.Run(nil, "cat-file", "-t", "refs/tags/"+tag) | ||
| 84 | if err != nil { | ||
| 85 | return fmt.Errorf("no tag %s here; create and push the release first "+ | ||
| 86 | "(vole release create %s -F notes.md && git push --follow-tags)", tag, tag) | ||
| 87 | } | ||
| 88 | if strings.TrimSpace(string(typ)) != "tag" { | ||
| 89 | return fmt.Errorf("%s is a lightweight tag; a channel names an annotated release with notes", tag) | ||
| 90 | } | ||
| 91 | object, err := c.Repo.RevParseRaw("refs/tags/" + tag) | ||
| 92 | if err != nil { | ||
| 93 | return fmt.Errorf("read tag %s: %w", tag, err) | ||
| 94 | } | ||
| 95 | ch := metadata.Channel{ | ||
| 96 | Name: name, | ||
| 97 | Release: tag, | ||
| 98 | ReleaseObject: object, | ||
| 99 | UpdatedBy: c.Author, | ||
| 100 | UpdatedAt: time.Now().UTC(), | ||
| 101 | Description: description, | ||
| 102 | } | ||
| 103 | message := fmt.Sprintf("channel: %s -> %s", name, tag) | ||
| 104 | write := func() error { return metadata.WriteChannel(c.Repo, metadata.Ref, &ch, message, c.Author) } | ||
| 105 | if err := write(); err != nil { | ||
| 106 | return err | ||
| 107 | } | ||
| 108 | if err := c.CommitAndPush(false, write); err != nil { | ||
| 109 | return err | ||
| 110 | } | ||
| 111 | fmt.Printf("channel %s -> %s\n", name, tag) | ||
| 112 | return nil | ||
| 113 | } | ||
| 114 | |||
| 115 | func cmdReleaseChannelList(args []string) error { | ||
| 116 | f, err := parseFlags(args, releaseGroup.Flags...) | ||
| 117 | if err != nil { | ||
| 118 | return err | ||
| 119 | } | ||
| 120 | if f.help { | ||
| 121 | fmt.Print(renderHelpText(releaseChannelGroup)) | ||
| 122 | return nil | ||
| 123 | } | ||
| 124 | if err := f.checkAllowed("vole release channel list"); err != nil { | ||
| 125 | return err | ||
| 126 | } | ||
| 127 | if len(f.rest) != 0 { | ||
| 128 | return usageErr{msg: "usage: vole release channel list [--remote <name>]"} | ||
| 129 | } | ||
| 130 | c, err := client.NewBranch(f.one("remote"), metadata.Ref) | ||
| 131 | if err != nil { | ||
| 132 | return err | ||
| 133 | } | ||
| 134 | list, err := metadata.LoadChannelsAt(c.Repo, metadata.Ref) | ||
| 135 | if err != nil { | ||
| 136 | return err | ||
| 137 | } | ||
| 138 | if len(list) == 0 { | ||
| 139 | fmt.Println("no channels") | ||
| 140 | return nil | ||
| 141 | } | ||
| 142 | for _, ch := range list { | ||
| 143 | note := "" | ||
| 144 | if !channelTargetOK(c, ch) { | ||
| 145 | note = " (dangling)" | ||
| 146 | } | ||
| 147 | fmt.Printf("%s\t%s\t%s\t%s%s\n", ch.Name, ch.Release, ch.UpdatedBy, | ||
| 148 | ch.UpdatedAt.Format(time.RFC3339), note) | ||
| 149 | } | ||
| 150 | return nil | ||
| 151 | } | ||
| 152 | |||
| 153 | // channelTargetOK is the CLI's version of the web check: an annotated tag whose | ||
| 154 | // object id is still the one the pointer recorded. | ||
| 155 | func channelTargetOK(c *client.Branch, ch metadata.Channel) bool { | ||
| 156 | typ, err := c.Repo.Run(nil, "cat-file", "-t", "refs/tags/"+ch.Release) | ||
| 157 | if err != nil || strings.TrimSpace(string(typ)) != "tag" { | ||
| 158 | return false | ||
| 159 | } | ||
| 160 | object, err := c.Repo.RevParseRaw("refs/tags/" + ch.Release) | ||
| 161 | if err != nil { | ||
| 162 | return false | ||
| 163 | } | ||
| 164 | return strings.EqualFold(object, ch.ReleaseObject) | ||
| 165 | } | ||
| 166 | |||
| 167 | func cmdReleaseChannelClear(args []string) error { | ||
| 168 | f, err := parseFlags(args, releaseGroup.Flags...) | ||
| 169 | if err != nil { | ||
| 170 | return err | ||
| 171 | } | ||
| 172 | if f.help { | ||
| 173 | fmt.Print(renderHelpText(releaseChannelGroup)) | ||
| 174 | return nil | ||
| 175 | } | ||
| 176 | if err := f.checkAllowed("vole release channel clear"); err != nil { | ||
| 177 | return err | ||
| 178 | } | ||
| 179 | if len(f.rest) != 1 { | ||
| 180 | return usageErr{msg: "usage: vole release channel clear <name> [--remote <name>]"} | ||
| 181 | } | ||
| 182 | name := f.rest[0] | ||
| 183 | if err := metadata.ValidChannelName(name); err != nil { | ||
| 184 | return err | ||
| 185 | } | ||
| 186 | c, err := client.NewBranch(f.one("remote"), metadata.Ref) | ||
| 187 | if err != nil { | ||
| 188 | return err | ||
| 189 | } | ||
| 190 | list, err := metadata.LoadChannelsAt(c.Repo, metadata.Ref) | ||
| 191 | if err != nil { | ||
| 192 | return err | ||
| 193 | } | ||
| 194 | found := false | ||
| 195 | for _, ch := range list { | ||
| 196 | if ch.Name == name { | ||
| 197 | found = true | ||
| 198 | break | ||
| 199 | } | ||
| 200 | } | ||
| 201 | if !found { | ||
| 202 | return fmt.Errorf("no channel %s", name) | ||
| 203 | } | ||
| 204 | message := fmt.Sprintf("channel: clear %s", name) | ||
| 205 | write := func() error { return metadata.DeleteChannel(c.Repo, metadata.Ref, name, message, c.Author) } | ||
| 206 | if err := write(); err != nil { | ||
| 207 | return err | ||
| 208 | } | ||
| 209 | if err := c.CommitAndPush(false, write); err != nil { | ||
| 210 | return err | ||
| 211 | } | ||
| 212 | fmt.Printf("cleared channel %s\n", name) | ||
| 213 | return nil | ||
| 214 | } | ||