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.
Publish release and run artifacts as file trees
5f2a0b0a7f84ec1bb43af5213e5c788039b72222 · Keenan Nemetz · 20d ago · parent 6d574bec
Publish release and run artifacts as file trees Release pointers and run outputs are now slash-separated paths. A flat name is a one-segment path, so every existing release, pointer, URL, and workflow that uses dist/* keeps working. - metadata validates artifact paths, lists and loads them recursively, and refuses a tag that would make the tag/path boundary ambiguous - vole release attach keeps a directory's relative paths; a plain file keeps its base name - a workflow match is published relative to the declaration's static root, so dist/* stays flat while dist/*/* keeps one directory level - release and run download routes accept nested paths; Content-Disposition still saves the base name - one internal rule is shared by the pointer writer, metadata validator, run record, CLI, and routes so they cannot disagree Refs: 01M7BPH6RRPK2934FCHVJPQNGY
metadata/releases.go +48−34
| @@ -1,7 +1,10 @@ | |||
| 1 | 1 | // Release artifacts are the files attached to a release. | |
| 2 | 2 | // | |
| 3 | // The artifact list is a directory on the metadata branch: releases/<tag>/<name> | ||
| 4 | // holds a standard git-lfs pointer blob, and the pointer is the whole record. | ||
| 3 | // The artifact list is a directory tree on the metadata branch: | ||
| 4 | // releases/<tag>/<path> holds a standard git-lfs pointer blob, and the pointer is | ||
| 5 | // the whole record. A path is slash-separated and may be one segment (the flat | ||
| 6 | // names every existing release uses) or a tree such as apt/Packages or | ||
| 7 | // yum/repodata/repomd.xml. | ||
| 5 | 8 | // Nothing else names the bytes, which is deliberate: | |
| 6 | 9 | // | |
| 7 | 10 | // - gc marks LFS objects named by pointer blobs in any tree reachable from any | |
| @@ -24,9 +27,11 @@ import ( | |||
| 24 | 27 | ||
| 25 | 28 | "rodent.software/vole/core/git" | |
| 26 | 29 | "rodent.software/vole/core/lfs" | |
| 30 | "rodent.software/vole/internal/artifactpath" | ||
| 27 | 31 | ) | |
| 28 | 32 | ||
| 29 | // Artifact is one file attached to a release. | ||
| 33 | // Artifact is one file attached to a release. Name is the slash-separated path | ||
| 34 | // under releases/<tag>/, so a flat attachment is one segment. | ||
| 30 | 35 | type Artifact struct { | |
| 31 | 36 | Name string | |
| 32 | 37 | OID string | |
| @@ -34,33 +39,18 @@ type Artifact struct { | |||
| 34 | 39 | } | |
| 35 | 40 | ||
| 36 | 41 | // Path is where an artifact's pointer lives on the metadata branch. | |
| 37 | func ReleasePath(tag, name string) string { return ReleasesDir + "/" + tag + "/" + name } | ||
| 42 | func ReleasePath(tag, path string) string { return ReleasesDir + "/" + tag + "/" + path } | ||
| 38 | 43 | ||
| 39 | // ValidName rejects artifact names that would not be one path segment under the | ||
| 40 | // release's directory. A name is a filename, not a path: allowing "/" would let | ||
| 41 | // an attach write outside releases/<tag>/, and the download route could not name | ||
| 42 | // the result. | ||
| 43 | func ValidReleaseName(name string) error { | ||
| 44 | switch { | ||
| 45 | case name == "": | ||
| 46 | return fmt.Errorf("an artifact needs a name") | ||
| 47 | case name == "." || name == "..": | ||
| 48 | return fmt.Errorf("%q is not a filename", name) | ||
| 49 | case strings.ContainsAny(name, "/\\"): | ||
| 50 | return fmt.Errorf("artifact name %q contains a path separator; attach a file, not a path tree", name) | ||
| 51 | case len(name) > 200: | ||
| 52 | return fmt.Errorf("artifact name is %d bytes, limit 200", len(name)) | ||
| 53 | case strings.ContainsAny(name, "\x00\n\r\t"): | ||
| 54 | return fmt.Errorf("artifact name %q contains a control character", name) | ||
| 55 | } | ||
| 56 | return nil | ||
| 57 | } | ||
| 44 | // ValidArtifactPath checks an artifact path under releases/<tag>/. The rule is | ||
| 45 | // shared with run outputs and with the download routes, so a path one layer | ||
| 46 | // writes is a path the next layer can name. | ||
| 47 | func ValidArtifactPath(path string) error { return artifactpath.Valid(path) } | ||
| 58 | 48 | ||
| 59 | // List reads the artifacts of one tag, sorted by name. A tag with nothing | ||
| 49 | // List reads the artifacts of one tag, sorted by path. A tag with nothing | ||
| 60 | 50 | // attached is an empty list rather than an error: the directory only exists once | |
| 61 | 51 | // something is attached to it. | |
| 62 | 52 | func ListReleaseArtifacts(g *git.Repo, tag string) ([]Artifact, error) { | |
| 63 | entries, err := g.LsTree("refs/heads/vole:" + ReleasesDir + "/" + tag) | ||
| 53 | entries, err := g.LsTreeR("refs/heads/vole:" + ReleasesDir + "/" + tag) | ||
| 64 | 54 | if err != nil { | |
| 65 | 55 | return nil, nil // no releases/<tag>/ directory: no artifacts | |
| 66 | 56 | } | |
| @@ -69,6 +59,11 @@ func ListReleaseArtifacts(g *git.Repo, tag string) ([]Artifact, error) { | |||
| 69 | 59 | if e.Type != "blob" { | |
| 70 | 60 | continue | |
| 71 | 61 | } | |
| 62 | if err := ValidArtifactPath(e.Name); err != nil { | ||
| 63 | // The validator refuses these at push time; a reader skips a path a | ||
| 64 | // human put there by hand rather than naming it in a link. | ||
| 65 | continue | ||
| 66 | } | ||
| 72 | 67 | data, err := g.BlobAt("refs/heads/vole", ReleasePath(tag, e.Name)) | |
| 73 | 68 | if err != nil { | |
| 74 | 69 | return nil, fmt.Errorf("read artifact pointer %s: %w", e.Name, err) | |
| @@ -88,7 +83,7 @@ func ListReleaseArtifacts(g *git.Repo, tag string) ([]Artifact, error) { | |||
| 88 | 83 | ||
| 89 | 84 | // Problems validates the releases/ portion of the metadata tree at commit. The | |
| 90 | 85 | // layout is closed for the same reason the rest of the metadata branch is: a file | |
| 91 | // that is not releases/<tag>/<name> pointing at an object nobody uploaded is | ||
| 86 | // that is not releases/<tag>/<path> pointing at an object nobody uploaded is | ||
| 92 | 87 | // either a mistake or a download that will 404, and both are cheaper to refuse | |
| 93 | 88 | // here than to discover later. | |
| 94 | 89 | func ReleaseProblems(g *git.Repo, commit string) []string { | |
| @@ -105,18 +100,24 @@ func ReleaseProblems(g *git.Repo, commit string) []string { | |||
| 105 | 100 | if !strings.HasPrefix(e.Name, ReleasesDir+"/") { | |
| 106 | 101 | continue | |
| 107 | 102 | } | |
| 108 | parts := strings.Split(e.Name, "/") | ||
| 103 | // The tag is one segment; the artifact is everything after it. A tag | ||
| 104 | // containing '/' cannot be told apart from a path here, and the attach | ||
| 105 | // writer refuses it for the same reason. | ||
| 106 | parts := strings.SplitN(e.Name, "/", 3) | ||
| 109 | 107 | switch { | |
| 110 | 108 | case len(parts) != 3: | |
| 111 | 109 | problems = append(problems, fmt.Sprintf( | |
| 112 | "%s: releases are %s/<tag>/<name>; a release directory holds files, not more directories", | ||
| 113 | e.Name, ReleasesDir)) | ||
| 110 | "%s: releases are %s/<tag>/<path>", e.Name, ReleasesDir)) | ||
| 114 | 111 | continue | |
| 115 | 112 | case parts[1] == "": | |
| 116 | 113 | problems = append(problems, fmt.Sprintf("%s: missing tag name", e.Name)) | |
| 117 | 114 | continue | |
| 118 | 115 | } | |
| 119 | if err := ValidReleaseName(parts[2]); err != nil { | ||
| 116 | if err := ValidArtifactPath(parts[1]); err != nil { | ||
| 117 | problems = append(problems, fmt.Sprintf("%s: invalid release tag: %v", e.Name, err)) | ||
| 118 | continue | ||
| 119 | } | ||
| 120 | if err := ValidArtifactPath(parts[2]); err != nil { | ||
| 120 | 121 | problems = append(problems, e.Name+": "+err.Error()) | |
| 121 | 122 | continue | |
| 122 | 123 | } | |
| @@ -146,9 +147,20 @@ func TagWithArtifacts(g *git.Repo, tag string) bool { | |||
| 146 | 147 | } | |
| 147 | 148 | ||
| 148 | 149 | // WritePointers records artifacts on the metadata branch, one literal LFS | |
| 149 | // pointer per name. It starts from the branch's current tree, so applying it | ||
| 150 | // pointer per path. It starts from the branch's current tree, so applying it | ||
| 150 | 151 | // again after a lost push race is idempotent. | |
| 151 | 152 | func WriteReleasePointers(g *git.Repo, ref, tag string, arts []Artifact, message, author string) error { | |
| 153 | if strings.Contains(tag, "/") { | ||
| 154 | return fmt.Errorf("release tag %q must not contain '/'; an artifact path is ambiguous after it", tag) | ||
| 155 | } | ||
| 156 | if err := ValidArtifactPath(tag); err != nil { | ||
| 157 | return fmt.Errorf("release tag %q: %w", tag, err) | ||
| 158 | } | ||
| 159 | for _, a := range arts { | ||
| 160 | if err := ValidArtifactPath(a.Name); err != nil { | ||
| 161 | return err | ||
| 162 | } | ||
| 163 | } | ||
| 152 | 164 | _, err := git.CommitFiles(g, ref, func(files map[string][]byte) error { | |
| 153 | 165 | for _, a := range arts { | |
| 154 | 166 | files[ReleasePath(tag, a.Name)] = lfs.Pointer{OID: a.OID, Size: a.Size}.Encode() | |
| @@ -176,8 +188,10 @@ func LoadArtifactsAt(g *git.Repo, commit string) (map[string][]Artifact, error) | |||
| 176 | 188 | if e.Type != "blob" || !strings.HasPrefix(e.Name, ReleasesDir+"/") { | |
| 177 | 189 | continue | |
| 178 | 190 | } | |
| 179 | // releases/<tag>/<name>; anything deeper is not an artifact. | ||
| 180 | if parts := strings.Split(e.Name, "/"); len(parts) != 3 { | ||
| 191 | // releases/<tag>/<path>; the tag is one segment and the path may be | ||
| 192 | // nested. A malformed hand edit is skipped, not served. | ||
| 193 | parts := strings.SplitN(e.Name, "/", 3) | ||
| 194 | if len(parts) != 3 || ValidArtifactPath(parts[1]) != nil || ValidArtifactPath(parts[2]) != nil { | ||
| 181 | 195 | continue | |
| 182 | 196 | } | |
| 183 | 197 | paths = append(paths, e.Name) | |
| @@ -188,7 +202,7 @@ func LoadArtifactsAt(g *git.Repo, commit string) (map[string][]Artifact, error) | |||
| 188 | 202 | return nil, err | |
| 189 | 203 | } | |
| 190 | 204 | for _, path := range paths { | |
| 191 | parts := strings.Split(path, "/") | ||
| 205 | parts := strings.SplitN(path, "/", 3) | ||
| 192 | 206 | p, ok := lfs.ParsePointer([]byte(files[path])) | |
| 193 | 207 | if !ok { | |
| 194 | 208 | // A file that is not a pointer is not an artifact; the release | |