Skip to content

Commit 663f659

Browse files
committed
Validate version against Cargo.toml
This is strongly inspired by an analogous check in the ripgrep workflow, but done differently (from how that currently does it) by parsing `Cargo.toml` using `yq`. The `yq` command supports reading TOML (just not writing it). This command is present on the `ubuntu-latest` runner. This also moves the "Show the version" step into the new step, and has that step also show the version extracted from `Cargo.toml`, so as to make errors easier to understand and also to help verify that this logic is really working.
1 parent 7306b20 commit 663f659

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

.github/workflows/release.yml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,31 @@ jobs:
3030
# VERSION: TEST-0.0.0
3131

3232
steps:
33-
- name: Create artifacts directory
34-
run: mkdir artifacts
33+
- name: Checkout repository
34+
uses: actions/checkout@v4
3535

3636
- name: Get the release version from the tag
3737
if: env.VERSION == ''
3838
run: echo 'VERSION=${{ github.ref_name }}' >> "$GITHUB_ENV"
3939

40-
- name: Show the version
40+
- name: Validate version against Cargo.toml
4141
run: |
42-
echo "version is: $VERSION"
42+
manifest_version="$(yq -r .package.version Cargo.toml)"
43+
echo "version to give the release: $VERSION"
44+
echo "version Cargo.toml declares: $manifest_version"
45+
46+
case "$VERSION" in
47+
"$manifest_version")
48+
echo "OK: Version to give the relase agrees with top-level Cargo.toml."
49+
;;
50+
*)
51+
echo "STOPPING: Version to give the release seems mistaken."
52+
exit 1
53+
;;
54+
esac
55+
56+
- name: Create artifacts directory
57+
run: mkdir artifacts
4358

4459
- name: Create GitHub release
4560
id: release

0 commit comments

Comments
 (0)