# Adapted from: https://github.com/crate-ci/cargo-release/blob/v0.25.15/.github/workflows/post-release.yml
name: "tagged-release"

on:
  push:
    tags:
      - "v*"

jobs:
  create-release:
    name: create-release
    runs-on: ubuntu-latest
    outputs:
      upload_url: ${{ steps.release.outputs.upload_url }}
      release_version: ${{ steps.release.outputs.automatic_releases_tag }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
      - name: Create GitHub release
        id: release
        uses: marvinpinto/action-automatic-releases@latest
        with:
          repo_token: "${{ secrets.GITHUB_TOKEN }}"
          prerelease: false
  publish-release:
    # Publish the release to crates.io
    # See [Trusted Publishing](https://crates.io/docs/trusted-publishing)
    name: publish-release
    runs-on: ubuntu-latest
    permissions:
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1
      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: stable
      - name: Auth crates.io
        uses: rust-lang/crates-io-auth-action@v1
        id: auth
      - name: Publish to crates.io
        # Don't know why, but cargo complains that Cargo.lock has been changed.
        run: cargo publish --allow-dirty
        env:
          CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
