Skip to content

Commit df2be8d

Browse files
committed
ci(release): publish to crates.io via trusted publishing
Add a publish-rust job mirroring cooklang-rs: OIDC auth through rust-lang/crates-io-auth-action, then `cargo publish --no-verify`. It depends on create-release rather than the build jobs — a crates.io publish can only be yanked, never redone, so it should not run unless the tag and GitHub release actually landed. Also adopt two cooklang-rs conventions: a dry_run input gating all three publish/release jobs, and prerelease derived from alpha/beta/rc in the version string instead of hardcoded false. Requires one-time setup on crates.io: Trusted Publishing for cooklang/cooklang-import with workflow filename release.yml.
1 parent aec4293 commit df2be8d

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

.github/workflows/release.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ on:
77
description: 'Release version (e.g., 0.8.16)'
88
required: true
99
type: string
10+
dry_run:
11+
description: 'Dry run (skip release creation and publishing)'
12+
required: false
13+
default: false
14+
type: boolean
1015

1116
env:
1217
CARGO_TERM_COLOR: always
@@ -351,6 +356,7 @@ jobs:
351356
name: Create Tags and Release
352357
needs: [prepare-release, build-ios, build-android, update-package-swift]
353358
runs-on: ubuntu-latest
359+
if: ${{ github.event.inputs.dry_run != 'true' }}
354360
permissions:
355361
contents: write
356362
steps:
@@ -391,7 +397,7 @@ jobs:
391397
tag_name: ${{ needs.prepare-release.outputs.version_tag }}
392398
name: Release ${{ needs.prepare-release.outputs.version_tag }}
393399
draft: false
394-
prerelease: false
400+
prerelease: ${{ contains(github.event.inputs.version, 'alpha') || contains(github.event.inputs.version, 'beta') || contains(github.event.inputs.version, 'rc') }}
395401
generate_release_notes: true
396402
files: |
397403
CooklangImportFFI.xcframework.zip
@@ -456,6 +462,7 @@ jobs:
456462
name: Publish Android to GitHub Packages
457463
needs: [prepare-release, build-android, create-release]
458464
runs-on: ubuntu-latest
465+
if: ${{ github.event.inputs.dry_run != 'true' }}
459466
permissions:
460467
contents: read
461468
packages: write
@@ -631,3 +638,30 @@ jobs:
631638
run: |
632639
gradle wrapper --gradle-version 8.5
633640
./gradlew publish --no-daemon
641+
642+
# Publish Rust crate to crates.io
643+
publish-rust:
644+
name: Publish to crates.io
645+
needs: [prepare-release, create-release]
646+
runs-on: ubuntu-latest
647+
if: ${{ github.event.inputs.dry_run != 'true' }}
648+
permissions:
649+
contents: read
650+
id-token: write
651+
steps:
652+
- name: Checkout sources
653+
uses: actions/checkout@v4
654+
with:
655+
ref: main
656+
657+
- name: Install Rust toolchain
658+
uses: dtolnay/rust-toolchain@stable
659+
660+
- name: Authenticate to crates.io
661+
uses: rust-lang/crates-io-auth-action@v1
662+
id: auth
663+
664+
- name: Publish to crates.io
665+
env:
666+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
667+
run: cargo publish --no-verify

0 commit comments

Comments
 (0)