Skip to content

Commit b7fe019

Browse files
committed
Add crates.io publish composite action
1 parent 64e2b8c commit b7fe019

File tree

1 file changed

+53
-0
lines changed
  • .github/workflows/actions/publish-crate-package

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: publish-crate-package
2+
description: |
3+
Deploy the crate package to crates.io
4+
inputs:
5+
dry_run:
6+
description: Dry run will not publish to crates.io, just test it.
7+
required: true
8+
package:
9+
description: crate package name.
10+
required: true
11+
api_token:
12+
description: crates.io API token.
13+
required: false
14+
15+
runs:
16+
using: "composite"
17+
steps:
18+
- name: Check crate latest version
19+
id: check_version
20+
shell: bash
21+
run: |
22+
echo "Check crate latest published version for '${{ inputs.package}}' package"
23+
LATEST_REMOTE_VERSION=$(curl -sL https://crates.io/api/v1/crates/${{ inputs.package}} | jq -r '.crate.newest_version')
24+
LOCAL_VERSION=$(cargo metadata --quiet --no-deps | jq -r '.packages[] | select(.name=="${{ inputs.package}}") | .version')
25+
echo "Latest crate.io version: $LATEST_REMOTE_VERSION"
26+
echo "Local version: $LOCAL_VERSION"
27+
28+
if [ "$LOCAL_VERSION" != "$LATEST_REMOTE_VERSION" ]; then
29+
echo "Local version is newer than remote version: we will publish to crates.io"
30+
echo "should_deploy=true" >> $GITHUB_OUTPUT
31+
else
32+
echo "Local version and remote version are the same: no need to publish to crates.io"
33+
echo "should_deploy=false" >> $GITHUB_OUTPUT
34+
fi
35+
36+
- name: Cargo publish dry run
37+
shell: bash
38+
run: |
39+
echo "Cargo publish '${{ inputs.package}}' package (dry run)"
40+
cargo publish -p ${{ inputs.package}} --dry-run --no-verify
41+
42+
- name: Cargo package list
43+
shell: bash
44+
run: |
45+
echo "Cargo package list '${{ inputs.package}}' package"
46+
cargo package -p ${{ inputs.package}} --list
47+
48+
- name: Cargo publish
49+
if: inputs.dry_run == 'false' && steps.check_version.outputs.should_deploy == 'true'
50+
shell: bash
51+
run: |
52+
echo "Cargo publish '${{ inputs.package}}' package"
53+
cargo publish -p ${{ inputs.package}} --token ${{ inputs.api_token }} --no-verify

0 commit comments

Comments
 (0)