name: Build and upload binaries to release

on:
  push:
    tags:
      - "v*"

permissions: {}

jobs:
  github:
    name: Publish Release on GitHub
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
        with:
          persist-credentials: false

      - name: Create GitHub release
        env:
          GH_TOKEN: ${{ github.token }}
          TAG: ${{ github.ref_name }}
        run: |
          gh release view "$TAG" > /dev/null 2>&1 || \
            gh release create "$TAG" --verify-tag --title "$TAG" --notes ""

  cratesio:
    name: Publish Release to Crates.io
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
        with:
          persist-credentials: false

      - name: Set up Rust
        run: |
          rustup toolchain install 1.85.0 --profile minimal
          rustup default 1.85.0

      - name: Publish to Crates.io - Library
        run: cargo publish -p bitcoind-async-client # zizmor: ignore[use-trusted-publishing]
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} # zizmor: ignore[secrets-outside-env]
