rinex-cli 0.15.0

GNSS data post processing and quality control, powered by GNSS-Qc
name: Release

# Builds the rinex-cli binaries for every supported platform and attaches
# them (with their SHA-256 checksums) to the GitHub release of the pushed tag.
#
# - push a tag (e.g. v0.15.0)  -> build + publish crate + draft GitHub release
# - manual "Run workflow"      -> build only (dry run), binaries available
#                                 as workflow artifacts, nothing is published

on:
  push:
    tags:
      - "v*"
  workflow_dispatch:

permissions:
  contents: read

env:
  # Minimal toolchain required by the application
  RUST_TOOLCHAIN: "1.92.0"
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1

jobs:
  publish-crate:
    name: Publish on crates.io
    if: github.ref_type == 'tag'
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v7

      - name: Install Rust
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ env.RUST_TOOLCHAIN }}

      - name: Publish
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
        run: cargo publish

  build:
    name: Build (${{ matrix.target }})
    runs-on: ${{ matrix.os }}
    # Tier-2 / less common targets must not block the release
    continue-on-error: ${{ matrix.experimental }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux, dynamically linked against glibc
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-24.04
            smoke: true
            experimental: false
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-24.04-arm
            smoke: true
            experimental: false

          # Linux, fully static (musl): runs on any distribution, any glibc
          - target: x86_64-unknown-linux-musl
            os: ubuntu-24.04
            smoke: true
            experimental: false

          # macOS: Apple Silicon natively, Intel cross-compiled
          - target: aarch64-apple-darwin
            os: macos-latest
            smoke: true
            experimental: false
          - target: x86_64-apple-darwin
            os: macos-latest
            smoke: false
            experimental: false

          # Windows
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            smoke: true
            experimental: false
          - target: aarch64-pc-windows-msvc
            os: windows-11-arm
            smoke: true
            experimental: true

    steps:
      - name: Checkout
        uses: actions/checkout@v7
        with:
          # test data (smoke test) lives in the "data" submodule
          submodules: true

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

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

      # ring requires clang on Windows ARM64
      - name: Install LLVM (Windows ARM64)
        if: matrix.target == 'aarch64-pc-windows-msvc'
        shell: pwsh
        run: |
          if (-not (Get-Command clang -ErrorAction SilentlyContinue)) {
            choco install llvm -y --no-progress
          }
          "C:\Program Files\LLVM\bin" | Out-File -FilePath $env:GITHUB_PATH -Append

      - name: Build
        shell: bash
        env:
          CARGO_PROFILE_RELEASE_STRIP: symbols
          CARGO_PROFILE_RELEASE_LTO: thin
          CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 1
        run: |
          cargo build --release --all-features --target ${{ matrix.target }}

      - name: Locate binary
        shell: bash
        run: |
          BIN="target/${{ matrix.target }}/release/rinex-cli"
          if [[ "${{ matrix.target }}" == *windows* ]]; then
            BIN="$BIN.exe"
          fi
          ls -lh "$BIN"
          echo "BIN=$BIN" >> "$GITHUB_ENV"

      - name: Smoke test
        if: matrix.smoke
        shell: bash
        run: |
          "$BIN" --version
          "$BIN" -q -o smoke-test \
            -f data/CRNX/V3/ESBC00DNK_R_20201770000_01D_30S_MO.crx.gz \
            -f data/NAV/V3/ESBC00DNK_R_20201770000_01D_MN.rnx.gz \
            index

      - name: Package
        shell: bash
        run: |
          VERSION="${{ github.ref_type == 'tag' && github.ref_name || format('dev-{0}', github.sha) }}"
          ARCHIVE="rinex-cli-${VERSION}-${{ matrix.target }}"
          mkdir -p "$ARCHIVE"
          cp README.md LICENSE "$BIN" "$ARCHIVE"/

          if [[ "${{ matrix.target }}" == *windows* ]]; then
            ASSET="$ARCHIVE.zip"
            7z a "$ASSET" "$ARCHIVE" > /dev/null
          else
            ASSET="$ARCHIVE.tar.gz"
            tar czf "$ASSET" "$ARCHIVE"
          fi

          if command -v sha256sum > /dev/null; then
            sha256sum "$ASSET" > "$ASSET.sha256"
          else
            shasum -a 256 "$ASSET" > "$ASSET.sha256"
          fi
          cat "$ASSET.sha256"
          echo "ASSET=$ASSET" >> "$GITHUB_ENV"

      - name: Upload artifact
        uses: actions/upload-artifact@v7
        with:
          name: ${{ env.ASSET }}
          path: |
            ${{ env.ASSET }}
            ${{ env.ASSET }}.sha256
          if-no-files-found: error

  release:
    name: GitHub release
    if: github.ref_type == 'tag'
    needs: build
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v8
        with:
          pattern: rinex-cli-*
          path: dist
          merge-multiple: true

      - name: List assets
        run: ls -lh dist

      - name: Create draft release and attach binaries
        uses: softprops/action-gh-release@v3
        with:
          tag_name: ${{ github.ref_name }}
          name: ${{ github.ref_name }}
          draft: true
          files: dist/*
          fail_on_unmatched_files: true