Skip to content

Commit 4cb8132

Browse files
bors[bot]Taowyoo
andauthored
Merge #266
266: ci: add workflow to publish crates to crates.io r=Taowyoo a=Taowyoo This PR add a github action to automate the publish of crates to crates.io. In this PR I added `--dry-run` so we could test it first to avoid anything wrong. And this action need the tag used for creating release follow this syntax: {crate_name}_v{version_value} This workflow depends on the secret `CARGO_REGISTRY_TOKEN` > [Using environments for deployment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment): Then since we need secret to be used to publish new versions to crates.io , GitHub offers Configure environments to set rules before a job can proceed and to limit access to secrets. so jobs that need access to specific secret need approval, more ref: [security-guides/encrypted-secrets](https://docs.github.com/en/github-ae@latest/actions/security-guides/encrypted-secrets) Need owner to add this organization level secret named `CARGO_REGISTRY_TOKEN` with proper access policy! CC: `@jethrogb` `@Goirad` `@chavipuri` Co-authored-by: Yuxiang Cao <[email protected]> Co-authored-by: YxC <[email protected]>
2 parents ce358f4 + 8b43e38 commit 4cb8132

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

.github/workflows/publish-crates.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish Crates
2+
3+
on:
4+
release:
5+
types: [created]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: actions-rs/toolchain@v1
17+
with:
18+
toolchain: stable
19+
override: true
20+
- run: |
21+
crate_name=$(python3 -c "print('$GITHUB_REF'.split('/')[2].rsplit('_v', 1)[0])") && \
22+
cargo publish --token ${CARGO_REGISTRY_TOKEN} --package "$crate_name" --dry-run
23+
env:
24+
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 commit comments

Comments
 (0)