jose 0.0.2

A JSON Object Signing and Encryption implementation
Documentation
permissions:
  contents: read

on:
  push:
    branches: [main]
  pull_request:
  merge_group:

name: test

jobs:
  required:
    runs-on: ubuntu-latest
    name: ubuntu / ${{ matrix.toolchain }}
    strategy:
      matrix:
        toolchain: [stable, beta]

    env:
      CARGO_TERM_COLOR: always

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: rust cache
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: "jose" # we share cache across jobs
      - name: Install ${{ matrix.toolchain }}
        uses: dtolnay/rust-toolchain@master
        with:
          toolchain: ${{ matrix.toolchain }}
      - name: cargo generate-lockfile
        if: hashFiles('Cargo.lock') == ''
        run: cargo generate-lockfile
      - name: cargo install cargo-hack
        uses: taiki-e/install-action@cargo-hack
      - name: cargo install cargo-nextest
        uses: taiki-e/install-action@nextest

      # https://twitter.com/jonhoo/status/1571290371124260865
      - name: cargo test --locked
        run: |
          export CRYPTO_FEATURES="$(cat Cargo.toml | grep -o 'crypto-[^ ]* =' | tr -d ' =' | paste -sd ',')"

          # run the tests for all crypto backends
          cargo hack \
            --each-feature \
            --include-features $CRYPTO_FEATURES \
            nextest run --all-targets

      # https://github.com/rust-lang/cargo/issues/6669
      #
      # Nextest doesn't support running doc tests, so use normal cargo for that
      - name: cargo test --doc
        run: |
          export CRYPTO_FEATURES="$(cat Cargo.toml | grep -o 'crypto-[^ ]* =' | tr -d ' =' | paste -sd ',')"

          # run the tests for all crypto backends
          cargo hack \
            --each-feature \
            --include-features $CRYPTO_FEATURES \
            test --locked --doc

  # FIXME: minimal versions is currently really hard to get to pass

  # minimal:
  #   runs-on: ubuntu-latest
  #   name: ubuntu / stable / minimal-versions
  #   steps:
  #     - uses: actions/checkout@v4
  #       with:
  #         submodules: true
  #     - name: Install stable
  #       uses: dtolnay/rust-toolchain@stable
  #     - name: Install nightly for -Zminimal-versions
  #       uses: dtolnay/rust-toolchain@nightly
  #     - name: rustup default stable
  #       run: rustup default stable
  #     - name: cargo update -Zminimal-versions
  #       run: cargo +nightly update -Zminimal-versions
  #     - name: cargo test
  #       run: cargo test --locked --all-features --all-targets

  os-check:
    runs-on: ${{ matrix.os }}
    name: ${{ matrix.os }} / stable
    strategy:
      fail-fast: false
      matrix:
        os: [macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: rust cache
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: "jose" # we share cache across jobs
      - name: Install stable
        uses: dtolnay/rust-toolchain@stable
      - name: cargo generate-lockfile
        if: hashFiles('Cargo.lock') == ''
        run: cargo generate-lockfile
      - name: cargo install cargo-nextest
        uses: taiki-e/install-action@nextest
      # TODO: check other possible backends too
      - name: cargo test
        run: cargo nextest run --features crypto-rustcrypto --all-targets

  coverage:
    runs-on: ubuntu-latest
    name: ubuntu / stable / coverage
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true
      - name: rust cache
        uses: Swatinem/rust-cache@v2
        with:
          shared-key: "jose" # we share cache across jobs
      - name: Install stable
        uses: dtolnay/rust-toolchain@stable
        with:
          components: llvm-tools-preview
      - name: cargo install cargo-llvm-cov
        uses: taiki-e/install-action@cargo-llvm-cov
      - name: cargo generate-lockfile
        if: hashFiles('Cargo.lock') == ''
        run: cargo generate-lockfile
      # TODO: In the future we may want to expand coverage to all crypto backends
      - name: cargo llvm-cov
        run: cargo llvm-cov --locked --features crypto-rustcrypto,std --lcov --output-path lcov.info
      - name: Upload to codecov.io
        uses: codecov/codecov-action@v3
        with:
          fail_ci_if_error: true
        env:
          CODECOV_TOKEN: ${{ secrets. CODECOV_TOKEN }}