Skip to content

Commit 8e1ce3d

Browse files
committed
Add GitHub Actions workflow for publishing to crates.io on tag push
1 parent 21f5951 commit 8e1ce3d

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# .github/workflows/publish.yml
2+
name: Publish (crates.io)
3+
4+
on:
5+
push:
6+
tags:
7+
- "v*.*.*" # e.g. v1.2.3
8+
workflow_dispatch: # allow manual runs
9+
10+
permissions:
11+
contents: write
12+
id-token: write
13+
14+
concurrency:
15+
group: publish-${{ github.ref }}
16+
cancel-in-progress: false
17+
18+
jobs:
19+
publish-crate:
20+
name: Publish to crates.io
21+
runs-on: ubuntu-latest
22+
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
23+
steps:
24+
- uses: actions/checkout@v6
25+
with:
26+
fetch-depth: 0
27+
28+
# Toolchain
29+
- uses: dtolnay/rust-toolchain@stable
30+
31+
# Verify Cargo.toml version matches the tag
32+
- name: Verify crate version matches tag
33+
shell: bash
34+
run: |
35+
CRATE_VERSION=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')
36+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
37+
test "$CRATE_VERSION" = "$TAG_VERSION" || (echo "Tag $TAG_VERSION != Cargo.toml $CRATE_VERSION" && exit 1)
38+
39+
# Dry run first (good practice)
40+
- name: cargo publish (dry run)
41+
run: cargo publish --dry-run
42+
43+
- uses: rust-lang/crates-io-auth-action@v1
44+
id: auth
45+
- run: cargo publish
46+
env:
47+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

0 commit comments

Comments
 (0)