hprof-analyzer 0.1.0

Fast, low-memory Java HPROF heap-dump analyzer with Eclipse MAT-parity reports (System Overview, Leak Suspects, Top Consumers).
name: Release

on:
  # Tagged releases: build + attach archives to a GitHub Release for the tag.
  push:
    tags: ["v*"]
  # Nightly: only publishes on days where a commit landed in the last 24h.
  schedule:
    - cron: "17 4 * * *"
  # Manual trigger (always builds; publishes to the rolling `nightly` release).
  workflow_dispatch:

permissions:
  contents: write

jobs:
  # For scheduled runs, skip the whole thing unless something was committed in
  # the last 24 hours. Tag pushes and manual dispatches always proceed.
  gate:
    runs-on: ubuntu-latest
    outputs:
      proceed: ${{ steps.check.outputs.proceed }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Decide whether to build
        id: check
        run: |
          if [ "${{ github.event_name }}" != "schedule" ]; then
            echo "proceed=true" >> "$GITHUB_OUTPUT"
            exit 0
          fi
          count="$(git rev-list --after='24 hours ago' --count HEAD)"
          echo "commits in last 24h: $count"
          if [ "$count" -gt 0 ]; then
            echo "proceed=true" >> "$GITHUB_OUTPUT"
          else
            echo "proceed=false" >> "$GITHUB_OUTPUT"
          fi

  build:
    needs: gate
    if: needs.gate.outputs.proceed == 'true'
    name: build (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            archive: tar.gz
          - os: ubuntu-latest
            target: x86_64-unknown-linux-musl
            archive: tar.gz
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-gnu
            archive: tar.gz
          - os: ubuntu-24.04-arm
            target: aarch64-unknown-linux-musl
            archive: tar.gz
          - os: macos-latest
            target: aarch64-apple-darwin
            archive: tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            archive: zip
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      # build.rs bundles web/ (esbuild) into the git-ignored web/dist/bundle.js
      # that src/html.rs embeds, so node/npm are required to compile the crate.
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: npm
          cache-dependency-path: web/package-lock.json

      - name: Install musl tools
        if: endsWith(matrix.target, '-linux-musl')
        run: sudo apt-get update && sudo apt-get install -y musl-tools

      - name: Cache cargo
        uses: Swatinem/rust-cache@v2
        with:
          key: ${{ matrix.target }}

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

      - name: Package (unix)
        if: matrix.archive == 'tar.gz'
        shell: bash
        run: |
          staging="hprof-analyzer-${{ matrix.target }}"
          mkdir "$staging"
          cp "target/${{ matrix.target }}/release/hprof-analyzer" "$staging/"
          cp LICENSE README.md "$staging/"
          tar czf "$staging.tar.gz" "$staging"
          echo "ASSET=$staging.tar.gz" >> "$GITHUB_ENV"

      - name: Package (windows)
        if: matrix.archive == 'zip'
        shell: bash
        run: |
          staging="hprof-analyzer-${{ matrix.target }}"
          mkdir "$staging"
          cp "target/${{ matrix.target }}/release/hprof-analyzer.exe" "$staging/"
          cp LICENSE README.md "$staging/"
          7z a "$staging.zip" "$staging"
          echo "ASSET=$staging.zip" >> "$GITHUB_ENV"

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

  # Tagged release: publish archives to the Release for the pushed tag.
  release-tag:
    needs: build
    if: startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: Publish release
        uses: softprops/action-gh-release@v2
        with:
          files: artifacts/*
          generate_release_notes: true

  # Nightly / manual: refresh a single rolling `nightly` pre-release.
  release-nightly:
    needs: build
    if: github.event_name != 'push'
    runs-on: ubuntu-latest
    steps:
      - name: Download artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
          merge-multiple: true

      - name: Publish rolling nightly
        uses: softprops/action-gh-release@v2
        with:
          tag_name: nightly
          name: Nightly
          prerelease: true
          files: artifacts/*
          body: "Rolling nightly build from the latest commit on main."