BlueGit

timfa bluegit

fix: haal het AUR-archief van BlueGit

publish_aur vroeg het GitLab-archief op en kreeg 404. De PKGBUILD en de job gebruiken nu het commit-archief op git.timfalken.com, publiek en met dezelfde bytes voor dezelfde sha.

Co-authored-by: tim <tim@timfalken.com>

timfa project_87923614_bot_3aff574f6f98414b945a8799374f9092 · pushed by timfa

Authored 2026-10-23 · 3 weeks ago

Hash
c66968f45cbdb853dadc2c45bcd24b004e6e0e24
Parent
02593963
Pipeline
Passed
8 files changed +261 −14
docs/AUR.md +10 −5
@@ -4,10 +4,10 @@ Elke push naar `master` werkt `packaging/aur/PKGBUILD` bij en pusht die naar `ss
4 4
5 5 ## Package
6 6
7 Er is één source-package, `bluegit`. Geen `-bin`. De PKGBUILD haalt de GitLab-archieven op:
7 Er is één source-package, `bluegit`. Geen `-bin`. De PKGBUILD haalt het archief van BlueGit op, op de commit-sha:
8 8
9 9 ```text
10 https://gitlab.com/Timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
10 https://git.timfalken.com/timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
11 11 ```
12 12
13 13 Die map heet `bluegit-<commit>`. `pkgver` is `YYYYMMDDHHMMSS`, de UTC-committertijd van de commit. De CI-job neemt `CI_COMMIT_TIMESTAMP` (ISO 8601). Ontbreekt die, dan neemt `publish-aur.sh` `git show -s --format=%cI` en rekent die om naar UTC. Het lokale script en de self-updater gebruiken dezelfde committer-tijd, zodat dezelfde sha dezelfde `pkgver` houdt. `pkgrel` gaat terug naar 1. `_commit` is de volledige sha. Het CI-script vult `sha256sums` met de hash van dat archief. Het lokale script doet hetzelfde met `updpkgsums`. Beide maken `.SRCINFO` opnieuw met `makepkg --printsrcinfo`. Draait de CI-job als root, dan doet gebruiker `aurbuild` dat (`AUR_MAKEPKG_USER` overschrijft de naam). De gedeelde functies staan in `scripts/aur-common.sh`.
@@ -103,10 +103,15 @@ De mini-PC heeft `base-devel`, `go` en `pacman-contrib` niet als package-depende
103 103
104 104 ## Archief
105 105
106 Het archief is anoniem te downloaden:
106 Het archief van een commit is anoniem te downloaden zolang de repository publiek is. Een token is niet nodig. `tar.gz` en `zip` bestaan allebei. De map in het archief heet `bluegit-<commit>`, met de volledige sha.
107 107
108 108 ```text
109 https://gitlab.com/Timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
109 https://git.timfalken.com/timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
110 https://git.timfalken.com/timfa/bluegit/-/archive/<commit>/bluegit-<commit>.zip
110 111 ```
111 112
112 De publish-job haalt die tarball zonder token op en zet de sha256 in de PKGBUILD. `makepkg` gebruikt dezelfde URL.
113 Twee downloads van dezelfde sha geven dezelfde bytes. `git archive` zet de gzip-mtime op 0, dus de klok zit niet in de checksum. `sha256sums` in de PKGBUILD hoort bij die url. Een andere git-versie op de server kan het archiefformaat wijzigen; dan klopt een al gepubliceerde checksum niet meer.
114
115 Een branch- of tagarchief (`/-/branches/archive`, `/-/tags/archive`) volgt de punt van die ref. Die url hoort niet in de PKGBUILD: de bytes veranderen zodra de ref opschuift, en dan breekt `sha256sums`.
116
117 De publish-job haalt de tarball zonder token op en zet de sha256 in de PKGBUILD. `makepkg` gebruikt dezelfde URL.
@@ -4,10 +4,10 @@ Elke push naar `master` werkt `packaging/aur/PKGBUILD` bij en pusht die naar `ss
4
4
5## Package
5## Package
6
6
7Er is één source-package, `bluegit`. Geen `-bin`. De PKGBUILD haalt de GitLab-archieven op:
7Er is één source-package, `bluegit`. Geen `-bin`. De PKGBUILD haalt het archief van BlueGit op, op de commit-sha:
8
8
9```text
9```text
10https://gitlab.com/Timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
10https://git.timfalken.com/timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
11```
11```
12
12
13Die map heet `bluegit-<commit>`. `pkgver` is `YYYYMMDDHHMMSS`, de UTC-committertijd van de commit. De CI-job neemt `CI_COMMIT_TIMESTAMP` (ISO 8601). Ontbreekt die, dan neemt `publish-aur.sh` `git show -s --format=%cI` en rekent die om naar UTC. Het lokale script en de self-updater gebruiken dezelfde committer-tijd, zodat dezelfde sha dezelfde `pkgver` houdt. `pkgrel` gaat terug naar 1. `_commit` is de volledige sha. Het CI-script vult `sha256sums` met de hash van dat archief. Het lokale script doet hetzelfde met `updpkgsums`. Beide maken `.SRCINFO` opnieuw met `makepkg --printsrcinfo`. Draait de CI-job als root, dan doet gebruiker `aurbuild` dat (`AUR_MAKEPKG_USER` overschrijft de naam). De gedeelde functies staan in `scripts/aur-common.sh`.
13Die map heet `bluegit-<commit>`. `pkgver` is `YYYYMMDDHHMMSS`, de UTC-committertijd van de commit. De CI-job neemt `CI_COMMIT_TIMESTAMP` (ISO 8601). Ontbreekt die, dan neemt `publish-aur.sh` `git show -s --format=%cI` en rekent die om naar UTC. Het lokale script en de self-updater gebruiken dezelfde committer-tijd, zodat dezelfde sha dezelfde `pkgver` houdt. `pkgrel` gaat terug naar 1. `_commit` is de volledige sha. Het CI-script vult `sha256sums` met de hash van dat archief. Het lokale script doet hetzelfde met `updpkgsums`. Beide maken `.SRCINFO` opnieuw met `makepkg --printsrcinfo`. Draait de CI-job als root, dan doet gebruiker `aurbuild` dat (`AUR_MAKEPKG_USER` overschrijft de naam). De gedeelde functies staan in `scripts/aur-common.sh`.
@@ -103,10 +103,15 @@ De mini-PC heeft `base-devel`, `go` en `pacman-contrib` niet als package-depende
103
103
104## Archief
104## Archief
105
105
106Het archief is anoniem te downloaden:
106Het archief van een commit is anoniem te downloaden zolang de repository publiek is. Een token is niet nodig. `tar.gz` en `zip` bestaan allebei. De map in het archief heet `bluegit-<commit>`, met de volledige sha.
107
107
108```text
108```text
109https://gitlab.com/Timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
109https://git.timfalken.com/timfa/bluegit/-/archive/<commit>/bluegit-<commit>.tar.gz
110https://git.timfalken.com/timfa/bluegit/-/archive/<commit>/bluegit-<commit>.zip
110```
111```
111
112
112De publish-job haalt die tarball zonder token op en zet de sha256 in de PKGBUILD. `makepkg` gebruikt dezelfde URL.
113Twee downloads van dezelfde sha geven dezelfde bytes. `git archive` zet de gzip-mtime op 0, dus de klok zit niet in de checksum. `sha256sums` in de PKGBUILD hoort bij die url. Een andere git-versie op de server kan het archiefformaat wijzigen; dan klopt een al gepubliceerde checksum niet meer.
114
115Een branch- of tagarchief (`/-/branches/archive`, `/-/tags/archive`) volgt de punt van die ref. Die url hoort niet in de PKGBUILD: de bytes veranderen zodra de ref opschuift, en dan breekt `sha256sums`.
116
117De publish-job haalt de tarball zonder token op en zet de sha256 in de PKGBUILD. `makepkg` gebruikt dezelfde URL.
internal/server/archive_test.go added +195 −0
@@ -0,0 +1,195 @@
1 package server
2
3 import (
4 "archive/tar"
5 "archive/zip"
6 "bytes"
7 "compress/gzip"
8 "crypto/sha256"
9 "encoding/hex"
10 "io"
11 "net/http"
12 "net/http/cookiejar"
13 "net/http/httptest"
14 "net/url"
15 "os/exec"
16 "path/filepath"
17 "strings"
18 "testing"
19
20 "gitlab.com/Timfa/bluegit/internal/auth"
21 "gitlab.com/Timfa/bluegit/internal/config"
22 "gitlab.com/Timfa/bluegit/internal/store"
23 )
24
25 func TestCommitArchivePublicAndStable(t *testing.T) {
26 if _, err := exec.LookPath("git"); err != nil {
27 t.Skip("git ontbreekt")
28 }
29 storage := t.TempDir()
30 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
31 if err != nil {
32 t.Fatal(err)
33 }
34 t.Cleanup(func() { _ = st.Close() })
35 cfg := config.Config{
36 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
37 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
38 Git: config.Git{Binary: "git", DefaultBranch: "master"},
39 }
40 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
41 ts := httptest.NewServer(srv.Handler())
42 t.Cleanup(ts.Close)
43 jar, _ := cookiejar.New(nil)
44 tim := &http.Client{Jar: jar}
45 anon := &http.Client{}
46
47 page := read(t, mustGet(t, tim, ts.URL+"/login"))
48 page = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
49 "csrf": {csrfOf(t, page)}, "name": {"archief"}, "visibility": {"public"},
50 }))
51 page = read(t, mustPost(t, tim, ts.URL+"/settings/tokens", url.Values{
52 "csrf": {csrfOf(t, page)}, "name": {"laptop"},
53 }))
54 token := between(page, `<p class="code">`, "</p>")
55 work := t.TempDir()
56 git(t, work, "init", "-b", "master")
57 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
58 git(t, work, "config", "user.name", "tim")
59 writeFile(t, filepath.Join(work, "hello.txt"), "alpha\n")
60 git(t, work, "add", "hello.txt")
61 git(t, work, "commit", "-m", "start")
62 remote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/archief.git"
63 git(t, work, "remote", "add", "origin", remote)
64 git(t, work, "push", "-u", "origin", "master")
65 sha := strings.TrimSpace(gitOutOK(t, work, "rev-parse", "HEAD"))
66
67 tarURL := ts.URL + "/tim/archief/-/archive/" + sha + "/archief-" + sha + ".tar.gz"
68 first := getBody(t, anon, tarURL)
69 second := getBody(t, anon, tarURL)
70 if first.code != http.StatusOK || !bytes.Equal(first.body, second.body) {
71 t.Fatalf("tar.gz %d, gelijk %v, lengte %d", first.code, bytes.Equal(first.body, second.body), len(first.body))
72 }
73 if len(first.body) < 2 || first.body[0] != 0x1f || first.body[1] != 0x8b {
74 t.Fatal("geen gzip")
75 }
76 if !strings.Contains(first.header.Get("Content-Disposition"), "archief-"+sha+".tar.gz") {
77 t.Fatalf("bestandsnaam: %s", first.header.Get("Content-Disposition"))
78 }
79 sum := sha256.Sum256(first.body)
80 if hex.EncodeToString(sum[:]) != hex.EncodeToString(sha256Sum(second.body)) {
81 t.Fatal("sha256 verschilt tussen twee downloads")
82 }
83 names := tarNames(t, first.body)
84 want := "archief-" + sha + "/hello.txt"
85 if !containsString(names, want) {
86 t.Fatalf("tar mist %s in %v", want, names)
87 }
88
89 zipURL := ts.URL + "/tim/archief/-/archive/" + sha + "/archief-" + sha + ".zip"
90 zipRes := getBody(t, anon, zipURL)
91 if zipRes.code != http.StatusOK || len(zipRes.body) < 2 || zipRes.body[0] != 'P' || zipRes.body[1] != 'K' {
92 t.Fatalf("zip %d", zipRes.code)
93 }
94 zr, err := zip.NewReader(bytes.NewReader(zipRes.body), int64(len(zipRes.body)))
95 if err != nil {
96 t.Fatal(err)
97 }
98 found := false
99 for _, f := range zr.File {
100 if f.Name == want {
101 found = true
102 }
103 }
104 if !found {
105 t.Fatalf("zip mist %s", want)
106 }
107 again := getBody(t, anon, zipURL)
108 if !bytes.Equal(zipRes.body, again.body) {
109 t.Fatal("zip verschilt tussen twee downloads")
110 }
111
112 for _, raw := range []string{
113 ts.URL + "/tim/archief/-/archive/" + sha[:12] + "/archief.tar.gz",
114 ts.URL + "/tim/archief/-/archive/master/archief-master.tar.gz",
115 ts.URL + "/tim/archief/-/archive/" + sha + "/archief-" + sha + ".tar.bz2",
116 ts.URL + "/tim/archief/-/archive/" + strings.Repeat("ab", 20) + "/archief.tar.gz",
117 } {
118 res := getBody(t, anon, raw)
119 if res.code != http.StatusNotFound {
120 t.Fatalf("%s: %d", raw, res.code)
121 }
122 }
123
124 page = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
125 "csrf": {csrfOf(t, page)}, "name": {"geheim"}, "visibility": {"private"},
126 }))
127 secret := t.TempDir()
128 git(t, secret, "init", "-b", "master")
129 git(t, secret, "config", "user.email", "tim@users.git.timfalken.com")
130 git(t, secret, "config", "user.name", "tim")
131 writeFile(t, filepath.Join(secret, "hello.txt"), "geheim\n")
132 git(t, secret, "add", "hello.txt")
133 git(t, secret, "commit", "-m", "geheim")
134 privRemote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/geheim.git"
135 git(t, secret, "remote", "add", "origin", privRemote)
136 git(t, secret, "push", "-u", "origin", "master")
137 privSHA := strings.TrimSpace(gitOutOK(t, secret, "rev-parse", "HEAD"))
138 hidden := getBody(t, anon, ts.URL+"/tim/geheim/-/archive/"+privSHA+"/geheim-"+privSHA+".tar.gz")
139 if hidden.code != http.StatusNotFound {
140 t.Fatalf("privé-archief: %d", hidden.code)
141 }
142 }
143
144 type bodyResult struct {
145 code int
146 header http.Header
147 body []byte
148 }
149
150 func getBody(t *testing.T, c *http.Client, raw string) bodyResult {
151 t.Helper()
152 res := mustGet(t, c, raw)
153 defer res.Body.Close()
154 body, err := io.ReadAll(res.Body)
155 if err != nil {
156 t.Fatal(err)
157 }
158 return bodyResult{code: res.StatusCode, header: res.Header, body: body}
159 }
160
161 func tarNames(t *testing.T, gz []byte) []string {
162 t.Helper()
163 zr, err := gzip.NewReader(bytes.NewReader(gz))
164 if err != nil {
165 t.Fatal(err)
166 }
167 defer zr.Close()
168 tr := tar.NewReader(zr)
169 var names []string
170 for {
171 hdr, err := tr.Next()
172 if err == io.EOF {
173 break
174 }
175 if err != nil {
176 t.Fatal(err)
177 }
178 names = append(names, hdr.Name)
179 }
180 return names
181 }
182
183 func sha256Sum(b []byte) []byte {
184 sum := sha256.Sum256(b)
185 return sum[:]
186 }
187
188 func containsString(list []string, want string) bool {
189 for _, item := range list {
190 if item == want {
191 return true
192 }
193 }
194 return false
195 }
@@ -0,0 +1,195 @@
1package server
2
3import (
4 "archive/tar"
5 "archive/zip"
6 "bytes"
7 "compress/gzip"
8 "crypto/sha256"
9 "encoding/hex"
10 "io"
11 "net/http"
12 "net/http/cookiejar"
13 "net/http/httptest"
14 "net/url"
15 "os/exec"
16 "path/filepath"
17 "strings"
18 "testing"
19
20 "gitlab.com/Timfa/bluegit/internal/auth"
21 "gitlab.com/Timfa/bluegit/internal/config"
22 "gitlab.com/Timfa/bluegit/internal/store"
23)
24
25func TestCommitArchivePublicAndStable(t *testing.T) {
26 if _, err := exec.LookPath("git"); err != nil {
27 t.Skip("git ontbreekt")
28 }
29 storage := t.TempDir()
30 st, err := store.Open(filepath.Join(storage, "bluegit.db"), bytes32())
31 if err != nil {
32 t.Fatal(err)
33 }
34 t.Cleanup(func() { _ = st.Close() })
35 cfg := config.Config{
36 BaseURL: "http://127.0.0.1:9", Listen: "127.0.0.1:0", StoragePath: storage,
37 Auth: config.Auth{Mode: "dev", DevUser: "tim", DevAuthID: 1, UserAgent: "test", BaseURL: "https://auth.timfalken.com"},
38 Git: config.Git{Binary: "git", DefaultBranch: "master"},
39 }
40 srv := &Server{Cfg: cfg, Store: st, Auth: auth.Dev{Username: "tim", AuthID: 1}, Dev: true, Git: "git", HookBin: "/bin/true"}
41 ts := httptest.NewServer(srv.Handler())
42 t.Cleanup(ts.Close)
43 jar, _ := cookiejar.New(nil)
44 tim := &http.Client{Jar: jar}
45 anon := &http.Client{}
46
47 page := read(t, mustGet(t, tim, ts.URL+"/login"))
48 page = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
49 "csrf": {csrfOf(t, page)}, "name": {"archief"}, "visibility": {"public"},
50 }))
51 page = read(t, mustPost(t, tim, ts.URL+"/settings/tokens", url.Values{
52 "csrf": {csrfOf(t, page)}, "name": {"laptop"},
53 }))
54 token := between(page, `<p class="code">`, "</p>")
55 work := t.TempDir()
56 git(t, work, "init", "-b", "master")
57 git(t, work, "config", "user.email", "tim@users.git.timfalken.com")
58 git(t, work, "config", "user.name", "tim")
59 writeFile(t, filepath.Join(work, "hello.txt"), "alpha\n")
60 git(t, work, "add", "hello.txt")
61 git(t, work, "commit", "-m", "start")
62 remote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/archief.git"
63 git(t, work, "remote", "add", "origin", remote)
64 git(t, work, "push", "-u", "origin", "master")
65 sha := strings.TrimSpace(gitOutOK(t, work, "rev-parse", "HEAD"))
66
67 tarURL := ts.URL + "/tim/archief/-/archive/" + sha + "/archief-" + sha + ".tar.gz"
68 first := getBody(t, anon, tarURL)
69 second := getBody(t, anon, tarURL)
70 if first.code != http.StatusOK || !bytes.Equal(first.body, second.body) {
71 t.Fatalf("tar.gz %d, gelijk %v, lengte %d", first.code, bytes.Equal(first.body, second.body), len(first.body))
72 }
73 if len(first.body) < 2 || first.body[0] != 0x1f || first.body[1] != 0x8b {
74 t.Fatal("geen gzip")
75 }
76 if !strings.Contains(first.header.Get("Content-Disposition"), "archief-"+sha+".tar.gz") {
77 t.Fatalf("bestandsnaam: %s", first.header.Get("Content-Disposition"))
78 }
79 sum := sha256.Sum256(first.body)
80 if hex.EncodeToString(sum[:]) != hex.EncodeToString(sha256Sum(second.body)) {
81 t.Fatal("sha256 verschilt tussen twee downloads")
82 }
83 names := tarNames(t, first.body)
84 want := "archief-" + sha + "/hello.txt"
85 if !containsString(names, want) {
86 t.Fatalf("tar mist %s in %v", want, names)
87 }
88
89 zipURL := ts.URL + "/tim/archief/-/archive/" + sha + "/archief-" + sha + ".zip"
90 zipRes := getBody(t, anon, zipURL)
91 if zipRes.code != http.StatusOK || len(zipRes.body) < 2 || zipRes.body[0] != 'P' || zipRes.body[1] != 'K' {
92 t.Fatalf("zip %d", zipRes.code)
93 }
94 zr, err := zip.NewReader(bytes.NewReader(zipRes.body), int64(len(zipRes.body)))
95 if err != nil {
96 t.Fatal(err)
97 }
98 found := false
99 for _, f := range zr.File {
100 if f.Name == want {
101 found = true
102 }
103 }
104 if !found {
105 t.Fatalf("zip mist %s", want)
106 }
107 again := getBody(t, anon, zipURL)
108 if !bytes.Equal(zipRes.body, again.body) {
109 t.Fatal("zip verschilt tussen twee downloads")
110 }
111
112 for _, raw := range []string{
113 ts.URL + "/tim/archief/-/archive/" + sha[:12] + "/archief.tar.gz",
114 ts.URL + "/tim/archief/-/archive/master/archief-master.tar.gz",
115 ts.URL + "/tim/archief/-/archive/" + sha + "/archief-" + sha + ".tar.bz2",
116 ts.URL + "/tim/archief/-/archive/" + strings.Repeat("ab", 20) + "/archief.tar.gz",
117 } {
118 res := getBody(t, anon, raw)
119 if res.code != http.StatusNotFound {
120 t.Fatalf("%s: %d", raw, res.code)
121 }
122 }
123
124 page = read(t, mustPost(t, tim, ts.URL+"/new/repo", url.Values{
125 "csrf": {csrfOf(t, page)}, "name": {"geheim"}, "visibility": {"private"},
126 }))
127 secret := t.TempDir()
128 git(t, secret, "init", "-b", "master")
129 git(t, secret, "config", "user.email", "tim@users.git.timfalken.com")
130 git(t, secret, "config", "user.name", "tim")
131 writeFile(t, filepath.Join(secret, "hello.txt"), "geheim\n")
132 git(t, secret, "add", "hello.txt")
133 git(t, secret, "commit", "-m", "geheim")
134 privRemote := strings.Replace(ts.URL, "http://", "http://tim:"+token+"@", 1) + "/tim/geheim.git"
135 git(t, secret, "remote", "add", "origin", privRemote)
136 git(t, secret, "push", "-u", "origin", "master")
137 privSHA := strings.TrimSpace(gitOutOK(t, secret, "rev-parse", "HEAD"))
138 hidden := getBody(t, anon, ts.URL+"/tim/geheim/-/archive/"+privSHA+"/geheim-"+privSHA+".tar.gz")
139 if hidden.code != http.StatusNotFound {
140 t.Fatalf("privé-archief: %d", hidden.code)
141 }
142}
143
144type bodyResult struct {
145 code int
146 header http.Header
147 body []byte
148}
149
150func getBody(t *testing.T, c *http.Client, raw string) bodyResult {
151 t.Helper()
152 res := mustGet(t, c, raw)
153 defer res.Body.Close()
154 body, err := io.ReadAll(res.Body)
155 if err != nil {
156 t.Fatal(err)
157 }
158 return bodyResult{code: res.StatusCode, header: res.Header, body: body}
159}
160
161func tarNames(t *testing.T, gz []byte) []string {
162 t.Helper()
163 zr, err := gzip.NewReader(bytes.NewReader(gz))
164 if err != nil {
165 t.Fatal(err)
166 }
167 defer zr.Close()
168 tr := tar.NewReader(zr)
169 var names []string
170 for {
171 hdr, err := tr.Next()
172 if err == io.EOF {
173 break
174 }
175 if err != nil {
176 t.Fatal(err)
177 }
178 names = append(names, hdr.Name)
179 }
180 return names
181}
182
183func sha256Sum(b []byte) []byte {
184 sum := sha256.Sum256(b)
185 return sum[:]
186}
187
188func containsString(list []string, want string) bool {
189 for _, item := range list {
190 if item == want {
191 return true
192 }
193 }
194 return false
195}
internal/server/server.go +1 −0
@@ -165,6 +165,7 @@ func (s *Server) Handler() http.Handler {
165 165 mux.HandleFunc("POST /{owner}/{repo}/-/tags", s.createTag)
166 166 mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag)
167 167 mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive)
168 mux.HandleFunc("GET /{owner}/{repo}/-/archive/{rev}/{file}", s.commitArchive)
168 169 mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit)
169 170 mux.HandleFunc("GET /{owner}/{repo}/-/branches/archive", s.branchArchive)
170 171 mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches)
@@ -165,6 +165,7 @@ func (s *Server) Handler() http.Handler {
165 mux.HandleFunc("POST /{owner}/{repo}/-/tags", s.createTag)
165 mux.HandleFunc("POST /{owner}/{repo}/-/tags", s.createTag)
166 mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag)
166 mux.HandleFunc("POST /{owner}/{repo}/-/tags/delete", s.deleteTag)
167 mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive)
167 mux.HandleFunc("GET /{owner}/{repo}/-/tags/archive", s.tagArchive)
168 mux.HandleFunc("GET /{owner}/{repo}/-/archive/{rev}/{file}", s.commitArchive)
168 mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit)
169 mux.HandleFunc("GET /{owner}/{repo}/-/commit/{sha}", s.commit)
169 mux.HandleFunc("GET /{owner}/{repo}/-/branches/archive", s.branchArchive)
170 mux.HandleFunc("GET /{owner}/{repo}/-/branches/archive", s.branchArchive)
170 mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches)
171 mux.HandleFunc("GET /{owner}/{repo}/-/branches", s.branches)
internal/server/tags.go +46 −0
@@ -85,6 +85,52 @@ func (s *Server) deleteTag(w http.ResponseWriter, r *http.Request) {
85 85 s.redirect(w, r, back, s.tr(r, "flash.tagDeleted"), "")
86 86 }
87 87
88 // commitArchive levert git archive van één volledige commit-sha.
89 // Het pad is de URL die makepkg ophaalt:
90 // /{owner}/{repo}/-/archive/{sha}/{name}-{sha}.tar.gz
91 func (s *Server) commitArchive(w http.ResponseWriter, r *http.Request) {
92 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
93 if !ok {
94 return
95 }
96 rev := r.PathValue("rev")
97 format := archiveFormat(r.PathValue("file"))
98 if format == "" || !fullHexSHA(rev) {
99 http.NotFound(w, r)
100 return
101 }
102 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
103 sha := gitOne(r.Context(), s.Git, dir, "rev-parse", "--verify", "--quiet", rev+"^{commit}")
104 if sha != rev {
105 http.NotFound(w, r)
106 return
107 }
108 s.writeArchive(w, r, repo, dir, sha, sha, format)
109 }
110
111 func archiveFormat(file string) string {
112 switch {
113 case strings.HasSuffix(file, ".tar.gz"):
114 return "tar.gz"
115 case strings.HasSuffix(file, ".zip"):
116 return "zip"
117 default:
118 return ""
119 }
120 }
121
122 func fullHexSHA(rev string) bool {
123 if len(rev) != 40 {
124 return false
125 }
126 for _, c := range rev {
127 if (c < '0' || c > '9') && (c < 'a' || c > 'f') {
128 return false
129 }
130 }
131 return true
132 }
133
88 134 func (s *Server) tagArchive(w http.ResponseWriter, r *http.Request) {
89 135 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
90 136 if !ok {
@@ -85,6 +85,52 @@ func (s *Server) deleteTag(w http.ResponseWriter, r *http.Request) {
85 s.redirect(w, r, back, s.tr(r, "flash.tagDeleted"), "")
85 s.redirect(w, r, back, s.tr(r, "flash.tagDeleted"), "")
86}
86}
87
87
88// commitArchive levert git archive van één volledige commit-sha.
89// Het pad is de URL die makepkg ophaalt:
90// /{owner}/{repo}/-/archive/{sha}/{name}-{sha}.tar.gz
91func (s *Server) commitArchive(w http.ResponseWriter, r *http.Request) {
92 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
93 if !ok {
94 return
95 }
96 rev := r.PathValue("rev")
97 format := archiveFormat(r.PathValue("file"))
98 if format == "" || !fullHexSHA(rev) {
99 http.NotFound(w, r)
100 return
101 }
102 dir := gitrepo.Dir(s.StoragePath(), repo.OwnerPath, repo.Name)
103 sha := gitOne(r.Context(), s.Git, dir, "rev-parse", "--verify", "--quiet", rev+"^{commit}")
104 if sha != rev {
105 http.NotFound(w, r)
106 return
107 }
108 s.writeArchive(w, r, repo, dir, sha, sha, format)
109}
110
111func archiveFormat(file string) string {
112 switch {
113 case strings.HasSuffix(file, ".tar.gz"):
114 return "tar.gz"
115 case strings.HasSuffix(file, ".zip"):
116 return "zip"
117 default:
118 return ""
119 }
120}
121
122func fullHexSHA(rev string) bool {
123 if len(rev) != 40 {
124 return false
125 }
126 for _, c := range rev {
127 if (c < '0' || c > '9') && (c < 'a' || c > 'f') {
128 return false
129 }
130 }
131 return true
132}
133
88func (s *Server) tagArchive(w http.ResponseWriter, r *http.Request) {
134func (s *Server) tagArchive(w http.ResponseWriter, r *http.Request) {
89 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
135 _, repo, _, ok := s.guard(w, r, access.RoleReadonly)
90 if !ok {
136 if !ok {
packaging/aur/.SRCINFO +3 −3
@@ -2,7 +2,7 @@ pkgbase = bluegit
2 2 pkgdesc = Self-hosted git-platform
3 3 pkgver = 20261022020626
4 4 pkgrel = 1
5 url = https://gitlab.com/Timfa/bluegit
5 url = https://git.timfalken.com/timfa/bluegit
6 6 install = bluegit.install
7 7 arch = x86_64
8 8 license = MIT
@@ -11,7 +11,7 @@ pkgbase = bluegit
11 11 makedepends = go
12 12 backup = etc/bluegit/config.yml
13 13 options = !debug
14 source = bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz::https://gitlab.com/Timfa/bluegit/-/archive/e65fc3c65c4e830955b015eba9b971335b6ceed8/bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz
15 sha256sums = 5a2b29413e1a4a19e9a018924478c5174f508ef552b63154628a3c2679f60b02
14 source = bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz::https://git.timfalken.com/timfa/bluegit/-/archive/e65fc3c65c4e830955b015eba9b971335b6ceed8/bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz
15 sha256sums = f40837ad2c6bf3cdea6080b3d257af44d2fcdb78659e59468c8fea5c33b7f338
16 16
17 17 pkgname = bluegit
@@ -2,7 +2,7 @@ pkgbase = bluegit
2 pkgdesc = Self-hosted git-platform
2 pkgdesc = Self-hosted git-platform
3 pkgver = 20261022020626
3 pkgver = 20261022020626
4 pkgrel = 1
4 pkgrel = 1
5 url = https://gitlab.com/Timfa/bluegit
5 url = https://git.timfalken.com/timfa/bluegit
6 install = bluegit.install
6 install = bluegit.install
7 arch = x86_64
7 arch = x86_64
8 license = MIT
8 license = MIT
@@ -11,7 +11,7 @@ pkgbase = bluegit
11 makedepends = go
11 makedepends = go
12 backup = etc/bluegit/config.yml
12 backup = etc/bluegit/config.yml
13 options = !debug
13 options = !debug
14 source = bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz::https://gitlab.com/Timfa/bluegit/-/archive/e65fc3c65c4e830955b015eba9b971335b6ceed8/bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz
14 source = bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz::https://git.timfalken.com/timfa/bluegit/-/archive/e65fc3c65c4e830955b015eba9b971335b6ceed8/bluegit-e65fc3c65c4e830955b015eba9b971335b6ceed8.tar.gz
15 sha256sums = 5a2b29413e1a4a19e9a018924478c5174f508ef552b63154628a3c2679f60b02
15 sha256sums = f40837ad2c6bf3cdea6080b3d257af44d2fcdb78659e59468c8fea5c33b7f338
16
16
17pkgname = bluegit
17pkgname = bluegit
packaging/aur/PKGBUILD +3 −3
@@ -4,7 +4,7 @@ pkgver=20261022020626
4 4 pkgrel=1
5 5 pkgdesc='Self-hosted git-platform'
6 6 arch=('x86_64')
7 url='https://gitlab.com/Timfa/bluegit'
7 url='https://git.timfalken.com/timfa/bluegit'
8 8 license=('MIT')
9 9 depends=('git' 'docker')
10 10 makedepends=('go')
@@ -12,8 +12,8 @@ backup=('etc/bluegit/config.yml')
12 12 options=('!debug')
13 13 install=bluegit.install
14 14 _commit=e65fc3c65c4e830955b015eba9b971335b6ceed8
15 source=("bluegit-${_commit}.tar.gz::https://gitlab.com/Timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz")
16 sha256sums=('5a2b29413e1a4a19e9a018924478c5174f508ef552b63154628a3c2679f60b02')
15 source=("bluegit-${_commit}.tar.gz::https://git.timfalken.com/timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz")
16 sha256sums=('f40837ad2c6bf3cdea6080b3d257af44d2fcdb78659e59468c8fea5c33b7f338')
17 17
18 18 build() {
19 19 cd "$srcdir/bluegit-${_commit}"
@@ -4,7 +4,7 @@ pkgver=20261022020626
4pkgrel=1
4pkgrel=1
5pkgdesc='Self-hosted git-platform'
5pkgdesc='Self-hosted git-platform'
6arch=('x86_64')
6arch=('x86_64')
7url='https://gitlab.com/Timfa/bluegit'
7url='https://git.timfalken.com/timfa/bluegit'
8license=('MIT')
8license=('MIT')
9depends=('git' 'docker')
9depends=('git' 'docker')
10makedepends=('go')
10makedepends=('go')
@@ -12,8 +12,8 @@ backup=('etc/bluegit/config.yml')
12options=('!debug')
12options=('!debug')
13install=bluegit.install
13install=bluegit.install
14_commit=e65fc3c65c4e830955b015eba9b971335b6ceed8
14_commit=e65fc3c65c4e830955b015eba9b971335b6ceed8
15source=("bluegit-${_commit}.tar.gz::https://gitlab.com/Timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz")
15source=("bluegit-${_commit}.tar.gz::https://git.timfalken.com/timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz")
16sha256sums=('5a2b29413e1a4a19e9a018924478c5174f508ef552b63154628a3c2679f60b02')
16sha256sums=('f40837ad2c6bf3cdea6080b3d257af44d2fcdb78659e59468c8fea5c33b7f338')
17
17
18build() {
18build() {
19 cd "$srcdir/bluegit-${_commit}"
19 cd "$srcdir/bluegit-${_commit}"
scripts/aur_test.go +1 −1
@@ -47,7 +47,7 @@ func TestRewritePkgbuild(t *testing.T) {
47 47 "pkgrel=1",
48 48 "_commit=" + commit,
49 49 "sha256sums=('" + sum + "')",
50 "https://gitlab.com/Timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz",
50 "https://git.timfalken.com/timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz",
51 51 } {
52 52 if !strings.Contains(text, want) {
53 53 t.Fatalf("mist %q in\n%s", want, text)
@@ -47,7 +47,7 @@ func TestRewritePkgbuild(t *testing.T) {
47 "pkgrel=1",
47 "pkgrel=1",
48 "_commit=" + commit,
48 "_commit=" + commit,
49 "sha256sums=('" + sum + "')",
49 "sha256sums=('" + sum + "')",
50 "https://gitlab.com/Timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz",
50 "https://git.timfalken.com/timfa/bluegit/-/archive/${_commit}/bluegit-${_commit}.tar.gz",
51 } {
51 } {
52 if !strings.Contains(text, want) {
52 if !strings.Contains(text, want) {
53 t.Fatalf("mist %q in\n%s", want, text)
53 t.Fatalf("mist %q in\n%s", want, text)
scripts/publish-aur.sh +2 −2
@@ -1,5 +1,5 @@
1 1 #!/usr/bin/env bash
2 # Update the AUR package bluegit from the GitLab source archive of this commit.
2 # Update the AUR package bluegit from the BlueGit source archive of this commit.
3 3 # Pushes ssh://aur@aur.archlinux.org/bluegit.git master. AUR only accepts master.
4 4 set -euo pipefail
5 5
@@ -93,7 +93,7 @@ WORKDIR="$(mktemp -d "$TMPDIR/bluegit-aur-XXXXXX")"
93 93 cleanup() { rm -rf "$WORKDIR"; }
94 94 trap cleanup EXIT
95 95
96 SOURCE_URL="https://gitlab.com/Timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz"
96 SOURCE_URL="https://git.timfalken.com/timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz"
97 97 TMP_SOURCE="$WORKDIR/source.tar.gz"
98 98 echo "Checking source tarball: $SOURCE_URL"
99 99 if ! curl -fsSL "$SOURCE_URL" -o "$TMP_SOURCE"; then
@@ -1,5 +1,5 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2# Update the AUR package bluegit from the GitLab source archive of this commit.
2# Update the AUR package bluegit from the BlueGit source archive of this commit.
3# Pushes ssh://aur@aur.archlinux.org/bluegit.git master. AUR only accepts master.
3# Pushes ssh://aur@aur.archlinux.org/bluegit.git master. AUR only accepts master.
4set -euo pipefail
4set -euo pipefail
5
5
@@ -93,7 +93,7 @@ WORKDIR="$(mktemp -d "$TMPDIR/bluegit-aur-XXXXXX")"
93cleanup() { rm -rf "$WORKDIR"; }
93cleanup() { rm -rf "$WORKDIR"; }
94trap cleanup EXIT
94trap cleanup EXIT
95
95
96SOURCE_URL="https://gitlab.com/Timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz"
96SOURCE_URL="https://git.timfalken.com/timfa/bluegit/-/archive/${COMMIT}/bluegit-${COMMIT}.tar.gz"
97TMP_SOURCE="$WORKDIR/source.tar.gz"
97TMP_SOURCE="$WORKDIR/source.tar.gz"
98echo "Checking source tarball: $SOURCE_URL"
98echo "Checking source tarball: $SOURCE_URL"
99if ! curl -fsSL "$SOURCE_URL" -o "$TMP_SOURCE"; then
99if ! curl -fsSL "$SOURCE_URL" -o "$TMP_SOURCE"; then