Skip to content

Commit 12570c5

Browse files
committed
ci: simplify release workflow to read version from Cargo.toml
Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent a13793a commit 12570c5

1 file changed

Lines changed: 14 additions & 32 deletions

File tree

.github/workflows/release.yml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ name: Create release
22

33
on:
44
workflow_dispatch:
5-
inputs:
6-
version:
7-
description: 'Release version (e.g., 0.2.0) — without the v prefix'
8-
required: true
9-
type: string
105

116
concurrency:
127
group: release
@@ -23,44 +18,31 @@ jobs:
2318
with:
2419
ref: main
2520

26-
- name: Validate version input
21+
- name: Read version from Cargo.toml
22+
id: version
23+
working-directory: host
24+
run: |
25+
VERSION=$(grep '^version' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/')
26+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
27+
echo "Detected version: $VERSION"
28+
29+
- name: Validate version
2730
run: |
28-
VERSION="${{ github.event.inputs.version }}"
31+
VERSION="${{ steps.version.outputs.version }}"
2932
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
30-
echo "::error::Invalid version '$VERSION' — expected semver like 1.2.3"
33+
echo "::error::Invalid version '$VERSION' in Cargo.toml — expected semver like 1.2.3"
3134
exit 1
3235
fi
3336
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
34-
echo "::error::Tag v$VERSION already exists"
37+
echo "::error::Tag v$VERSION already exists — bump the version in Cargo.toml first"
3538
exit 1
3639
fi
3740
38-
- uses: Swatinem/rust-cache@v2
39-
with:
40-
workspaces: host -> target
41-
42-
- name: Bump Cargo.toml version
43-
working-directory: host
44-
run: |
45-
VERSION="${{ github.event.inputs.version }}"
46-
sed -i "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
47-
cargo generate-lockfile
48-
grep "^version" Cargo.toml
49-
50-
- name: Commit version bump
51-
run: |
52-
VERSION="${{ github.event.inputs.version }}"
53-
git config user.name "github-actions[bot]"
54-
git config user.email "github-actions[bot]@users.noreply.github.com"
55-
git add host/Cargo.toml host/Cargo.lock
56-
git commit -m "release: v$VERSION"
57-
git push origin main
58-
5941
- name: Create tag and GitHub Release
6042
env:
6143
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6244
run: |
63-
VERSION="${{ github.event.inputs.version }}"
45+
VERSION="${{ steps.version.outputs.version }}"
6446
git tag "v$VERSION"
6547
git push origin "v$VERSION"
6648
gh release create "v$VERSION" \
@@ -71,5 +53,5 @@ jobs:
7153
env:
7254
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7355
run: |
74-
VERSION="${{ github.event.inputs.version }}"
56+
VERSION="${{ steps.version.outputs.version }}"
7557
gh workflow run publish-examples.yml --ref "v$VERSION"

0 commit comments

Comments
 (0)