1818 publish :
1919 name : publish @openagentlock/cli
2020 runs-on : ubuntu-latest
21+ outputs :
22+ version : ${{ steps.ver.outputs.version }}
2123 steps :
2224 - uses : actions/checkout@v6
2325
@@ -41,45 +43,125 @@ jobs:
4143 working-directory : cli
4244 run : bun test
4345
46+ - id : ver
47+ name : Resolve version
48+ run : echo "version=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
49+
4450 - name : Publish
4551 working-directory : cli
4652 env :
4753 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
4854 run : npm publish --provenance --access public
4955
50- - name : Open Homebrew formula PR
51- env :
52- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
53- VERSION : ${{ github.ref_name }}
56+ formula :
57+ name : open Homebrew formula PR
58+ needs : publish
59+ runs-on : ubuntu-latest
60+ continue-on-error : true
61+ env :
62+ VERSION : ${{ needs.publish.outputs.version }}
63+ steps :
64+ - uses : actions/checkout@v6
65+ with :
66+ ref : main
67+ fetch-depth : 0
68+
69+ - uses : actions/setup-node@v6
70+ with :
71+ node-version : " 20"
72+ registry-url : " https://registry.npmjs.org"
73+
74+ - name : Wait for tarball + compute sha256
75+ id : tarball
5476 run : |
5577 set -euo pipefail
56- v="${VERSION#v}"
57- tarball="https://registry.npmjs.org/@openagentlock/cli/-/cli-${v}.tgz"
58- for i in 1 2 3 4 5 6; do
59- if curl -sfI "$tarball" >/dev/null; then break; fi
60- sleep 5
78+ v="${VERSION}"
79+ pkg="@openagentlock/cli"
80+
81+ deadline=$(( $(date +%s) + 300 ))
82+ tarball=""
83+ integrity=""
84+ while [ "$(date +%s)" -lt "$deadline" ]; do
85+ tarball=$(npm view "${pkg}@${v}" dist.tarball 2>/dev/null || true)
86+ integrity=$(npm view "${pkg}@${v}" dist.integrity 2>/dev/null || true)
87+ if [ -n "$tarball" ] && [ -n "$integrity" ]; then
88+ if curl -fLsS --retry 3 --retry-delay 3 --max-time 30 \
89+ -o /tmp/cli.tgz "$tarball"; then
90+ break
91+ fi
92+ fi
93+ echo "tarball not ready yet; retrying in 15s..."
94+ sleep 15
95+ tarball=""
6196 done
62- sha=$(curl -sfL "$tarball" | shasum -a 256 | awk '{print $1}')
63- git config user.name "github-actions[bot]"
64- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
65- git fetch origin main
66- branch="formula/v${v}"
67- git checkout -B "$branch" origin/main
97+
98+ if [ -z "$tarball" ] || [ ! -s /tmp/cli.tgz ]; then
99+ echo "::error::Tarball for ${pkg}@${v} not available after 5 minutes" >&2
100+ exit 1
101+ fi
102+
103+ want_sha512=$(printf '%s' "$integrity" | sed -E 's|^sha512-||' \
104+ | base64 -d 2>/dev/null | xxd -p -c 256 | tr -d '\n')
105+ got_sha512=$(shasum -a 512 /tmp/cli.tgz | awk '{print $1}')
106+ if [ "$want_sha512" != "$got_sha512" ]; then
107+ echo "::error::Integrity mismatch: registry=${want_sha512} got=${got_sha512}" >&2
108+ exit 1
109+ fi
110+
111+ sha256=$(shasum -a 256 /tmp/cli.tgz | awk '{print $1}')
112+ echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
113+ echo "sha256=$sha256" >> "$GITHUB_OUTPUT"
114+ {
115+ echo "### Tarball"
116+ echo ""
117+ echo "- url: \`$tarball\`"
118+ echo "- sha256: \`$sha256\`"
119+ } >> "$GITHUB_STEP_SUMMARY"
120+
121+ - name : Edit Formula
122+ env :
123+ SHA256 : ${{ steps.tarball.outputs.sha256 }}
124+ run : |
125+ set -euo pipefail
126+ v="${VERSION}"
68127 sed -i -E \
69128 -e "s|cli-[0-9]+\.[0-9]+\.[0-9]+\.tgz|cli-${v}.tgz|" \
70- -e "s|sha256 \"[^\"]+\"|sha256 \"${sha }\"|" \
129+ -e "s|sha256 \"[^\"]+\"|sha256 \"${SHA256 }\"|" \
71130 -e "s|version \"[^\"]+\"|version \"${v}\"|" \
72131 Formula/agentlock.rb
73132 if git diff --quiet -- Formula/agentlock.rb; then
74- echo "Formula already at v${v}"
75- exit 0
133+ echo "Formula already at v${v}; nothing to do." \
134+ >> "$GITHUB_STEP_SUMMARY"
135+ echo "NO_CHANGES=1" >> "$GITHUB_ENV"
76136 fi
137+
138+ - name : Open PR
139+ if : env.NO_CHANGES != '1'
140+ env :
141+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
142+ run : |
143+ set -euo pipefail
144+ v="${VERSION}"
145+ branch="formula/v${v}"
146+ git config user.name "github-actions[bot]"
147+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
148+
149+ # Recreate the branch cleanly (delete any stale remote copy first).
150+ git push origin --delete "$branch" 2>/dev/null || true
151+ git checkout -B "$branch"
77152 git add Formula/agentlock.rb
78153 git commit -m "Formula: pin v${v} sha256"
79- git push -f origin "$branch"
80- gh pr create \
81- --base main \
82- --head "$branch" \
83- --title "Formula: pin v${v} sha256" \
84- --body "Automated formula bump after publishing \`@openagentlock/cli@${v}\` to npm." \
85- || gh pr edit "$branch" --title "Formula: pin v${v} sha256"
154+ git push -u origin "$branch"
155+
156+ existing=$(gh pr list --head "$branch" --state open \
157+ --json number --jq '.[0].number' || true)
158+ if [ -n "$existing" ]; then
159+ echo "PR #$existing already open for $branch" \
160+ >> "$GITHUB_STEP_SUMMARY"
161+ else
162+ gh pr create \
163+ --base main \
164+ --head "$branch" \
165+ --title "Formula: pin v${v} sha256" \
166+ --body "Automated formula bump after publishing \`@openagentlock/cli@${v}\` to npm."
167+ fi
0 commit comments