git-ledger: v0.1.0-alpha.2 #8
Workflow file for this run
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
| name: CD | |
| on: | |
| release: | |
| types: [released, prereleased] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| check-tag: | |
| name: Check release tag | |
| if: github.event_name == 'workflow_dispatch' || github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should-publish: ${{ github.event_name == 'workflow_dispatch' || steps.check.outputs.match == 'true' }} | |
| crate-name: ${{ steps.check.outputs.crate-name }} | |
| steps: | |
| - name: Match semver tag | |
| id: check | |
| if: github.event_name == 'release' | |
| run: | | |
| TAG="${{ github.event.release.tag_name }}" | |
| if [[ "$TAG" =~ ^(git-metadata|git-ledger|git-chain)-v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then | |
| echo "match=true" >> "$GITHUB_OUTPUT" | |
| echo "crate-name=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "match=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| release: | |
| name: Release | |
| needs: check-tag | |
| if: needs.check-tag.outputs.should-publish == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| # Used to sign the release artifacts | |
| id-token: write | |
| # Used to upload release artifacts | |
| contents: write | |
| # Used to generate artifact attestation | |
| attestations: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions-rust-lang/setup-rust-toolchain@v1 | |
| with: | |
| cache: true | |
| toolchain: stable | |
| - name: Package crate | |
| run: | | |
| CRATE="${{ needs.check-tag.outputs.crate-name }}" | |
| if [ -n "$CRATE" ]; then | |
| cargo package -p "$CRATE" | |
| else | |
| cargo package --workspace | |
| fi | |
| - name: Generate artifact attestation | |
| uses: actions/attest-build-provenance@v2 | |
| with: | |
| subject-path: "target/package/*.crate" | |
| - name: Publish to crates.io | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| run: | | |
| CRATE="${{ needs.check-tag.outputs.crate-name }}" | |
| if [ -n "$CRATE" ]; then | |
| PKG_FLAG="-p $CRATE" | |
| else | |
| PKG_FLAG="--workspace" | |
| fi | |
| cargo publish $PKG_FLAG --token "$CARGO_REGISTRY_TOKEN" |