name: Release
on:
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: "Version tag to publish (e.g. v0.1.0). Must already exist."
required: true
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
permissions:
contents: read
jobs:
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
steps:
- name: Resolve tag
id: tag
run: |
TAG="${{ github.event.release.tag_name || inputs.tag }}"
if [[ -z "$TAG" ]]; then
echo "::error::Could not resolve a tag to publish."
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
- uses: actions/checkout@v5
with:
ref: ${{ steps.tag.outputs.tag }}
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Verify tag matches Cargo.toml version
run: |
CARGO_VERSION=$(cargo metadata --format-version 1 --no-deps \
| jq -r '.packages[] | select(.name == "walletsuite-tx-compiler") | .version')
if [[ "$CARGO_VERSION" != "${{ steps.tag.outputs.version }}" ]]; then
echo "::error::Tag ${{ steps.tag.outputs.tag }} does not match Cargo.toml version ($CARGO_VERSION)."
exit 1
fi
echo "OK: tag ${{ steps.tag.outputs.tag }} matches Cargo.toml version $CARGO_VERSION"
- name: Run tests (locked)
run: cargo test --all-features --locked
- name: Dry-run publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked --dry-run
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --locked