pixelsrc 0.2.0

Pixelsrc - GenAI-native pixel art format and compiler
Documentation
name: Release

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:
    inputs:
      version:
        description: 'Version tag (e.g., v0.1.0)'
        required: true
        type: string

env:
  CARGO_TERM_COLOR: always
  VERSION: ${{ inputs.version || github.ref_name }}

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            archive: tar.gz
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-latest
            archive: tar.gz
            cross: true
          # macOS
          - target: x86_64-apple-darwin
            os: macos-latest
            archive: tar.gz
          - target: aarch64-apple-darwin
            os: macos-14
            archive: tar.gz
          # Windows
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            archive: zip
          - target: aarch64-pc-windows-msvc
            os: windows-latest
            archive: zip

    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Install cross
        if: matrix.cross
        run: cargo install cross --git https://github.com/cross-rs/cross

      - name: Build
        shell: bash
        run: |
          if [ "${{ matrix.cross }}" = "true" ]; then
            cross build --release --target ${{ matrix.target }}
          else
            cargo build --release --target ${{ matrix.target }}
          fi

      - name: Package (Unix)
        if: matrix.os != 'windows-latest'
        shell: bash
        run: |
          cd target/${{ matrix.target }}/release
          tar czvf ../../../pxl-${{ env.VERSION }}-${{ matrix.target }}.tar.gz pxl
          cd ../../..

      - name: Package (Windows)
        if: matrix.os == 'windows-latest'
        shell: pwsh
        run: |
          cd target/${{ matrix.target }}/release
          Compress-Archive -Path pxl.exe -DestinationPath ../../../pxl-${{ env.VERSION }}-${{ matrix.target }}.zip
          cd ../../..

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

  build-deb:
    name: Build Debian package
    needs: build
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Download Linux x86_64 binary
        uses: actions/download-artifact@v4
        with:
          name: pxl-x86_64-unknown-linux-gnu
          path: artifacts

      - name: Extract binary
        run: |
          cd artifacts
          tar xzf pxl-*.tar.gz
          chmod +x pxl

      - name: Build .deb package
        env:
          RELEASE_VERSION: ${{ env.VERSION }}
        run: |
          VERSION="${RELEASE_VERSION#v}"
          PKG_NAME="pxl"
          PKG_DIR="${PKG_NAME}_${VERSION}_amd64"

          mkdir -p "${PKG_DIR}/DEBIAN"
          mkdir -p "${PKG_DIR}/usr/bin"

          cp artifacts/pxl "${PKG_DIR}/usr/bin/"

          cat > "${PKG_DIR}/DEBIAN/control" << EOF
          Package: ${PKG_NAME}
          Version: ${VERSION}
          Section: graphics
          Priority: optional
          Architecture: amd64
          Maintainer: Pixelsrc Developers <pixelsrc@example.com>
          Description: GenAI-native pixel art format and compiler
           Pixelsrc (pxl) is a GenAI-native pixel art format that enables
           creating and manipulating pixel art through a declarative syntax.
           It supports palettes, layers, animations, and compositions with
           a focus on AI-assisted workflows.
          EOF

          dpkg-deb --build "${PKG_DIR}"
          # dpkg-deb creates PKG_DIR.deb which already has the correct name

      - name: Upload .deb artifact
        uses: actions/upload-artifact@v4
        with:
          name: pxl-deb
          path: pxl_*.deb

  checksums:
    name: Generate checksums
    needs: [build, build-deb]
    runs-on: ubuntu-latest
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Generate SHA256 checksums
        run: |
          cd artifacts
          find . -type f \( -name "*.tar.gz" -o -name "*.zip" -o -name "*.deb" \) -exec mv {} . \;
          rm -rf pxl-*/ pxl-deb/
          sha256sum * > SHA256SUMS.txt
          cat SHA256SUMS.txt

      - name: Upload checksums
        uses: actions/upload-artifact@v4
        with:
          name: checksums
          path: artifacts/SHA256SUMS.txt

  release:
    name: Create release
    needs: [build, build-deb, checksums]
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Prepare release assets
        run: |
          cd artifacts
          find . -type f \( -name "*.tar.gz" -o -name "*.zip" -o -name "*.deb" -o -name "SHA256SUMS.txt" \) -exec mv {} . \;
          rm -rf pxl-*/ pxl-deb/ checksums/
          ls -la

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ env.VERSION }}
          files: artifacts/*
          generate_release_notes: true
          fail_on_unmatched_files: true