oneseed 0.5.2

Deterministic cryptographic keys from a single seed
name: CI

on:
  push:
    branches: [main, master]
    tags:
      - 'v*'
  pull_request:
    branches: [main, master]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: write

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    runs-on: ${{ matrix.os }}
    timeout-minutes: 20
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable
        with:
          components: rustfmt, clippy

      - name: Cache cargo
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

      - name: Check formatting
        run: cargo fmt -- --check

      - name: Clippy
        run: cargo clippy -- -D warnings

      - name: Build
        run: cargo build --release

      - name: Test
        run: cargo test
        env:
          ONESEED_TEST_MODE: "1"

      - name: Integration tests
        run: cargo test --test integration -- --test-threads=1
        env:
          ONESEED_TEST_MODE: "1"

  release:
    needs: test
    if: startsWith(github.ref, 'refs/tags/')
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            asset: 1seed-linux-amd64
            extension: ''
            archive: tar.gz
          - os: macos-latest
            target: x86_64-apple-darwin
            asset: 1seed-darwin-amd64
            extension: ''
            archive: tar.gz
          - os: macos-latest
            target: aarch64-apple-darwin
            asset: 1seed-darwin-arm64
            extension: ''
            archive: tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            asset: 1seed-windows-amd64
            extension: .exe
            archive: zip

    steps:
      - uses: actions/checkout@v4

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

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

      - name: Package (Unix)
        if: matrix.archive == 'tar.gz'
        run: |
          cp target/${{ matrix.target }}/release/1seed${{ matrix.extension }} ${{ matrix.asset }}${{ matrix.extension }}
          chmod +x ${{ matrix.asset }}${{ matrix.extension }}
          tar czf ${{ matrix.asset }}.tar.gz ${{ matrix.asset }}${{ matrix.extension }}

      - name: Package (Windows)
        if: matrix.archive == 'zip'
        run: |
          Copy-Item target/${{ matrix.target }}/release/1seed${{ matrix.extension }} ${{ matrix.asset }}${{ matrix.extension }}
          Compress-Archive -Path ${{ matrix.asset }}${{ matrix.extension }} -DestinationPath ${{ matrix.asset }}.zip

      - name: Upload
        uses: softprops/action-gh-release@v1
        with:
          files: ${{ matrix.asset }}.${{ matrix.archive }}