cargo-sync-rdme 0.5.1

Cargo subcommand to synchronize README with crate documentation
name: CD

on:
  push:
    tags:
      - "v?[0-9]+.[0-9]+.[0-9]+"
    branches:
      - main
  pull_request:
  workflow_dispatch:

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: ${{ github.ref_name != github.event.repository.default_branch }}

env:
  CARGO_TERM_COLOR: always

permissions: {}

jobs:
  build-release-assets:
    name: Build artifacts for ${{ matrix.job.target }}
    runs-on: ${{ matrix.job.os }}
    strategy:
      fail-fast: true
      matrix:
        rust: [stable]
        job:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
          - os: ubuntu-latest
            target: i686-unknown-linux-gnu
          - os: macos-latest
            target: aarch64-apple-darwin
          - os: windows-latest
            target: x86_64-pc-windows-msvc
          - os: windows-11-arm
            target: aarch64-pc-windows-msvc
    steps:
      - uses: actions/checkout@v7
      - uses: dtolnay/rust-toolchain@v1
        with:
          toolchain: ${{ matrix.rust }}
      - uses: taiki-e/install-action@v2
        with:
          tool: cross
      - uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.job.target }}

      - name: Install modern bash on macOS
        if: startsWith(matrix.job.os, 'macos')
        run: |
          brew install bash
          echo "/opt/homebrew/bin" >> "$GITHUB_PATH"
        shell: bash

      - name: Build artifact
        run: ./scripts/build-dist --target "${{ matrix.job.target }}"
        shell: bash

      - name: Upload binaries as artifacts
        uses: actions/upload-artifact@v7
        with:
          name: artifact-${{ matrix.job.target }}
          path: target/dist/*

  release:
    name: Create GitHub release
    runs-on: ubuntu-latest
    needs:
      - build-release-assets
    permissions:
      contents: write
    if: ${{ startsWith(github.ref, 'refs/tags/') }}
    steps:
      - name: Download built artifacts
        uses: actions/download-artifact@v8
        with:
          pattern: artifact-*
          path: target/dist
          merge-multiple: true

      - name: Releasing assets
        uses: softprops/action-gh-release@v3
        with:
          files: target/dist/*
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  cd-complete:
    needs:
      - build-release-assets
      - release
    runs-on: ubuntu-latest
    if: ${{ always() }}
    steps:
      - name: CD complete
        run: |
          if ${{ !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}; then
            echo "CD succeeded"
          else
            echo "CD failed"
            exit 1
          fi
        shell: bash