-
Notifications
You must be signed in to change notification settings - Fork 24
Publish crates to crates.io via trusted publishing #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+121
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| # Publishes a single crate from this workspace to crates.io using Trusted Publishing. | ||
| # | ||
| # There is no `CARGO_REGISTRY_TOKEN` secret: `rust-lang/crates-io-auth-action` exchanges this | ||
| # workflow's GitHub OIDC identity for a short-lived crates.io token that expires after the run. | ||
| # | ||
| # One-time setup per crate, on https://crates.io/crates/<crate>/settings/trusted-publishing: | ||
| # Repository owner: github | ||
| # Repository name: rust-gems | ||
| # Workflow name: publish-crates.yaml | ||
| # Environment: crates-io | ||
| # The environment name must match the `environment:` value below exactly, or crates.io rejects | ||
| # the token exchange. A crate must be published manually once before it can be configured. | ||
| name: Publish crates | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| crate: | ||
| description: Crate to publish, at the version in its Cargo.toml | ||
| required: true | ||
| type: choice | ||
| options: | ||
| - bpe | ||
| - bpe-openai | ||
| - casefold | ||
| - commutative_hasher | ||
| - consistent-choose-k | ||
| - geo_filters | ||
| - hash-sorted-map | ||
| - sparse-ngrams | ||
| - string-offsets | ||
| crate_name_override: | ||
| description: Crate name to publish instead, for crates missing from the list above | ||
| required: false | ||
| type: string | ||
| dry_run: | ||
| description: Package and verify the crate without uploading it | ||
| type: boolean | ||
| default: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write # Required to mint the crates.io OIDC token. | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: Publish ${{ inputs.crate_name_override || inputs.crate }} | ||
| runs-on: ubuntu-latest | ||
| # Gate releases behind an environment so protection rules apply, and so the OIDC claim | ||
| # matches the trusted publisher configured on crates.io. | ||
| environment: crates-io | ||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - uses: rui314/setup-mold@7e4f20ad28a2e8ca6fd0892ccf72e2abb706b9c3 | ||
|
|
||
| # `crate_name_override` wins when set, because a choice input always has one option | ||
| # selected and so can't express "none of these". | ||
| - name: Resolve crate | ||
| id: resolve | ||
| env: | ||
| CHOICE: ${{ inputs.crate }} | ||
| OVERRIDE: ${{ inputs.crate_name_override }} | ||
| run: | | ||
| crate=$(printf '%s' "${OVERRIDE:-$CHOICE}" | tr -d '[:space:]') | ||
| # Check the name against the workspace so a typo fails here with a clear message, | ||
| # and so nothing unvetted reaches the cargo commands below. | ||
| publishable=$(cargo metadata --no-deps --format-version 1 | | ||
| jq -r '.packages[] | select(.publish != []) | .name') | ||
| if ! printf '%s\n' "$publishable" | grep -qxF "$crate"; then | ||
| echo "::error::'$crate' is not a publishable crate. Available: $(echo $publishable)" | ||
| exit 1 | ||
| fi | ||
| echo "crate=$crate" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Package and verify | ||
| run: cargo publish --package "$CRATE" --dry-run | ||
| env: | ||
| CRATE: ${{ steps.resolve.outputs.crate }} | ||
|
|
||
| - name: Get crates.io token | ||
| if: ${{ !inputs.dry_run }} | ||
| id: auth | ||
| uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5 | ||
|
|
||
| # Verification already happened in the dry run above, on this exact tree. | ||
| - name: Publish | ||
| if: ${{ !inputs.dry_run }} | ||
| run: cargo publish --package "$CRATE" --no-verify | ||
| env: | ||
| CRATE: ${{ steps.resolve.outputs.crate }} | ||
| CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| [package] | ||
| name = "bpe-benchmarks" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [lib] | ||
| path = "lib.rs" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| [package] | ||
| name = "casefold-benchmarks" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [lib] | ||
| path = "lib.rs" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.