Skip to content

Commit 43e1fbc

Browse files
authored
Updates to wasm-tool's release process (#2021) (#2028)
* Enable releases to happen on `release-*` branches, not just `main` * PRs to bump versions from `release-*` branches now have the correct base branch. * Logic for publication was moved from `.github/workflows/publish.yml` to `.github/actions/publish-release` to be able to share logic with `main.yml`. This is because releases from `main` always have the merge queue first, hence the `publish.yml` workflow, but releases from a `release-*` branch don't have a merge queue meaning it has to run at the end of normal CI. * Some various conditions were tweaked for various conditions to assist with external testing of the release workflow, e.g. dropinng requirements for repos to be in the `bytecodealliance` organization. * The `main.yml` CI now runs for all pushes to `release-*` branches, enabling artifacts being built for publication.
1 parent 966e1dc commit 43e1fbc

File tree

5 files changed

+118
-72
lines changed

5 files changed

+118
-72
lines changed
+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: 'Maybe perform a release'
2+
description: 'Steps to perform a conditional release of this repository'
3+
4+
inputs:
5+
cargo_token:
6+
description: 'token used to publish crates'
7+
required: false
8+
9+
runs:
10+
using: composite
11+
steps:
12+
# If this commit log has an indicator saying that a tag should be made. If
13+
# so create one and push it.
14+
- name: Test if tag is needed
15+
run: |
16+
git log ${{ github.event.before }}...${{ github.event.after }} | tee main.log
17+
version=$(./ci/print-current-version.sh)
18+
echo "version: $version"
19+
echo "version=$version" >> $GITHUB_OUTPUT
20+
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
21+
if grep -q "automatically-tag-and-release-this-commit" main.log; then
22+
echo push-tag
23+
echo "push_tag=yes" >> $GITHUB_OUTPUT
24+
else
25+
echo no-push-tag
26+
echo "push_tag=no" >> $GITHUB_OUTPUT
27+
fi
28+
shell: bash
29+
id: tag
30+
31+
- name: Push the tag
32+
run: |
33+
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
34+
curl -iX POST $git_refs_url \
35+
-H "Authorization: token ${{ github.token }}" \
36+
-d @- << EOF
37+
{
38+
"ref": "refs/tags/v${{ steps.tag.outputs.version }}",
39+
"sha": "${{ steps.tag.outputs.sha }}"
40+
}
41+
EOF
42+
shell: bash
43+
if: steps.tag.outputs.push_tag == 'yes'
44+
45+
# Download all github actions artifact for this commit. We're either running
46+
# on `main` after the merge queue or on a release branch after the rest of
47+
# CI, so use the github API to find the artifacts for consistency.
48+
- run: |
49+
sha=${{ github.sha }}
50+
run_id=$(
51+
gh api -H 'Accept: application/vnd.github+json' \
52+
/repos/${{ github.repository }}/actions/workflows/main.yml/runs\?exclude_pull_requests=true \
53+
| jq '.workflow_runs' \
54+
| jq "map(select(.head_commit.id == \"$sha\"))[0].id" \
55+
)
56+
gh run download $run_id
57+
ls
58+
find bins-*
59+
mkdir dist
60+
mv bins-*/* dist
61+
shell: bash
62+
env:
63+
GH_TOKEN: ${{ github.token }}
64+
65+
# Conditionally make a release if a tag was made.
66+
- uses: softprops/action-gh-release@v1
67+
if: steps.tag.outputs.push_tag == 'yes'
68+
with:
69+
files: "dist/*"
70+
generate_release_notes: true
71+
tag_name: v${{ steps.tag.outputs.version }}
72+
73+
# Conditionally run crate publishes if the token is present.
74+
- run: rustup update stable && rustup default stable
75+
shell: bash
76+
77+
- run: |
78+
rm -rf dist main.log
79+
rustc ci/publish.rs
80+
./publish publish
81+
shell: bash
82+
env:
83+
CARGO_REGISTRY_TOKEN: ${{ inputs.cargo_token }}
84+
if: steps.tag.outputs.push_tag == 'yes' && github.repository_owner == 'bytecodealliance'

.github/workflows/main.yml

+26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
name: CI
22
on:
3+
# Run CI for PRs to `main` and to release branches.
34
pull_request:
5+
# This is the CI that runs for PRs-to-merge.
46
merge_group:
7+
# Run full CI on pushes to release branches since the merge queue can't be
8+
# used with for all release branches (wildcard pattern turns that off)
9+
push:
10+
branches:
11+
- 'release-*'
512

613
# Cancel any in-flight jobs for the same PR/branch so there's only one active
714
# at a time
@@ -329,3 +336,22 @@ jobs:
329336
- name: Report failure on cancellation
330337
if: ${{ contains(needs.*.result, 'cancelled') || cancelled() }}
331338
run: exit 1
339+
340+
# Once CI has finished on `release-*` branches test to see if a release needs
341+
# to be made based on the commits of this push.
342+
maybe-trigger-tag:
343+
runs-on: ubuntu-latest
344+
needs: ci-status
345+
if: |
346+
always()
347+
&& needs.ci-status.result == 'success'
348+
&& github.event_name == 'push'
349+
&& startsWith(github.ref, 'refs/heads/release-')
350+
steps:
351+
- uses: actions/checkout@v4
352+
with:
353+
submodules: true
354+
fetch-depth: 0
355+
- uses: ./.github/actions/publish-release
356+
with:
357+
cargo_token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/playground.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646

4747
deploy:
4848
name: Deploy playground
49-
if: github.ref == 'refs/heads/main'
49+
if: github.ref == 'refs/heads/main' && github.repository_owner == 'bytecodealliance'
5050
needs: build
5151
permissions:
5252
pages: write

.github/workflows/publish.yml

+6-70
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Publication half of the release process for this repository. This runs on
2-
# pushes to `main` and will detect a magical string in commit messages. When
3-
# found a tag will be created, pushed, and then everything is published.
1+
# Publication of the `main` branch.
2+
#
3+
# Commits to `main` go through the merge queue first to produce artifacts and
4+
# test results. If a special commit marker is found then a publish is made.
45

56
name: Publish Artifacts
67
on:
@@ -14,76 +15,11 @@ jobs:
1415
create_tag:
1516
name: Publish artifacts of build
1617
runs-on: ubuntu-latest
17-
if: |
18-
github.repository_owner == 'bytecodealliance'
19-
&& github.event_name == 'push'
20-
&& github.ref == 'refs/heads/main'
2118
steps:
2219
- uses: actions/checkout@v4
2320
with:
2421
submodules: true
2522
fetch-depth: 0
26-
27-
- run: rustup update stable && rustup default stable
28-
29-
# If this is a push to `main` see if the push has an indicator saying that
30-
# a tag should be made. If so create one and push it.
31-
- name: Test if tag is needed
32-
run: |
33-
git log ${{ github.event.before }}...${{ github.event.after }} | tee main.log
34-
version=$(./ci/print-current-version.sh)
35-
echo "version: $version"
36-
echo "version=$version" >> $GITHUB_OUTPUT
37-
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
38-
if grep -q "automatically-tag-and-release-this-commit" main.log; then
39-
echo push-tag
40-
echo "push_tag=yes" >> $GITHUB_OUTPUT
41-
else
42-
echo no-push-tag
43-
echo "push_tag=no" >> $GITHUB_OUTPUT
44-
fi
45-
id: tag
46-
47-
- name: Push the tag
48-
run: |
49-
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
50-
curl -iX POST $git_refs_url \
51-
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
52-
-d @- << EOF
53-
{
54-
"ref": "refs/tags/v${{ steps.tag.outputs.version }}",
55-
"sha": "${{ steps.tag.outputs.sha }}"
56-
}
57-
EOF
58-
if: steps.tag.outputs.push_tag == 'yes'
59-
60-
- run: |
61-
sha=${{ github.sha }}
62-
run_id=$(
63-
gh api -H 'Accept: application/vnd.github+json' \
64-
/repos/${{ github.repository }}/actions/workflows/main.yml/runs\?exclude_pull_requests=true \
65-
| jq '.workflow_runs' \
66-
| jq "map(select(.head_commit.id == \"$sha\"))[0].id" \
67-
)
68-
gh run download $run_id
69-
ls
70-
find bins-*
71-
mkdir dist
72-
mv bins-*/* dist
73-
env:
74-
GH_TOKEN: ${{ github.token }}
75-
76-
- uses: softprops/action-gh-release@v1
77-
if: steps.tag.outputs.push_tag == 'yes'
23+
- uses: ./.github/actions/publish-release
7824
with:
79-
files: "dist/*"
80-
generate_release_notes: true
81-
tag_name: v${{ steps.tag.outputs.version }}
82-
83-
- run: |
84-
rm -rf dist main.log
85-
rustc ci/publish.rs
86-
./publish publish
87-
env:
88-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
89-
if: steps.tag.outputs.push_tag == 'yes'
25+
cargo_token: ${{ secrets.CARGO_REGISTRY_TOKEN }}

.github/workflows/release-process.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
git push origin HEAD:ci/release-$cur
5757
echo "PR_HEAD=ci/release-$cur" >> $GITHUB_ENV
5858
echo "PR_TITLE=Release ${{ github.event.repository.name }} $cur" >> $GITHUB_ENV
59-
echo "PR_BASE=main" >> $GITHUB_ENV
59+
echo "PR_BASE=${{ github.ref_name }}" >> $GITHUB_ENV
6060
cat > pr-body <<-EOF
6161
This is an automated pull request from CI to release
6262
${{ github.event.repository.name }} $cur when merged. The commit

0 commit comments

Comments
 (0)