Skip to content

Commit

Permalink
Merge #266
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and Taowyoo authored Jun 12, 2023
2 parents ce358f4 + 8b43e38 commit 4cb8132
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/publish-crates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Publish Crates

on:
release:
types: [created]
workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- run: |
crate_name=$(python3 -c "print('$GITHUB_REF'.split('/')[2].rsplit('_v', 1)[0])") && \
cargo publish --token ${CARGO_REGISTRY_TOKEN} --package "$crate_name" --dry-run
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

0 comments on commit 4cb8132

Please sign in to comment.