Skip to content

Commit 611a0ee

Browse files
authored
Add release workflow (#68)
1 parent e24e05a commit 611a0ee

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

.github/workflows/release.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Release
2+
3+
run-name: "Release run '${{ github.head_ref || github.ref_name }}'"
4+
5+
on:
6+
workflow_dispatch:
7+
8+
jobs:
9+
semver:
10+
name: semver
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Check semver
15+
uses: obi1kenobi/cargo-semver-checks-action@v2
16+
17+
release:
18+
name: Process Release
19+
runs-on: ubuntu-latest
20+
needs: semver
21+
permissions:
22+
contents: write # required for creating tags and GitHub releases
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Install Rust toolchain
30+
uses: dtolnay/rust-toolchain@stable
31+
32+
- name: Cache dependencies
33+
uses: Swatinem/rust-cache@v2
34+
35+
- name: Install a TOML parser
36+
run: |
37+
curl -L https://github.com/tamasfe/taplo/releases/download/0.8.1/taplo-full-linux-x86_64.gz | gunzip - > taplo
38+
chmod +x taplo
39+
sudo mv taplo /usr/bin/taplo
40+
41+
- name: Configure git
42+
run: |
43+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
44+
git config user.name "github-actions[bot]"
45+
git config --add --bool push.autoSetupRemote true
46+
47+
- name: Extract version from branch name
48+
id: version
49+
run: |
50+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
51+
VERSION="${BRANCH_NAME#release/}"
52+
echo "Version from branch: $VERSION"
53+
54+
# Validate version matches Cargo.toml
55+
CARGO_VERSION=$(taplo get -f Cargo.toml "package.version")
56+
if [ "$VERSION" != "$CARGO_VERSION" ]; then
57+
echo "Error: Branch version ($VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)"
58+
exit 1
59+
fi
60+
61+
echo "version=$VERSION" >> $GITHUB_OUTPUT
62+
63+
- name: Create and push tag
64+
run: |
65+
git tag -a "v${{ steps.version.outputs.version }}" -m "Release version ${{ steps.version.outputs.version }}"
66+
git push origin "v${{ steps.version.outputs.version }}"
67+
68+
- name: Publish crate
69+
env:
70+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
71+
run: cargo publish
72+
73+
- name: Create GitHub Release
74+
uses: softprops/action-gh-release@v1
75+
with:
76+
tag_name: v${{ steps.version.outputs.version }}
77+
name: Release ${{ steps.version.outputs.version }}
78+
draft: false
79+
prerelease: false
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)