Skip to content

Commit cc19f31

Browse files
authored
CI: Only run semver checks on crates with a lib target (#403)
#### Problem The semver-checks step during publish doesn't distinguish the current crate targets, and semver-checks only works on crates with lib targets. This means it fails on proc-macro crates, preventing us from publishing. #### Summary of changes Similar to what's done in the program repos at [this workflow](https://github.com/solana-program/actions/blob/3823505ada06f9c8362cd935b73a7f22a1490374/.github/workflows/publish-rust.yml#L103), check for a lib target and then run semver-checks.
1 parent 6f14a71 commit cc19f31

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

.github/workflows/publish-rust.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,28 @@ jobs:
151151
- name: Install cargo-semver-checks
152152
uses: taiki-e/install-action@v2
153153
with:
154-
tool: cargo-semver-checks,cargo-release
154+
tool: toml-cli,cargo-semver-checks,cargo-release
155+
156+
- name: Check if crate has a lib target
157+
id: has_lib
158+
shell: bash
159+
run: |
160+
set +e # toml crashes the whole shell if it fails to find the key
161+
result=$(toml get "${{ inputs.package-path }}/Cargo.toml" lib.crate-type)
162+
if [[ "$result" == *"lib"* ]]; then
163+
echo "has_lib=true" >> "$GITHUB_OUTPUT"
164+
else
165+
echo "has_lib=false" >> "$GITHUB_OUTPUT"
166+
fi
155167
156168
- name: Set Git Author (required for cargo-release)
169+
if: ${{ steps.has_lib.outputs.has_lib == 'true' }}
157170
run: |
158171
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
159172
git config --global user.name "github-actions[bot]"
160173
161174
- name: Set Version
175+
if: ${{ steps.has_lib.outputs.has_lib == 'true' }}
162176
run: |
163177
if [ "${{ inputs.level }}" == "version" ]; then
164178
LEVEL=${{ inputs.version }}
@@ -168,6 +182,7 @@ jobs:
168182
cargo release $LEVEL --manifest-path "${{ inputs.package_path }}/Cargo.toml" --no-tag --no-publish --no-push --no-confirm --execute
169183
170184
- name: Check semver
185+
if: ${{ steps.has_lib.outputs.has_lib == 'true' }}
171186
run: cargo semver-checks --manifest-path "${{ inputs.package_path }}/Cargo.toml"
172187

173188
publish-crate:

0 commit comments

Comments
 (0)