mdbook-toc 0.15.4

mdbook preprocessor to add Table of Contents
Documentation
# Based on https://github.com/starship/starship/blob/master/.github/workflows/deploy.yml

name: Deploy
on:
  push:
    tags:
      - "*"

env:
  CRATE_NAME: mdbook-toc

jobs:
  # Build sources for every OS
  github_build:
    name: Build release binaries
    strategy:
      fail-fast: false
      matrix:
        target:
          - x86_64-unknown-linux-gnu
          - aarch64-unknown-linux-musl
          - x86_64-unknown-linux-musl
          - x86_64-apple-darwin
          - aarch64-apple-darwin
          - x86_64-pc-windows-msvc
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-22.04
            name: x86_64-unknown-linux-gnu.tar.gz
          - target: aarch64-unknown-linux-musl
            os: ubuntu-latest
            name: aarch64-unknown-linux-musl.tar.gz
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            name: x86_64-unknown-linux-musl.tar.gz
          - target: x86_64-apple-darwin
            os: macOS-latest
            name: x86_64-apple-darwin.tar.gz
          - target: aarch64-apple-darwin
            os: macOS-latest
            name: aarch64-apple-darwin.tar.gz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            name: x86_64-pc-windows-msvc.zip
    runs-on: ${{ matrix.os }}
    steps:
      - name: Setup | Checkout
        uses: actions/checkout@v4

      # Cache files between builds
      - uses: Swatinem/rust-cache@v2

      - name: Setup | Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Apt Setup on act
        if: ${{ env.ACT }}
        run: sudo apt update

      - name: Setup | musl tools
        if: matrix.target == 'x86_64-unknown-linux-musl'
        run: sudo apt install -y musl-tools

      - name: Setup | musl cross-compile
        if: matrix.target == 'aarch64-unknown-linux-musl'
        run: |
          pushd /tmp
          wget https://github.com/musl-cross/musl-cross/releases/download/20241103/aarch64-unknown-linux-musl.tar.xz
          tar -xf aarch64-unknown-linux-musl.tar.xz
          echo "d3c597e89f4b87f78d473f1f6a539ed817afbce9b73a02dd123c6d5c4e43f617 *aarch64-unknown-linux-musl.tar.xz" | sha256sum -c -
          ccpath=$(realpath $(find . -name aarch64-unknown-linux-musl-cc))
          popd
          mkdir -p .cargo
          echo "[target.aarch64-unknown-linux-musl]" > .cargo/config.toml
          printf 'linker = "%s"\n' "$ccpath" >> .cargo/config.toml

      - name: Build | Build
        run: cargo build --release --target ${{ matrix.target }}

      - name: Post Setup | Extract tag name
        shell: bash
        run: |
          if [ -z "$ACT" ]; then
            tag="${GITHUB_REF#refs/tags/}"
          else
            tag="v1.0.0"
          fi

          echo "tag=$tag" >> $GITHUB_OUTPUT
        id: extract_tag

      - name: Post Setup | Prepare artifacts [Windows]
        if: matrix.os == 'windows-latest'
        run: |
          mkdir -p target/stage
          cd target/${{ matrix.target }}/release
          strip ${{ env.CRATE_NAME }}.exe
          7z a ../../stage/${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }} ${{ env.CRATE_NAME }}.exe
          cd -

      - name: Post Setup | Prepare artifacts [-nix]
        if: matrix.os != 'windows-latest'
        run: |
          mkdir -p target/stage
          cd target/${{ matrix.target }}/release
          if [ "${{ matrix.target }}" != "aarch64-unknown-linux-musl" ]; then
            strip ${{ env.CRATE_NAME }}
          fi
          tar czvf ../../stage/${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }} ${{ env.CRATE_NAME }}
          cd -

      - name: Post Setup | Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.CRATE_NAME }}-${{ steps.extract_tag.outputs.tag }}-${{ matrix.name }}
          path: target/stage/*

  # Create GitHub release with Rust build targets and release notes
  github_release:
    name: Create GitHub Release
    needs: github_build
    runs-on: ubuntu-latest
    steps:
      - name: Setup | Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Setup | Artifacts
        uses: actions/download-artifact@v4

      - name: Setup | Release notes
        run: |
          git log -1 --pretty='%s' > RELEASE.md

      - name: Build | Publish
        uses: softprops/action-gh-release@v2
        with:
          files: ${{ env.CRATE_NAME }}-*/${{ env.CRATE_NAME }}-*
          body_path: RELEASE.md
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}