Skip to content

Commit 5c7488e

Browse files
tmmampagent
andauthored
chore(zero-swift): create GitHub releases on the mirror (#42)
After tagging a version on wevm/zero-swift, the release workflow creates a GitHub release there whose notes are the version's section of packages/zero-swift-cli/CHANGELOG.md, with wevm/zero commit hashes turned into links. The plan job checks for the release separately from the tag, so a run that tagged but failed to release creates only the release when rerun. Amp-Thread-ID: https://ampcode.com/threads/T-c513a037-a257-45e0-b9a9-15c15edfe859 Co-authored-by: Amp <amp@ampcode.com>
1 parent 38fa380 commit 5c7488e

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

‎.github/workflows/swift-release.yml‎

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ name: Swift Release
88
# - With pending changesets, opens or updates the "Version Packages" PR.
99
# - Otherwise, if the version in swift/VERSION isn't released yet, after
1010
# approval in the swift-release environment:
11-
# - publishes swift/ to the SwiftPM mirror (wevm/zero-swift) and tags the
12-
# version there. SwiftPM needs Package.swift at a repository root and
13-
# clones whole repositories, so consumers install from the mirror.
11+
# - publishes swift/ to the SwiftPM mirror (wevm/zero-swift), tags the
12+
# version there, and creates a GitHub release from the version's section
13+
# of packages/zero-swift-cli/CHANGELOG.md. SwiftPM needs Package.swift at
14+
# a repository root and clones whole repositories, so consumers install
15+
# from the mirror.
1416
# - publishes the zero-swift CLI to npm with trusted publishing.
1517
# Each step is skipped when its release already exists, so a failed run can be
1618
# rerun.
@@ -63,6 +65,7 @@ jobs:
6365
outputs:
6466
version: ${{ steps.plan.outputs.version }}
6567
mirror: ${{ steps.plan.outputs.mirror }}
68+
release: ${{ steps.plan.outputs.release }}
6669
npm: ${{ steps.plan.outputs.npm }}
6770
steps:
6871
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
@@ -73,6 +76,8 @@ jobs:
7376
packages/zero-swift-cli/package.json
7477
sparse-checkout-cone-mode: false
7578
- id: plan
79+
env:
80+
GH_TOKEN: ${{ github.token }}
7681
run: |
7782
set -euo pipefail
7883
version="$(tr -d '[:space:]' < swift/VERSION)"
@@ -87,6 +92,13 @@ jobs:
8792
else
8893
echo "mirror=true" >> "$GITHUB_OUTPUT"
8994
fi
95+
status="$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $GH_TOKEN" \
96+
"https://api.github.com/repos/wevm/zero-swift/releases/tags/$version")"
97+
case "$status" in
98+
200) echo "release=false" >> "$GITHUB_OUTPUT" ;;
99+
404) echo "release=true" >> "$GITHUB_OUTPUT" ;;
100+
*) echo "Looking up the $version release returned HTTP $status." >&2; exit 1 ;;
101+
esac
90102
if npm view "zero-swift@$version" version >/dev/null 2>&1; then
91103
echo "npm=false" >> "$GITHUB_OUTPUT"
92104
else
@@ -97,7 +109,7 @@ jobs:
97109
name: Publish mirror
98110
runs-on: ubuntu-latest
99111
needs: plan
100-
if: needs.plan.outputs.mirror == 'true'
112+
if: needs.plan.outputs.mirror == 'true' || needs.plan.outputs.release == 'true'
101113
environment: swift-release
102114
env:
103115
MIRROR_TOKEN: ${{ secrets.ZERO_SWIFT_MIRROR_TOKEN }}
@@ -109,13 +121,31 @@ jobs:
109121
fetch-depth: 0
110122
persist-credentials: false
111123
- name: Split and push
124+
if: needs.plan.outputs.mirror == 'true'
112125
run: |
113126
set -euo pipefail
114127
git subtree split --prefix=swift -b mirror
115128
remote="https://x-access-token:${MIRROR_TOKEN}@github.com/${MIRROR_REPO}.git"
116129
git push "$remote" mirror:main
117130
git tag "$VERSION" mirror
118131
git push "$remote" "refs/tags/$VERSION"
132+
# The version's changelog section. Its commit hashes are wevm/zero's,
133+
# which GitHub doesn't link from the mirror, so they become links.
134+
- name: Create release
135+
env:
136+
GH_TOKEN: ${{ env.MIRROR_TOKEN }}
137+
run: |
138+
set -euo pipefail
139+
awk -v v="## $VERSION" '$0 == v {f = 1; next} /^## / {f = 0} f' \
140+
packages/zero-swift-cli/CHANGELOG.md |
141+
sed -E 's|^- ([0-9a-f]{7,40}):|- [`\1`](https://github.com/wevm/zero/commit/\1):|' \
142+
>"$RUNNER_TEMP/notes.md"
143+
if ! grep -q '[^[:space:]]' "$RUNNER_TEMP/notes.md"; then
144+
echo "No section for $VERSION in packages/zero-swift-cli/CHANGELOG.md." >&2
145+
exit 1
146+
fi
147+
gh release create "$VERSION" -R "$MIRROR_REPO" --verify-tag \
148+
--title "$VERSION" --notes-file "$RUNNER_TEMP/notes.md"
119149
120150
npm-build:
121151
name: Build npm package

0 commit comments

Comments
 (0)