jj-fork 0.2.2

Maintain a fork as jj series and glues on top of upstream, and keep them current
name: Release

on:
  push:
    tags: ["v*"]

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        include:
          - { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
          - { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04-arm }
          - { target: x86_64-apple-darwin, os: macos-15-intel }
          - { target: aarch64-apple-darwin, os: macos-latest }
          - { target: x86_64-pc-windows-msvc, os: windows-latest }
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v7
      - name: Install Rust
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable
          rustup target add ${{ matrix.target }}
      - run: cargo build --locked --release --target ${{ matrix.target }}
      - name: Package (unix)
        if: runner.os != 'Windows'
        run: |
          name=jj-fork-${{ github.ref_name }}-${{ matrix.target }}
          mkdir "$name"
          cp target/${{ matrix.target }}/release/jj-fork LICENSE README.md "$name/"
          tar czf "$name.tar.gz" "$name"
          shasum -a 256 "$name.tar.gz" >"$name.tar.gz.sha256"
      - name: Package (windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          $name = "jj-fork-${{ github.ref_name }}-${{ matrix.target }}"
          New-Item -ItemType Directory $name
          Copy-Item "target/${{ matrix.target }}/release/jj-fork.exe", LICENSE, README.md $name
          Compress-Archive $name "$name.zip"
          $hash = (Get-FileHash "$name.zip" -Algorithm SHA256).Hash.ToLower()
          "$hash  $name.zip" | Out-File "$name.zip.sha256" -Encoding ascii
      - uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.target }}
          path: |
            jj-fork-*.tar.gz*
            jj-fork-*.zip*

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          path: dist
          merge-multiple: true
      - name: Create GitHub release
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          gh release create "${{ github.ref_name }}" dist/* \
            --repo "${{ github.repository }}" --generate-notes --verify-tag

  publish:
    needs: release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Install Rust
        run: |
          rustup toolchain install stable --profile minimal --no-self-update
          rustup default stable
      - name: Check tag matches Cargo.toml version
        run: |
          v=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].version')
          [ "v$v" = "${{ github.ref_name }}" ] || { echo "Tag ${{ github.ref_name }} != Cargo.toml version $v"; exit 1; }
      - run: cargo publish --locked
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}