Skip to content

Commit db36651

Browse files
committed
add release workflow
Signed-off-by: Aaqa Ishtyaq <aaqaishtyaq@gmail.com>
1 parent d81168b commit db36651

1 file changed

Lines changed: 130 additions & 36 deletions

File tree

.github/workflows/release.yml

Lines changed: 130 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,150 @@
11
name: Release
22

3-
permissions:
4-
contents: write
5-
63
on:
74
push:
8-
tags:
9-
- v[0-9]+.*
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
1010

1111
env:
12-
RUSTFLAGS: -D warnings --cfg tokio_unstable
1312
CARGO_TERM_COLOR: always
13+
RUSTFLAGS: -D warnings --cfg tokio_unstable
1414

1515
jobs:
16-
create-release:
17-
runs-on: ubuntu-latest
16+
release-meta:
17+
name: Prepare release metadata
18+
runs-on: ubuntu-24.04
19+
outputs:
20+
release_name: ${{ steps.meta.outputs.release_name }}
21+
short_sha: ${{ steps.meta.outputs.short_sha }}
22+
tag: ${{ steps.meta.outputs.tag }}
23+
version: ${{ steps.meta.outputs.version }}
1824
steps:
19-
- uses: actions/checkout@v3
20-
- uses: taiki-e/create-gh-release-action@v1
21-
with:
22-
token: ${{ secrets.GITHUB_TOKEN }}
25+
- uses: actions/checkout@v4
26+
27+
- id: meta
28+
name: Derive release metadata
29+
shell: bash
30+
run: |
31+
set -euo pipefail
32+
33+
version="$(sed -n 's/^version = "\(.*\)"$/\1/p' crates/corrosion/Cargo.toml | head -n 1)"
34+
if [[ -z "${version}" ]]; then
35+
echo "Failed to read the corrosion package version" >&2
36+
exit 1
37+
fi
2338
24-
upload-assets:
39+
short_sha="${GITHUB_SHA::7}"
40+
tag="v${version}-main-${short_sha}"
41+
release_name="corrosion ${version} (${short_sha})"
42+
43+
{
44+
echo "release_name=${release_name}"
45+
echo "short_sha=${short_sha}"
46+
echo "tag=${tag}"
47+
echo "version=${version}"
48+
} >> "${GITHUB_OUTPUT}"
49+
50+
build-assets:
51+
name: Build ${{ matrix.arch }} release asset
52+
needs: release-meta
53+
runs-on: ${{ matrix.os }}
2554
strategy:
55+
fail-fast: false
2656
matrix:
2757
include:
28-
- target: aarch64-apple-darwin
29-
os: macos-latest
30-
- target: x86_64-unknown-linux-gnu
31-
os: ubuntu-latest
32-
- target: aarch64-unknown-linux-gnu
33-
os: ubuntu-latest
34-
runs-on: ${{ matrix.os }}
35-
env:
36-
SCCACHE_GHA_ENABLED: "true"
37-
RUSTC_WRAPPER: "sccache"
58+
- arch: amd64
59+
os: ubuntu-24.04
60+
target: x86_64-unknown-linux-gnu
61+
- arch: arm64
62+
os: ubuntu-24.04-arm
63+
target: aarch64-unknown-linux-gnu
3864
steps:
39-
- uses: actions/checkout@v3
40-
41-
- uses: rui314/setup-mold@v1
65+
- uses: actions/checkout@v4
4266

43-
- uses: taiki-e/setup-cross-toolchain-action@v1
67+
- name: Install Rust toolchain
68+
uses: dtolnay/rust-toolchain@stable
4469
with:
45-
target: ${{ matrix.target }}
46-
if: startsWith(matrix.os, 'ubuntu')
70+
toolchain: 1.89
71+
targets: ${{ matrix.target }}
72+
73+
- name: Install Linux build dependencies
74+
run: |
75+
sudo apt-get update
76+
sudo apt-get install --yes libsystemd-dev pkg-config
77+
78+
- name: Build release binary
79+
run: cargo build --locked --release --bin corrosion --target ${{ matrix.target }}
4780

48-
- name: Run sccache-cache
49-
uses: mozilla-actions/sccache-action@v0.0.9
81+
- name: Package release archive
82+
shell: bash
83+
run: |
84+
set -euo pipefail
85+
86+
mkdir -p dist
87+
cp "target/${{ matrix.target }}/release/corrosion" dist/corrosion
88+
tar -C dist -czf "corrosion-linux-${{ matrix.arch }}.tar.gz" corrosion
89+
sha256sum "corrosion-linux-${{ matrix.arch }}.tar.gz" > "corrosion-linux-${{ matrix.arch }}.tar.gz.sha256"
90+
91+
- name: Upload packaged assets
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: release-${{ matrix.arch }}
95+
path: |
96+
corrosion-linux-${{ matrix.arch }}.tar.gz
97+
corrosion-linux-${{ matrix.arch }}.tar.gz.sha256
5098
51-
- uses: taiki-e/upload-rust-binary-action@v1
99+
publish-release:
100+
name: Publish GitHub release
101+
needs:
102+
- release-meta
103+
- build-assets
104+
runs-on: ubuntu-24.04
105+
steps:
106+
- name: Download packaged assets
107+
uses: actions/download-artifact@v4
52108
with:
53-
bin: corrosion
54-
archive: "corrosion-$target"
55-
target: ${{ matrix.target }}
56-
token: ${{ secrets.GITHUB_TOKEN }}
109+
merge-multiple: true
110+
path: dist
111+
pattern: release-*
112+
113+
- name: Write release notes
114+
shell: bash
115+
run: |
116+
cat <<EOF > release-notes.md
117+
Automated prerelease from main.
118+
119+
- Version: \`${{ needs.release-meta.outputs.version }}\`
120+
- Commit: [\`${{ github.sha }}\`](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
121+
122+
Release assets:
123+
- \`corrosion-linux-amd64.tar.gz\`
124+
- \`corrosion-linux-arm64.tar.gz\`
125+
EOF
126+
127+
- name: Create or update GitHub release
128+
env:
129+
GH_TOKEN: ${{ github.token }}
130+
RELEASE_NAME: ${{ needs.release-meta.outputs.release_name }}
131+
TAG: ${{ needs.release-meta.outputs.tag }}
132+
shell: bash
133+
run: |
134+
set -euo pipefail
135+
136+
if gh release view "${TAG}" >/dev/null 2>&1; then
137+
gh release edit "${TAG}" \
138+
--notes-file release-notes.md \
139+
--prerelease \
140+
--title "${RELEASE_NAME}"
141+
else
142+
gh release create "${TAG}" \
143+
--latest=false \
144+
--notes-file release-notes.md \
145+
--prerelease \
146+
--target "${GITHUB_SHA}" \
147+
--title "${RELEASE_NAME}"
148+
fi
149+
150+
gh release upload "${TAG}" dist/* --clobber

0 commit comments

Comments
 (0)