random-output 0.3.2

Output random lines to stdout and stderr
Documentation
name: Release

on:
  workflow_dispatch:

env:
  CARGO_INCREMENTAL: 0
  CARGO_TERM_COLOR: always
  CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
  CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER: musl-gcc
  BINARY_NAME: random-output

concurrency:
  group: release
  cancel-in-progress: false

jobs:
  prepare:
    name: Prepare release
    runs-on: ubuntu-latest
    permissions:
      contents: read
    timeout-minutes: 15
    steps:
      - name: Require master
        if: github.ref != 'refs/heads/master'
        run: |
          echo 'Run this workflow from the master branch.' >&2
          exit 1

  build:
    name: Build ${{ matrix.target }}
    needs: prepare
    runs-on: ${{ matrix.os }}
    permissions:
      contents: read
    timeout-minutes: 45
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            archive: tar.gz
          - target: x86_64-unknown-linux-musl
            os: ubuntu-latest
            packages: musl-tools
            archive: tar.gz
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-24.04-arm
            archive: tar.gz
          - target: aarch64-unknown-linux-musl
            os: ubuntu-24.04-arm
            packages: musl-tools
            archive: tar.gz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            archive: zip
          - target: x86_64-apple-darwin
            os: macos-15-intel
            archive: tar.gz
          - target: aarch64-apple-darwin
            os: macos-15
            archive: tar.gz

    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
        with:
          persist-credentials: false

      - name: Install Rust target
        run: rustup target add ${{ matrix.target }}

      - name: Install system packages
        if: matrix.packages
        run: |
          sudo apt-get update
          sudo apt-get install --yes ${{ matrix.packages }}

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

      - name: Package tarball
        if: matrix.archive == 'tar.gz'
        shell: bash
        run: |
          archive="${BINARY_NAME}-${{ matrix.target }}.tar.gz"
          tar -C "target/${{ matrix.target }}/release" -czf "$archive" "$BINARY_NAME"

      - name: Package zip
        if: matrix.archive == 'zip'
        shell: pwsh
        run: |
          $archive = "${env:BINARY_NAME}-${{ matrix.target }}.zip"
          Compress-Archive `
            -Path "target/${{ matrix.target }}/release/${env:BINARY_NAME}.exe" `
            -DestinationPath $archive

      - name: Upload build artifact
        uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.target }}
          path: ${{ env.BINARY_NAME }}-${{ matrix.target }}.${{ matrix.archive }}
          if-no-files-found: error
          retention-days: 1

  release:
    name: Publish
    needs: [prepare, build]
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: write
    timeout-minutes: 30
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
        with:
          fetch-depth: 0
          persist-credentials: false

      - name: Download build artifacts
        uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          path: ${{ runner.temp }}/dist
          merge-multiple: true

      - name: Create tag, publish crate, and create draft release
        id: release-plz
        uses: release-plz/action@2eb1d8bcb770b4c48ccfaad919734b38b51958c9 # v0.5
        with:
          command: release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Attach binaries to draft release
        env:
          ARTIFACT_DIR: ${{ runner.temp }}/dist
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          RELEASE_TAG: ${{ fromJSON(steps.release-plz.outputs.releases)[0].tag }}
        run: gh release upload "$RELEASE_TAG" "$ARTIFACT_DIR"/* --clobber

      # Publishing is deliberately last: immutable releases cannot accept
      # assets after this operation succeeds.
      - name: Publish GitHub release
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          RELEASE_TAG: ${{ fromJSON(steps.release-plz.outputs.releases)[0].tag }}
        run: gh release edit "$RELEASE_TAG" --draft=false --latest