Skip to content

Commit d49ace7

Browse files
committed
chore(github): verify release tag matches Cargo.toml before publishing anything
1 parent 9722991 commit d49ace7

1 file changed

Lines changed: 30 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,36 @@ jobs:
3737
echo "Using ref: $REF"
3838
echo "Using version: $VERSION"
3939
40+
verify-version:
41+
name: Verify version matches tag
42+
needs: setup
43+
runs-on: ubuntu-latest
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
with:
48+
ref: ${{ needs.setup.outputs.ref }}
49+
50+
- name: Verify Cargo.toml version matches tag
51+
run: |
52+
TAG_VERSION="${{ needs.setup.outputs.version }}"
53+
# Remove 'v' prefix if present
54+
TAG_VERSION="${TAG_VERSION#v}"
55+
CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d'"' -f2)
56+
57+
echo "Tag version: $TAG_VERSION"
58+
echo "Cargo.toml version: $CARGO_VERSION"
59+
60+
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
61+
echo "❌ Error: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)"
62+
echo "Please ensure the version in Cargo.toml matches the tag you're trying to release."
63+
exit 1
64+
fi
65+
echo "✅ Version check passed!"
66+
4067
test:
4168
name: Run tests
42-
needs: setup
69+
needs: [setup, verify-version]
4370
runs-on: ubuntu-latest
4471

4572
steps:
@@ -58,7 +85,7 @@ jobs:
5885

5986
build-binaries:
6087
name: Build binaries
61-
needs: [setup, test]
88+
needs: [setup, verify-version, test]
6289
strategy:
6390
matrix:
6491
include:
@@ -252,14 +279,9 @@ jobs:
252279
- name: Install Rust
253280
uses: dtolnay/rust-toolchain@stable
254281

255-
- name: Verify version matches tag
282+
- name: Get Cargo version for checking
256283
run: |
257-
TAG_VERSION="${GITHUB_REF#refs/tags/v}"
258284
CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | cut -d'"' -f2)
259-
if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
260-
echo "Error: Tag version ($TAG_VERSION) doesn't match Cargo.toml version ($CARGO_VERSION)"
261-
exit 1
262-
fi
263285
echo "CARGO_VERSION=$CARGO_VERSION" >> $GITHUB_ENV
264286
265287
- name: Authenticate with crates.io

0 commit comments

Comments
 (0)