generate-sample-pdf 0.1.1

Distinguishable sample PDF generator
name: Build

on:
  push:
    branches: [ "master" ]
    tags: [ "v*" ]
  pull_request:
    branches: [ "master" ]

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always
  BIN_NAME: generate_pdf
  # Override local config (like mold) to use default linker in CI
  RUSTFLAGS: ""

jobs:
  build:
    name: ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            cmd: cargo
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            cmd: cross
          - target: x86_64-apple-darwin
            os: macos-latest
            cmd: cargo
          - target: aarch64-apple-darwin
            os: macos-latest
            cmd: cargo

    steps:
    - uses: actions/checkout@v4

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

    - name: Install Cross
      if: matrix.cmd == 'cross'
      uses: taiki-e/install-action@cross

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

    - name: Rename Binary
      run: cp target/${{ matrix.target }}/release/${{ env.BIN_NAME }} ${{ env.BIN_NAME }}-${{ matrix.target }}

    - name: Upload Artifact
      uses: actions/upload-artifact@v4
      with:
        name: ${{ env.BIN_NAME }}-${{ matrix.target }}
        path: ${{ env.BIN_NAME }}-${{ matrix.target }}

  release:
    name: Release
    if: startsWith(github.ref, 'refs/tags/')
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          pattern: ${{ env.BIN_NAME }}-*
          merge-multiple: true

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: ${{ env.BIN_NAME }}-*