Skip to content

Commit 4aca5b3

Browse files
authored
add release automation (#81)
* Cargo: set rust-version following wasmtime's policy of stable minus two * switch to install-rust action used in wasm-tools etc * add publish.rs and verify-publish ci job * add release-process publish workflows copied from wit-bindgen, except got rid of publishing the dist files, since we arent distributing any binaries as part of this release process * fix comment * use trusted publishing workflow adapted from bytecodealliance/wit-bindgen#1350 * fix typos
1 parent 1cf72be commit 4aca5b3

File tree

11 files changed

+660
-14
lines changed

11 files changed

+660
-14
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: 'Install Rust toolchain'
2+
description: 'Install a rust toolchain'
3+
4+
inputs:
5+
toolchain:
6+
description: 'Default toolchan to install'
7+
required: false
8+
default: 'stable'
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Install Rust
14+
shell: bash
15+
id: select
16+
run: |
17+
# Determine MSRV as N in `1.N.0` by looking at the `rust-version`
18+
# located in the root `Cargo.toml`.
19+
msrv=$(grep 'rust-version.*1' Cargo.toml | sed 's/.*\.\([0-9]*\)\..*/\1/')
20+
21+
if [ "${{ inputs.toolchain }}" = "msrv" ]; then
22+
echo "version=1.$msrv.0" >> "$GITHUB_OUTPUT"
23+
else
24+
echo "version=${{ inputs.toolchain }}" >> "$GITHUB_OUTPUT"
25+
fi
26+
27+
- name: Install Rust
28+
shell: bash
29+
run: |
30+
rustup set profile minimal
31+
rustup update "${{ steps.select.outputs.version }}" --no-self-update
32+
rustup default "${{ steps.select.outputs.version }}"
33+
34+
# Save disk space by avoiding incremental compilation. Also turn down
35+
# debuginfo from 2 to 0 to help save disk space.
36+
cat >> "$GITHUB_ENV" <<EOF
37+
CARGO_INCREMENTAL=0
38+
CARGO_PROFILE_DEV_DEBUG=0
39+
CARGO_PROFILE_TEST_DEBUG=0
40+
EOF
41+
42+
# Deny warnings on CI to keep our code warning-free as it lands in-tree.
43+
echo RUSTFLAGS="-D warnings" >> "$GITHUB_ENV"

.github/workflows/ci.yaml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,11 @@ jobs:
1717
strategy:
1818
matrix:
1919
os: [ubuntu-latest, windows-latest, macOS-latest]
20-
rust: [stable]
2120

2221
steps:
2322
- uses: actions/checkout@master
2423

25-
- name: Install ${{ matrix.rust }}
26-
uses: actions-rs/toolchain@v1
27-
with:
28-
toolchain: ${{ matrix.rust }}
29-
target: wasm32-wasip2
30-
override: true
24+
- uses: ./.github/actions/install-rust
3125

3226
- name: Install wasmtime
3327
uses: bytecodealliance/actions/wasmtime/setup@v1
@@ -56,12 +50,7 @@ jobs:
5650
runs-on: ubuntu-latest
5751
steps:
5852
- uses: actions/checkout@master
59-
- uses: actions-rs/toolchain@v1
60-
with:
61-
toolchain: nightly
62-
target: wasm32-wasip2
63-
components: rustfmt, clippy
64-
override: true
53+
- uses: ./.github/actions/install-rust
6554

6655
- name: fmt
6756
run: cargo fmt --all -- --check
@@ -71,3 +60,17 @@ jobs:
7160

7261
- name: Clippy
7362
run: cargo clippy --all
63+
64+
verify-publish:
65+
name: Verify publish
66+
if: github.repository_owner == 'bytecodealliance'
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@master
70+
- uses: ./.github/actions/install-rust
71+
- run: rustc ci/publish.rs
72+
# Make sure we can bump version numbers for the next release
73+
- run: ./publish bump
74+
# Make sure the tree is publish-able as-is
75+
- run: ./publish verify
76+

.github/workflows/publish.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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.
4+
5+
name: Publish Artifacts
6+
on:
7+
push:
8+
branches: [main]
9+
10+
permissions:
11+
contents: write
12+
id-token: write
13+
14+
jobs:
15+
create_tag:
16+
name: Publish artifacts of build
17+
runs-on: ubuntu-latest
18+
environment: release
19+
if: |
20+
github.repository_owner == 'bytecodealliance'
21+
&& github.event_name == 'push'
22+
&& github.ref == 'refs/heads/main'
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
submodules: true
27+
fetch-depth: 0
28+
29+
- run: rustup update stable && rustup default stable
30+
31+
# If this is a push to `main` see if the push has an indicator saying that
32+
# a tag should be made. If so create one and push it.
33+
- name: Test if tag is needed
34+
run: |
35+
git log ${{ github.event.before }}...${{ github.event.after }} | tee main.log
36+
version=$(./ci/print-current-version.sh)
37+
echo "version: $version"
38+
echo "version=$version" >> $GITHUB_OUTPUT
39+
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
40+
if grep -q "automatically-tag-and-release-this-commit" main.log; then
41+
echo push-tag
42+
echo "push_tag=yes" >> $GITHUB_OUTPUT
43+
else
44+
echo no-push-tag
45+
echo "push_tag=no" >> $GITHUB_OUTPUT
46+
fi
47+
id: tag
48+
49+
- name: Push the tag
50+
run: |
51+
git_refs_url=$(jq .repository.git_refs_url $GITHUB_EVENT_PATH | tr -d '"' | sed 's/{\/sha}//g')
52+
curl -iX POST $git_refs_url \
53+
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
54+
-d @- << EOF
55+
{
56+
"ref": "refs/tags/v${{ steps.tag.outputs.version }}",
57+
"sha": "${{ steps.tag.outputs.sha }}"
58+
}
59+
EOF
60+
if: steps.tag.outputs.push_tag == 'yes'
61+
62+
- uses: softprops/action-gh-release@v1
63+
if: steps.tag.outputs.push_tag == 'yes'
64+
with:
65+
tag_name: v${{ steps.tag.outputs.version }}
66+
67+
- uses: rust-lang/crates-io-auth-action@v1
68+
id: auth
69+
if: steps.tag.outputs.push_tag == 'yes'
70+
71+
- run: |
72+
rm -rf main.log
73+
rustc ci/publish.rs
74+
./publish publish
75+
env:
76+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
77+
if: steps.tag.outputs.push_tag == 'yes'
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Initiation half of the release process for this repository.
2+
#
3+
# This is triggered manually through the github actions UI and will execute
4+
# `./publish bump` (or `bump-patch`). Afterwards the result will be pushed to a
5+
# branch in the main repository and a PR will be opened. This PR, when merged,
6+
# will trigger the second half in `publish.yml`.
7+
8+
name: "Automated Release Process"
9+
on:
10+
# Allow manually triggering this request via the button on the action
11+
# workflow page.
12+
workflow_dispatch:
13+
inputs:
14+
action:
15+
description: 'Publish script argument: "bump", or "bump-patch"'
16+
required: false
17+
default: 'bump'
18+
19+
permissions:
20+
contents: write
21+
pull-requests: write
22+
23+
jobs:
24+
release_process:
25+
name: Run the release process
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
with:
30+
submodules: true
31+
- name: Setup
32+
run: |
33+
rustc ci/publish.rs
34+
git config user.name 'Auto Release Process'
35+
git config user.email '[email protected]'
36+
git remote set-url origin https://git:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
37+
38+
- name: Bump version number
39+
run: ./publish ${{ github.event.inputs.action }}
40+
41+
- name: Prep PR metadata
42+
run: |
43+
set -ex
44+
git fetch origin
45+
46+
cur=$(./ci/print-current-version.sh)
47+
48+
git commit --allow-empty -a -F-<<EOF
49+
Release ${{ github.event.repository.name }} $cur
50+
51+
[automatically-tag-and-release-this-commit]
52+
EOF
53+
54+
# Push the result to a branch and setup metadata for the step below
55+
# that creates a PR
56+
git push origin HEAD:ci/release-$cur
57+
echo "PR_HEAD=ci/release-$cur" >> $GITHUB_ENV
58+
echo "PR_TITLE=Release ${{ github.event.repository.name }} $cur" >> $GITHUB_ENV
59+
echo "PR_BASE=main" >> $GITHUB_ENV
60+
cat > pr-body <<-EOF
61+
This is an automated pull request from CI to release
62+
${{ github.event.repository.name }} $cur when merged. The commit
63+
message for this PR has a marker that is detected by CI to create
64+
tags and publish crate artifacts.
65+
66+
When first opened this PR will not have CI run because it is generated
67+
by a bot. A maintainer should close this PR and then reopen it to
68+
trigger CI to execute which will then enable merging this PR.
69+
EOF
70+
71+
- name: Make a PR
72+
run: gh pr create -B "$PR_BASE" -H "$PR_HEAD" --title "$PR_TITLE" --body "$(cat ./pr-body)"
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ target/
22
tmp/
33
Cargo.lock
44
.DS_Store
5+
publish

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ authors.workspace = true
1010
keywords.workspace = true
1111
categories.workspace = true
1212
repository.workspace = true
13+
rust-version.workspace = true
1314

1415
[features]
1516
default = ["json"]
@@ -52,6 +53,8 @@ license = "Apache-2.0 WITH LLVM-exception"
5253
repository = "https://github.com/yoshuawuyts/wstd"
5354
keywords = ["WebAssembly", "async", "stdlib", "Components"]
5455
categories = ["wasm", "asynchronous"]
56+
# Rust-version policy: stable N-2, same as wasmtime.
57+
rust-version = "1.87"
5558
authors = [
5659
"Yoshua Wuyts <[email protected]>",
5760
"Pat Hickey <[email protected]>",

ci/print-current-version.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
grep '^version =' Cargo.toml | head -n 1 | sed 's/.*"\(.*\)"/\1/'

0 commit comments

Comments
 (0)