|
2 | 2 | (:require |
3 | 3 | [babashka.fs :as fs] |
4 | 4 | [babashka.process :refer [shell]] |
| 5 | + [cheshire.core :as json] |
5 | 6 | [selmer.parser :as p])) |
6 | 7 |
|
7 | 8 | (defn- release-tag [sha] (str "release-" sha)) |
|
30 | 31 | (< attempt 6) (do (Thread/sleep (* attempt 2000)) (recur (inc attempt))) |
31 | 32 | :else (throw (ex-info (str "gh release upload failed for " asset) {:asset asset})))))) |
32 | 33 |
|
| 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 | + |
33 | 57 | (defn create |
34 | 58 | [sha assets] |
35 | 59 | (let [tag (release-tag sha)] |
36 | 60 | (when-not (exists? sha) |
37 | 61 | (shell "gh" "release" "create" tag "--title" (title sha) "--notes" (notes sha))) |
38 | 62 | (->> assets |
39 | 63 | (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))))) |
43 | 67 | (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)) |
44 | 71 | tag)) |
0 commit comments