Skip to content

Commit a1a0263

Browse files
authored
ci: Restructure release workflow (shaka-project#60)
This isolates elevated permissions to the release publication job only, and simplifies a more complex sequence of creating a draft release, then building and attaching binaries, then compiling release notes, then publishing the release. Now we simply build, compile notes, then publish a full release with notes and binaries at once. This also removes the need for our own "api client" in JavaScript. Now we perform these actions with GitHub's own tools: "gh" command line to create the release and "actions/" official actions to upload and download build artifacts.
1 parent 7f593bd commit a1a0263

File tree

6 files changed

+20
-485
lines changed

6 files changed

+20
-485
lines changed

.github/workflows/build.yaml

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,9 @@ on:
2222
# workflows.
2323
workflow_call:
2424
inputs:
25-
release_id:
26-
required: false
27-
type: string
2825
ref:
2926
required: true
3027
type: string
31-
secrets:
32-
# The GITHUB_TOKEN name is reserved, but not passed through implicitly.
33-
# So we call our secret parameter simply TOKEN.
34-
TOKEN:
35-
required: false
3628

3729
# Runs on manual trigger.
3830
workflow_dispatch:
@@ -214,23 +206,6 @@ jobs:
214206
- name: Check that executables are static
215207
run: ./repo-src/build-scripts/99-check-static.sh
216208

217-
- name: Attach assets to release
218-
if: inputs.release_id != ''
219-
env:
220-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
221-
run: |
222-
set -e
223-
set -x
224-
225-
# Attach the build outputs to the draft release. Each machine will
226-
# do this separately and in parallel. Later, another job will take
227-
# over to collect them all and use their MD5 sums to create the
228-
# release notes (the "body" of the release).
229-
release_id="${{ inputs.release_id }}"
230-
(cd ./repo-src/api-client && npm ci)
231-
node ./repo-src/api-client/main.js \
232-
upload-all-assets "$release_id" assets/
233-
234209
- name: Debug
235210
uses: mxschmitt/[email protected]
236211
with:

.github/workflows/release.yaml

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -30,54 +30,29 @@ on:
3030
# will have to opt in after setting up their own self-hosted runners.
3131

3232
jobs:
33-
# On a single Linux host, draft a release. Later, different hosts will build
34-
# for each OS/CPU in parallel, and then attach the resulting binaries to this
35-
# draft.
36-
draft_release:
37-
name: Draft release
38-
runs-on: ubuntu-latest
39-
outputs:
40-
release_id: ${{ steps.draft_release.outputs.release_id }}
41-
steps:
42-
- uses: actions/checkout@v4
43-
with:
44-
path: repo-src
45-
ref: ${{ github.ref }}
46-
47-
- name: Draft release
48-
id: draft_release
49-
env:
50-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51-
run: |
52-
set -e
53-
set -x
54-
55-
# Create a draft release associated with the tag that triggered this
56-
# workflow.
57-
tag="${{ github.ref }}"
58-
(cd repo-src/api-client && npm ci)
59-
release_id=$(node ./repo-src/api-client/main.js draft-release "$tag")
60-
echo "::set-output name=release_id::$release_id"
61-
6233
build:
63-
needs: draft_release
6434
uses: ./.github/workflows/build.yaml
6535
with:
66-
release_id: ${{ needs.draft_release.outputs.release_id }}
6736
ref: ${{ github.ref }}
68-
secrets:
69-
TOKEN: ${{ secrets.GITHUB_TOKEN }}
7037

7138
publish_release:
7239
name: Publish release
73-
needs: [draft_release, build]
40+
needs: [build]
7441
runs-on: ubuntu-latest
42+
permissions:
43+
# "Write" to contents is necessary to create a release.
44+
contents: write
7545
steps:
7646
- uses: actions/checkout@v4
7747
with:
7848
path: repo-src
7949
ref: ${{ github.ref }}
8050

51+
- uses: actions/download-artifact@v4
52+
with:
53+
path: assets
54+
merge-multiple: true
55+
8156
- name: Publish release
8257
env:
8358
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -93,41 +68,24 @@ jobs:
9368
echo " - $(date -I)" >> body.txt
9469
echo "" >> body.txt
9570
96-
echo "$GITHUB_REPOSITORY version:" >> body.txt
97-
echo " - $repo_tag" >> body.txt
71+
echo "${{ github.repository }} version:" >> body.txt
72+
echo " - ${{ github.ref_name }}" >> body.txt
9873
echo "" >> body.txt
9974
10075
echo "Software versions:" >> body.txt
10176
cat repo-src/versions.txt | \
10277
sed -e 's/^/ - /' >> body.txt
10378
echo "" >> body.txt
10479
105-
# Update the release notes with this preliminary version. This is
106-
# what gets emailed out when we publish the release below.
107-
release_id="${{ needs.draft_release.outputs.release_id }}"
108-
(cd repo-src/api-client && npm ci)
109-
node ./repo-src/api-client/main.js \
110-
update-release-body "$release_id" "$(cat body.txt)"
111-
112-
# Now we have to take the release out of draft mode. Until we do, we
113-
# can't get download URLs for the assets.
114-
node ./repo-src/api-client/main.js \
115-
publish-release "$release_id"
116-
117-
# The downloads are sometimes a bit flaky (responding with 404) if we
118-
# don't put some delay between publication and download. This number
119-
# is arbitrary, but experimentally, it seems to solve the issue.
120-
sleep 30
121-
122-
# Next, download the assets.
123-
node ./repo-src/api-client/main.js \
124-
download-all-assets "$release_id" assets/
125-
126-
# Now add the MD5 sums to the release notes.
80+
# Add the MD5 sums to the release notes.
12781
echo "MD5 sums:" >> body.txt
12882
(cd assets; md5sum * | sed -e 's/^/ - /') >> body.txt
12983
130-
# Now update the release notes one last time, with the MD5 sums
131-
# appended.
132-
node ./repo-src/api-client/main.js \
133-
update-release-body "$release_id" "$(cat body.txt)"
84+
# Publish the release, including release notes and assets.
85+
gh release create \
86+
-R ${{ github.repository }} \
87+
--verify-tag \
88+
--notes-file body.txt \
89+
--title "${{ github.ref_name }}" \
90+
"${{ github.ref_name }}" \
91+
assets/*

api-client/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)