Skip to content

Commit b503b24

Browse files
authored
CI: Fix semver checks on publish (#44)
* CI: Fix semver checks to use a script #### Problem The semver checks step during publish is broken because it's simply passing in the folder, but there's some additional work needed to decompose it into a manifest path. #### Summary of changes Similar to many other repos, add a semver script which will pull out the manifest given a path. * Do it differently * Use pinocchio style * Install things consistently * Make publish depend on semver check * Add back version options (and fix inputs.crate)
1 parent ef92ca0 commit b503b24

File tree

1 file changed

+49
-10
lines changed

1 file changed

+49
-10
lines changed

Diff for: .github/workflows/publish-rust.yml

+49-10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ on:
2222
- patch
2323
- minor
2424
- major
25+
- rc
26+
- beta
27+
- alpha
28+
- release
29+
- version
30+
version:
31+
description: Version (used with level "version")
32+
required: false
33+
type: string
2534
dry_run:
2635
description: Dry run
2736
required: true
@@ -50,11 +59,6 @@ jobs:
5059
cargo-cache-key: cargo-test-publish-${{ inputs.package_path }}
5160
cargo-cache-fallback-key: cargo-test-publish
5261

53-
- name: Install cargo-audit
54-
uses: taiki-e/install-action@v2
55-
with:
56-
tool: cargo-semver-checks
57-
5862
- name: Format
5963
run: pnpm zx ./scripts/rust/format.mjs "${{ inputs.package_path }}"
6064

@@ -67,13 +71,40 @@ jobs:
6771
- name: Test
6872
run: pnpm zx ./scripts/rust/test.mjs "${{ inputs.package_path }}"
6973

74+
semver:
75+
name: Check Semver
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Git checkout
79+
uses: actions/checkout@v4
80+
81+
- name: Setup Environment
82+
uses: ./.github/actions/setup
83+
with:
84+
cargo-cache-key: cargo-publish-semver-${{ inputs.package_path }}
85+
cargo-cache-fallback-key: cargo-publish-semver
86+
87+
- name: Install cargo-semver-checks
88+
uses: taiki-e/install-action@v2
89+
with:
90+
tool: cargo-semver-checks,cargo-release
91+
92+
- name: Set Version
93+
run: |
94+
if [ "${{ inputs.level }}" == "version" ]; then
95+
LEVEL=${{ inputs.version }}
96+
else
97+
LEVEL=${{ inputs.level }}
98+
fi
99+
cargo release $LEVEL --manifest-path " ${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute
100+
70101
- name: Check semver
71-
run: pnpm rust:semver ${{ inputs.package_path }} --release-type ${{ inputs.level }}
102+
run: pnpm rust:semver --manifest-path "${{ inputs.package_path }}/Cargo.toml"
72103

73104
publish:
74105
name: Publish Rust Crate
75106
runs-on: ubuntu-latest
76-
needs: test
107+
needs: [test, semver]
77108
permissions:
78109
contents: write
79110
steps:
@@ -89,8 +120,10 @@ jobs:
89120
cargo-cache-key: cargo-publish-${{ inputs.package_path }}
90121
cargo-cache-fallback-key: cargo-publish
91122

92-
- name: Install Cargo Release
93-
run: which cargo-release || cargo install cargo-release
123+
- name: Install cargo-release
124+
uses: taiki-e/install-action@v2
125+
with:
126+
tool: cargo-release
94127

95128
- name: Ensure CARGO_REGISTRY_TOKEN variable is set
96129
env:
@@ -111,13 +144,19 @@ jobs:
111144
env:
112145
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
113146
run: |
147+
if [ "${{ inputs.level }}" == "version" ]; then
148+
LEVEL=${{ inputs.version }}
149+
else
150+
LEVEL=${{ inputs.level }}
151+
fi
152+
114153
if [ "${{ inputs.dry_run }}" == "true" ]; then
115154
OPTIONS="--dry-run"
116155
else
117156
OPTIONS=""
118157
fi
119158
120-
pnpm rust:publish "${{ inputs.package_path }}" "${{ inputs.level }}" $OPTIONS
159+
pnpm rust:publish "${{ inputs.package_path }}" $LEVEL $OPTIONS
121160
122161
- name: Generate a changelog
123162
if: github.event.inputs.create_release == 'true'

0 commit comments

Comments
 (0)