plotpx 0.1.7

Pixel-focused plotting engine that renders magnitude grids, heatmaps, and spectra to RGBA buffers
Documentation
name: Release Artifacts

on:
  workflow_dispatch:
    inputs:
      release_tag:
        description: 'Git tag to publish (e.g. v0.1.0)'
        required: true
  push:
    tags:
      - 'v*'

permissions:
  contents: write
  pull-requests: write

jobs:
  build:
    name: Build ${{ matrix.label }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - label: linux-x86_64
            os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            platform: x86_64-unknown-linux-gnu
            lib_name: libplotpx.so
            archive: plotpx-linux-x86_64.tar.gz
          - label: macos-aarch64
            os: macos-14
            target: aarch64-apple-darwin
            platform: aarch64-apple-darwin
            lib_name: libplotpx.dylib
            archive: plotpx-macos-aarch64.tar.gz
          - label: windows-x86_64
            os: windows-latest
            target: x86_64-pc-windows-msvc
            platform: x86_64-pc-windows-msvc
            lib_name: plotpx.dll
            archive: plotpx-windows-x86_64.tar.gz

    steps:
      - uses: actions/checkout@v4

      - name: Sync Julia project version
        run: python scripts/sync_versions.py

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

      - name: Build release library
        run: cargo build --release --target ${{ matrix.target }}
        env:
          CARGO_INCREMENTAL: 0

      - name: Stage artifact payload
        shell: bash
        run: |
          set -euo pipefail
          mkdir -p dist/${{ matrix.label }}
          cp target/${{ matrix.target }}/release/${{ matrix.lib_name }} dist/${{ matrix.label }}/

      - name: Create archive
        shell: bash
        run: |
          set -euo pipefail
          mkdir -p uploads
          tar -C dist/${{ matrix.label }} -czf uploads/${{ matrix.archive }} .

      - name: Compute checksum
        id: checksum
        shell: bash
        run: |
          set -euo pipefail
          file=uploads/${{ matrix.archive }}
          python -c "import hashlib, pathlib; path = pathlib.Path(r'${file}'); print(hashlib.sha256(path.read_bytes()).hexdigest())" > "${file}.sha256"
          cat "${file}.sha256"
          echo "sha256=$(cat "${file}.sha256")" >> "$GITHUB_OUTPUT"

      - name: Write metadata
        shell: bash
        run: |
          set -euo pipefail
          cat <<'TOML' > uploads/${{ matrix.label }}.toml
          name = "plotpx"
          platform = "${{ matrix.platform }}"
          archive = "${{ matrix.archive }}"
          sha256 = "${{ steps.checksum.outputs.sha256 }}"
          target = "${{ matrix.target }}"
          lib_name = "${{ matrix.lib_name }}"
          TOML

      - name: Upload build outputs
        uses: actions/upload-artifact@v4
        with:
          name: plotpx-${{ matrix.label }}
          path: |
            uploads/${{ matrix.archive }}
            uploads/${{ matrix.archive }}.sha256
            uploads/${{ matrix.label }}.toml

  publish:
    name: Publish release assets
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/download-artifact@v4
        with:
          path: dist

      - name: Determine release tag
        id: release
        run: |
          if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
            tag="${{ inputs.release_tag }}"
            if [ -z "$tag" ]; then
              echo "::error::release_tag input must be provided" >&2
              exit 1
            fi
          else
            tag="${GITHUB_REF_NAME}"
          fi
          echo "tag=$tag" >> "$GITHUB_OUTPUT"

      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'

      - name: Update Artifacts.toml
        run: |
          python scripts/update_artifacts_from_metadata.py \
            --metadata-dir dist \
            --release-tag ${{ steps.release.outputs.tag }} \
            --repo ${{ github.repository }} \
            --artifacts-toml julia/PlotPx/Artifacts.toml

      - name: Sync Julia project version
        run: python scripts/sync_versions.py

      - name: Create artifact update PR
        uses: peter-evans/create-pull-request@v6
        with:
          commit-message: Update PlotPx artifacts for ${{ steps.release.outputs.tag }}
          branch: chore/update-plotpx-artifacts-${{ steps.release.outputs.tag }}
          title: Update PlotPx artifacts for ${{ steps.release.outputs.tag }}
          body: |
            Automated refresh of PlotPx shared-library artifacts for `${{ steps.release.outputs.tag }}`.

            Generated by the Release Artifacts workflow.
          base: ${{ github.event.repository.default_branch || 'main' }}
          add-paths: |
            julia/PlotPx/Artifacts.toml

      - name: Publish GitHub release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ steps.release.outputs.tag }}
          target_commitish: ${{ github.sha }}
          files: |
            dist/**/plotpx-*.tar.gz
            dist/**/*.sha256
          generate_release_notes: true
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}