name: Publish to crates.io # Manual recovery workflow. The primary release path is release.yml # (triggered by a v* tag push). Use this only to re-run a crate publish # in isolation when the main pipeline has partially failed. on: workflow_dispatch: inputs: tag: description: "Release tag (e.g. v0.9.6)" required: true type: string concurrency: group: publish-crate cancel-in-progress: false permissions: contents: read id-token: write jobs: publish: name: Publish to crates.io runs-on: ubuntu-latest # Manual dispatch publishes to crates.io exactly as a tagged release does, # so it takes the same approval gate. Without this the recovery path is a # way to publish with no review. environment: production-publish steps: - uses: actions/checkout@v5 with: ref: ${{ inputs.tag }} # Recovery is run by hand against a tag, so the crate version it finds # may already be published, or may be a stable version sitting under a # prerelease tag, which the release itself would have skipped. Either # way there is nothing this run should publish, so it stops with the # reason, before the tests, rather than succeeding having done nothing. # The decision is the script release.yml uses, so the two paths cannot # drift. - name: Decide whether to publish the crate env: INPUT_TAG: ${{ inputs.tag }} run: | TAG="$INPUT_TAG" VERSION="${TAG#v}" # Same shape rule as release.yml, from the same script. if [ "$VERSION" = "$TAG" ] || ! scripts/is-semver.sh "$VERSION"; then echo "::error::Invalid tag format: $TAG (expected vX.Y.Z or vX.Y.Z-pre.N)" exit 1 fi CRATE=$(grep -m1 '^version = ' Cargo.toml | cut -d'"' -f2) DECISION=$(scripts/crate-publish-decision.sh dynoxide-rs "$CRATE" "$VERSION") || { echo "::error::could not decide whether to publish dynoxide-rs $CRATE for $TAG. Refusing to guess." exit 1 } case "$DECISION" in publish) echo "dynoxide-rs $CRATE is not published; continuing" ;; already-published) echo "::error::dynoxide-rs $CRATE is already on crates.io. Nothing to recover." exit 1 ;; stable-crate-on-prerelease) echo "::error::$TAG is a prerelease and dynoxide-rs $CRATE is not. A stable crate is only published from a stable tag; recover it from that release." exit 1 ;; *) echo "::error::unexpected crate publish decision '$DECISION'" exit 1 ;; esac - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Run tests run: cargo test # Trusted Publishing, as release.yml uses. crates.io matches the # exchange on the workflow filename, so this recovery path needs its own # config on crates.io naming publish-crate.yml; the one for release.yml # will not cover it. - name: Authenticate with crates.io id: auth uses: rust-lang/crates-io-auth-action@v1 - name: Dry run run: cargo publish --dry-run env: CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }} - name: Publish run: cargo publish env: CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}