Skip to content

Commit 40144dd

Browse files
committed
ci: add publish-crate workflow triggered by v* tags
uses oidc auth via rust-lang/crates-io-auth-action so no api token needs to be stored as a repo secret. verifies the tag matches the cargo.toml version before publishing to catch typos.
1 parent a9cc6c2 commit 40144dd

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish Crate
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
jobs:
9+
publish:
10+
name: Publish to crates.io
11+
runs-on: ubuntu-latest
12+
environment: crates-io
13+
permissions:
14+
contents: read
15+
id-token: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- uses: dtolnay/rust-toolchain@stable
20+
21+
- name: Verify tag matches Cargo.toml version
22+
run: |
23+
tag_version="${GITHUB_REF_NAME#v}"
24+
cargo_version="$(cargo pkgid | sed -E 's/.*[#@]([0-9]+\.[0-9]+\.[0-9]+.*)$/\1/')"
25+
if [ "$tag_version" != "$cargo_version" ]; then
26+
echo "Tag $GITHUB_REF_NAME does not match Cargo.toml version $cargo_version"
27+
exit 1
28+
fi
29+
30+
- name: Authenticate with crates.io
31+
id: auth
32+
uses: rust-lang/crates-io-auth-action@v1
33+
34+
- name: Publish lora-packet
35+
run: cargo publish
36+
env:
37+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

0 commit comments

Comments
 (0)