Skip to content

Commit 1ecf119

Browse files
author
Marko Vejnovic
committed
feat(release): publish per-asset sha256 sidecars and manifest.json
Each binary now ships a <asset>.sha256 sidecar in sha256sum(1) format (verifiable with sha256sum -c), reusing the digest already computed at build time. A manifest.json is also uploaded listing the commit sha and, per build, its name/arch/version/asset filename/sha256 so consumers can select and verify images without parsing asset names.
1 parent c20ce4d commit 1ecf119

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

src/vmlinux/gha/release.clj

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
(:require
33
[babashka.fs :as fs]
44
[babashka.process :refer [shell]]
5+
[cheshire.core :as json]
56
[selmer.parser :as p]))
67

78
(defn- release-tag [sha] (str "release-" sha))
@@ -30,15 +31,41 @@
3031
(< attempt 6) (do (Thread/sleep (* attempt 2000)) (recur (inc attempt)))
3132
:else (throw (ex-info (str "gh release upload failed for " asset) {:asset asset}))))))
3233

34+
(defn- stage-asset!
35+
"Copy the build binary to its release asset name and write a `<asset>.sha256`
36+
sidecar in sha256sum(1) format. Returns the [asset sidecar] paths."
37+
[build]
38+
(let [name (asset-name build)
39+
asset (str (fs/parent (:binary-path build)) "/" name)
40+
sidecar (str asset ".sha256")]
41+
(fs/copy (:binary-path build) asset {:replace-existing true})
42+
(spit sidecar (str (:sha256-sum build) " " name "\n"))
43+
[asset sidecar]))
44+
45+
(defn- manifest-json
46+
[sha assets]
47+
(json/generate-string {:sha sha,
48+
:builds (mapv (fn [{:keys [name arch version sha256-sum], :as build}]
49+
{:name name,
50+
:arch (clojure.core/name arch),
51+
:version version,
52+
:asset (asset-name build),
53+
:sha256 sha256-sum})
54+
assets)}
55+
{:pretty true}))
56+
3357
(defn create
3458
[sha assets]
3559
(let [tag (release-tag sha)]
3660
(when-not (exists? sha)
3761
(shell "gh" "release" "create" tag "--title" (title sha) "--notes" (notes sha)))
3862
(->> assets
3963
(mapv (fn [build]
40-
(future (let [asset (str (fs/parent (:binary-path build)) "/" (asset-name build))]
41-
(fs/copy (:binary-path build) asset {:replace-existing true})
42-
(upload! tag asset)))))
64+
(future (let [[asset sidecar] (stage-asset! build)]
65+
(upload! tag asset)
66+
(upload! tag sidecar)))))
4367
(run! deref))
68+
(let [manifest (str (fs/parent (:binary-path (first assets))) "/manifest.json")]
69+
(spit manifest (manifest-json sha assets))
70+
(upload! tag manifest))
4471
tag))

0 commit comments

Comments
 (0)