copernicus_viewer 0.1.0

GUI viewer and library for inspecting and comparing EOPF Zarr products from the Copernicus ecosystem
Documentation
name: Release

on:
  push:
    tags:
      - "v*"

env:
  CARGO_TERM_COLOR: always
  BINARY_NAME: copernicus_viewer

permissions:
  contents: write

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - uses: Swatinem/rust-cache@v2

      - name: Install Linux GUI build dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libxkbcommon-dev \
            libgl1-mesa-dev \
            libwayland-dev \
            libxrandr-dev \
            libxinerama-dev \
            libxcursor-dev \
            libxi-dev \
            pkg-config

      - name: Run tests
        run: cargo test --locked

  publish-crates:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: dtolnay/rust-toolchain@master
        with:
          toolchain: stable

      - uses: Swatinem/rust-cache@v2

      - name: Publish to crates.io
        run: cargo publish --locked --token "${{ secrets.CARGO_REGISTRY_TOKEN }}"

  build:
    needs: test
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            archive: tar.gz
          - runner: windows-latest
            target: x86_64-pc-windows-msvc
            archive: zip
          - runner: macos-latest
            target: aarch64-apple-darwin
            archive: tar.gz
          - runner: macos-latest
            target: x86_64-apple-darwin
            archive: tar.gz

    runs-on: ${{ matrix.runner }}
    steps:
      - uses: actions/checkout@v4

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

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

      - name: Install Linux GUI build dependencies
        if: runner.os == 'Linux'
        run: |
          sudo apt-get update
          sudo apt-get install -y \
            libxkbcommon-dev \
            libgl1-mesa-dev \
            libwayland-dev \
            libxrandr-dev \
            libxinerama-dev \
            libxcursor-dev \
            libxi-dev \
            pkg-config

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

      - name: Package archive (Unix)
        if: matrix.archive == 'tar.gz'
        shell: bash
        run: |
          VERSION="${GITHUB_REF_NAME#v}"
          ARCHIVE="${RUNNER_TEMP}/${{ env.BINARY_NAME }}-${VERSION}-${{ matrix.target }}.tar.gz"
          tar czf "${ARCHIVE}" -C "target/${{ matrix.target }}/release" "${{ env.BINARY_NAME }}"

      - name: Package archive (Windows)
        if: matrix.archive == 'zip'
        shell: pwsh
        run: |
          $Version = $env:GITHUB_REF_NAME.Substring(1)
          $Archive = Join-Path $env:RUNNER_TEMP "${{ env.BINARY_NAME }}-${Version}-${{ matrix.target }}.zip"
          Compress-Archive `
            -Path "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" `
            -DestinationPath $Archive

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ matrix.target }}
          path: ${{ runner.temp }}/${{ env.BINARY_NAME }}-*
          if-no-files-found: error

  release:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v4
        with:
          path: dist
          merge-multiple: true

      - name: Write checksums
        shell: bash
        run: |
          cd dist
          sha256sum ${{ env.BINARY_NAME }}-* > SHA256SUMS.txt

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v2
        with:
          generate_release_notes: true
          files: |
            dist/${{ env.BINARY_NAME }}-*
            dist/SHA256SUMS.txt