Skip to content

Commit ff4720c

Browse files
committed
fix: release action
1 parent c4bcf75 commit ff4720c

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

.github/workflows/release.yml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,65 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v4
1919

20-
- name: Read MSRV from Cargo.toml
21-
id: msrv
20+
# Install a minimal Rust toolchain so that `cargo metadata` is available.
21+
- name: Install Rust (stable, minimal)
22+
uses: dtolnay/rust-toolchain@v1
23+
with:
24+
toolchain: stable
25+
profile: minimal
26+
27+
- name: Ensure jq is available
2228
shell: bash
2329
run: |
2430
set -euo pipefail
2531
if ! command -v jq >/dev/null 2>&1; then
2632
sudo apt-get update -y && sudo apt-get install -y jq
2733
fi
28-
RV=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].rust_version // empty')
29-
if [ -z "$RV" ]; then
30-
echo "rust-version is not set in Cargo.toml"
34+
35+
- name: Read MSRV from Cargo.toml (crate = masterror)
36+
id: msrv
37+
shell: bash
38+
run: |
39+
set -euo pipefail
40+
CRATE_NAME="masterror"
41+
RV="$(
42+
cargo metadata --no-deps --format-version=1 |
43+
jq -r --arg name "$CRATE_NAME" '
44+
.packages[]
45+
| select(.name == $name and .source == null)
46+
| .rust_version // empty
47+
' | head -n1
48+
)"
49+
if [ -z "${RV:-}" ]; then
50+
echo "rust-version is not set for crate: ${CRATE_NAME}"
3151
exit 1
3252
fi
53+
# Normalize X.Y to X.Y.0
3354
if [[ "$RV" =~ ^[0-9]+\.[0-9]+$ ]]; then
3455
RV="${RV}.0"
3556
fi
3657
echo "msrv=${RV}" >> "$GITHUB_OUTPUT"
3758
38-
- name: Ensure tag matches Cargo.toml version
59+
- name: Ensure tag matches Cargo.toml version (crate = masterror)
3960
shell: bash
4061
run: |
4162
set -euo pipefail
4263
TAG="${GITHUB_REF#refs/tags/}"
43-
FILE_VER=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')
64+
CRATE_NAME="masterror"
65+
FILE_VER="$(
66+
cargo metadata --no-deps --format-version=1 |
67+
jq -r --arg name "$CRATE_NAME" '
68+
.packages[]
69+
| select(.name == $name and .source == null)
70+
| .version
71+
' | head -n1
72+
)"
73+
if [ -z "${FILE_VER:-}" ]; then
74+
echo "Cannot determine version for crate: ${CRATE_NAME}"
75+
exit 1
76+
fi
4477
if [ "v${FILE_VER}" != "${TAG}" ]; then
45-
echo "Tag ${TAG} != Cargo.toml version v${FILE_VER}"
78+
echo "Tag ${TAG} != ${CRATE_NAME} version v${FILE_VER}"
4679
exit 1
4780
fi
4881
@@ -55,3 +88,4 @@ jobs:
5588
env:
5689
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
5790
run: cargo +${{ steps.msrv.outputs.msrv }} publish --locked --token "$CARGO_REGISTRY_TOKEN"
91+

0 commit comments

Comments
 (0)