1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
name: Publish to crates.io
# This workflow publishes the crate to crates.io when a new tag is pushed
# Requirements:
# - Tag must start with 'v' (e.g., v0.3.1)
# - CRATES_IO_TOKEN must be set in the repository secrets
# (Settings > Secrets and variables > Actions)
on:
push:
tags:
- 'v*'
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
# Check if CRATES_IO_TOKEN secret is available
# This step will fail if the secret is not set
- name: Validate crates.io token
run: |
if [ -z "${CARGO_REGISTRY_TOKEN}" ]; then
echo "::error::CRATES_IO_TOKEN is not set in GitHub repository secrets"
echo "Please add CRATES_IO_TOKEN in repository Settings > Secrets and variables > Actions"
exit 1
else
echo "Crates.io token is configured correctly"
fi
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish