-
Notifications
You must be signed in to change notification settings - Fork 58
90 lines (80 loc) · 3.99 KB
/
Copy pathrelease.yml
File metadata and controls
90 lines (80 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+*"
permissions:
contents: write
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@4360b52568e2003a75bf9bc1d59f33a8e3fc893c # stable
- name: Inject version from tag
run: |
tag_version="${GITHUB_REF_NAME#v}"
echo "Releasing version: $tag_version"
# Replace the 0.0.0 placeholder under [workspace.package] with the tag version.
sed -i 's/^version = "0\.0\.0"$/version = "'"$tag_version"'"/' Cargo.toml
# Pin spacewasm_c_api's dependency on spacewasm to the exact tag version.
# Its manifest carries a `version = "=0.0.0"` placeholder for this.
sed -i 's/version = "=0\.0\.0"/version = "='"$tag_version"'"/' crates/spacewasm_c_api/Cargo.toml
# Fail if any placeholder was not found / not replaced.
for pkg in spacewasm spacewasm_c_api; do
crate_version=$(cargo metadata --no-deps --format-version 1 \
| jq -r '.packages[] | select(.name == "'"$pkg"'") | .version')
if [ "$crate_version" != "$tag_version" ]; then
echo "::error::Failed to inject version for $pkg. Expected $tag_version but Cargo.toml resolves to $crate_version. Is the 0.0.0 placeholder still present?"
exit 1
fi
done
dep_version=$(cargo metadata --no-deps --format-version 1 \
| jq -r '.packages[] | select(.name == "spacewasm_c_api") | .dependencies[] | select(.name == "spacewasm") | .req')
if [ "$dep_version" != "=$tag_version" ]; then
echo "::error::spacewasm_c_api's spacewasm dependency resolves to '$dep_version', expected '=$tag_version'. Is the =0.0.0 placeholder still present?"
exit 1
fi
- name: Install WABT (WebAssembly Binary Toolkit)
uses: ./.github/actions/install-wabt
- name: Run tests
run: cargo test --workspace --verbose
- name: Publish spacewasm to crates.io
# --allow-dirty: the injected version is an uncommitted working-tree change.
run: cargo publish -p spacewasm --allow-dirty
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Verify spacewasm_c_api packaging
run: |
cargo build -p spacewasm_c_api --release --verbose
cargo package -p spacewasm_c_api --allow-dirty --no-verify
- name: Publish spacewasm_c_api to crates.io
# Published after spacewasm since it depends on the exact matching
# release. cargo waits for the dependency to be available in the index.
# --allow-dirty: the injected version is an uncommitted working-tree change.
# --no-verify: skips cargo's verify build, which fails with "unwinding
# panics are not supported without std" for this no_std `panic = "abort"`
# staticlib/cdylib.
run: cargo publish -p spacewasm_c_api --allow-dirty --no-verify
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Create GitHub Release
# Do NOT use an action that regenerates notes unconditionally: if the
# release already exists (e.g. created from the GitHub UI, which also
# creates the tag that triggers this workflow), generate_release_notes
# *appends* a second copy of the changelog to the existing body
# (softprops/action-gh-release#827). Generate notes only when creating a
# brand-new release so the changelog is written exactly once.
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME}"
if gh release view "$tag" >/dev/null 2>&1; then
echo "Release $tag already exists; leaving its notes untouched."
else
gh release create "$tag" --generate-notes --verify-tag
fi