ReviewOS

also looking at this

craft-native/craft

ci: pin the first-party Zig dependencies to commits

#39
Merged glennmichael123 wants to merge ci/pin-first-party-zig-deps into main
2 files +62 -15
.github/actions/first-party-zig-deps/action.ymlmodified+36-15
Changes to .github/actions/first-party-zig-deps/action.yml
@@ -2,32 +2,53 @@ name: First-party Zig dependencies
22description: >
33 Clone the first-party Zig packages craft depends on by relative path
44 (zig-js and its zig-regex / zig-gc) into the directory build.zig.zon
5 resolves to.
5 resolves to, at the revisions pinned in pins.env.
66
77runs:
88 using: composite
99 steps:
1010 # These are co-developed first-party packages, so there is no published
11 # tarball to fetch and the dependency is a relative path. The destination is
12 # derived from that same relative path rather than hardcoded, so the two
13 # cannot drift apart.
11 # tarball to fetch and the dependency is a relative path — which means Zig's
12 # package manager has no `.url` + hash to verify and nothing records which
13 # revision a build used.
1414 #
15 # Unpinned, which is the honest cost of a path dependency: an unrelated push
16 # to zig-js can turn a craft build red. Pinning belongs with a future
17 # `.url` + hash dependency, which first needs zig-js to publish its own
18 # dependencies the same way.
15 # So the revision is recorded here instead, in pins.env. Cloning the default
16 # branch, which this did until now, hands the question of whether craft's CI
17 # is green to whoever last pushed to another repository. See pins.env for
18 # what that cost and for how to bump one.
1919 #
2020 # Idempotent, because several jobs call this and some run more than one
21 # build step.
21 # build step. A checkout already at the pinned revision is left alone; one
22 # at any other revision is replaced, so a stale cache cannot silently win.
2223 - shell: bash
2324 run: |
2425 set -euo pipefail
26
27 # shellcheck source=pins.env
28 . "$GITHUB_ACTION_PATH/pins.env"
29
2530 deps="$GITHUB_WORKSPACE/packages/zig/../../../../Libraries"
2631 mkdir -p "$deps"
27 for repo in zig-js zig-regex zig-gc; do
28 if [ -d "$deps/$repo/.git" ]; then
29 echo "$repo already present"
30 else
31 git clone --depth 1 "https://github.com/zig-utils/$repo" "$deps/$repo"
32
33 fetch_pinned() {
34 local repo="$1" sha="$2" dest="$deps/$1"
35
36 if [ -d "$dest/.git" ] && [ "$(git -C "$dest" rev-parse HEAD)" = "$sha" ]; then
37 echo "$repo already at $sha"
38 return
3239 fi
33 done
40
41 rm -rf "$dest"
42 git init --quiet "$dest"
43 git -C "$dest" remote add origin "https://github.com/zig-utils/$repo"
44 # Fetch the one commit rather than the branch: the pin may point at
45 # something that is no longer the tip, and --depth 1 on a branch would
46 # not reach it.
47 git -C "$dest" fetch --quiet --depth 1 origin "$sha"
48 git -C "$dest" checkout --quiet FETCH_HEAD
49 echo "$repo pinned at $sha"
50 }
51
52 fetch_pinned zig-js "$zig_js"
53 fetch_pinned zig-regex "$zig_regex"
54 fetch_pinned zig-gc "$zig_gc"