shex 2.0.2

An OPAQUE-authenticated, end-to-end encrypted Redis remote shell
name: Native release

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+"

permissions:
  contents: write

jobs:
  build:
    name: Build ${{ matrix.target }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: ubuntu-22.04
            target: x86_64-unknown-linux-gnu
            deb_arch: amd64
          - runner: ubuntu-22.04-arm
            target: aarch64-unknown-linux-gnu
            deb_arch: arm64
          - runner: macos-15-intel
            target: x86_64-apple-darwin
            deb_arch: ""
          - runner: macos-15
            target: aarch64-apple-darwin
            deb_arch: ""
    runs-on: ${{ matrix.runner }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - name: Verify release version
        shell: bash
        run: |
          set -euo pipefail
          version=$(sed -n 's/^version = "\([^"]*\)"/\1/p' Cargo.toml | head -1)
          test "v$version" = "$GITHUB_REF_NAME"
      - name: Install Rust
        shell: bash
        run: |
          rustup set profile minimal
          rustup toolchain install stable --no-self-update
          rustup default stable
      - name: Build
        run: cargo build --locked --release --target ${{ matrix.target }}
      - name: Package archive
        shell: bash
        run: |
          set -euo pipefail
          version=${GITHUB_REF_NAME#v}
          package="shex-$version-${{ matrix.target }}"
          mkdir -p "dist/$package"
          cp "target/${{ matrix.target }}/release/shex" "dist/$package/shex"
          cp README.md "dist/$package/README.md"
          tar -C dist -czf "dist/$package.tar.gz" "$package"
          rm -rf "dist/$package"
      - name: Package Debian archive
        if: matrix.deb_arch != ''
        shell: bash
        run: |
          chmod +x packaging/build-deb.sh
          packaging/build-deb.sh \
            "target/${{ matrix.target }}/release/shex" \
            "${GITHUB_REF_NAME#v}" \
            "${{ matrix.deb_arch }}" \
            dist
      - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
        with:
          name: ${{ matrix.target }}
          path: dist/*
          if-no-files-found: error

  release:
    name: Publish GitHub release
    needs: build
    runs-on: ubuntu-22.04
    env:
      GH_TOKEN: ${{ github.token }}
    steps:
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          path: dist
          merge-multiple: true
      - name: Create checksums
        run: cd dist && sha256sum ./* >SHA256SUMS
      - name: Publish release
        run: >-
          gh release create "$GITHUB_REF_NAME"
          dist/*
          --repo "$GITHUB_REPOSITORY"
          --title "shex $GITHUB_REF_NAME"
          --generate-notes
          --verify-tag

  apt:
    name: Publish signed APT repository
    needs: build
    runs-on: ubuntu-22.04
    env:
      GH_TOKEN: ${{ github.token }}
      APT_GPG_PRIVATE_KEY: ${{ secrets.APT_GPG_PRIVATE_KEY }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
      - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
        with:
          path: dist
          merge-multiple: true
      - name: Install repository tools
        run: |
          sudo apt-get update
          sudo apt-get install --yes apt-utils gnupg
      - name: Import signing key
        shell: bash
        run: |
          set -euo pipefail
          test -n "$APT_GPG_PRIVATE_KEY"
          printf '%s' "$APT_GPG_PRIVATE_KEY" | gpg --batch --import
      - name: Check out pages branch
        shell: bash
        run: |
          set -euo pipefail
          remote="https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
          if git ls-remote --exit-code --heads "$remote" gh-pages; then
            git clone --depth 1 --branch gh-pages "$remote" pages
          else
            git init pages
            git -C pages checkout --orphan gh-pages
            git -C pages remote add origin "$remote"
          fi
      - name: Build signed repository
        run: |
          chmod +x packaging/publish-apt.sh
          packaging/publish-apt.sh dist pages
      - name: Publish pages branch
        shell: bash
        run: |
          set -euo pipefail
          git -C pages config user.name github-actions[bot]
          git -C pages config user.email 41898282+github-actions[bot]@users.noreply.github.com
          git -C pages add --all
          if git -C pages diff --cached --quiet; then
            exit 0
          fi
          git -C pages commit -m "Publish APT packages for $GITHUB_REF_NAME"
          git -C pages push origin gh-pages