jwt-compact 0.5.0

Minimalistic JWT implementation with focus on type safety and secure cryptographic primitives
Documentation
name: Rust

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  msrv: 1.51.0
  nightly: nightly-2021-04-15

jobs:
  # Checks minimum supported Rust version.
  build-msrv:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Install packages
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-suggests --no-install-recommends libsodium-dev

      - name: Cache cargo build
        uses: actions/cache@v1
        with:
          path: target
          key: ${{ runner.os }}-msrv-cargo-build-target

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ env.msrv }}
          override: true

      - name: Build with ES256K & RSA
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: -p jwt-compact --lib --features exonum-crypto,es256k,with_rsa
      - name: Build with dalek crypto
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: -p jwt-compact --no-default-features --features std,ed25519-dalek --lib
      - name: Build with ed25519-compact
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: -p jwt-compact --no-default-features --features std,ed25519-compact --lib

  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Install packages
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-suggests --no-install-recommends libsodium-dev

      - name: Cache cargo build
        uses: actions/cache@v1
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
          components: rustfmt, clippy

      - name: Format
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check
      - name: Clippy
        uses: actions-rs/clippy-check@v1
        with:
          name: "Clippy: exonum-crypto, es256k, rsa"
          token: ${{ secrets.GITHUB_TOKEN }}
          args: -p jwt-compact --features exonum-crypto,es256k,with_rsa,rsa/pem --all-targets -- -D warnings
      - name: Clippy dalek crypto
        uses: actions-rs/clippy-check@v1
        with:
          name: "Clippy: ed25519-dalek"
          token: ${{ secrets.GITHUB_TOKEN }}
          args: -p jwt-compact --no-default-features --features std,ed25519-dalek --all-targets -- -D warnings
      - name: Clippy ed25519-compact
        uses: actions-rs/clippy-check@v1
        with:
          name: "Clippy: ed25519-compact"
          token: ${{ secrets.GITHUB_TOKEN }}
          args: -p jwt-compact --no-default-features --features std,ed25519-compact --all-targets -- -D warnings
      - name: Clippy k256
        uses: actions-rs/clippy-check@v1
        with:
          name: "Clippy: k256"
          token: ${{ secrets.GITHUB_TOKEN }}
          args: -p jwt-compact --no-default-features --features k256 --all-targets -- -D warnings
      - name: Clippy WASM crate
        uses: actions-rs/clippy-check@v1
        with:
          name: "Clippy: WASM"
          token: ${{ secrets.GITHUB_TOKEN }}
          args: -p jwt-compact-wasm --all-targets -- -D warnings

      - name: Run tests
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: -p jwt-compact --features exonum-crypto,es256k,with_rsa,rsa/pem
      - name: Test dalek crypto
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: -p jwt-compact --no-default-features --features std,ed25519-dalek --lib --tests
      - name: Test ed25519-compact
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: -p jwt-compact --no-default-features --features std,ed25519-compact --lib --tests
      - name: Test k256
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: -p jwt-compact --no-default-features --features std,k256 --lib --tests

  build-wasm:
    needs:
      - build

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true
      - name: Install Node.js
        uses: actions/setup-node@v1
        with:
          node-version: '16'
      - name: Install wasm-pack
        uses: jetli/wasm-pack-action@v0.3.0
        with:
          version: 'latest'

      - name: Cache cargo build
        uses: actions/cache@v1
        with:
          path: target
          key: ${{ runner.os }}-wasm-cargo-build-target

      - name: Compile WASM
        # The profile config must be placed in the root workspace manifest,
        # where we don't want to commit it.
        run: |
          echo $'[profile.release]\nlto = true\nopt-level = "s"' >> Cargo.toml;
          (cd e2e-tests/wasm; npm run build && npm ci)
      - name: Run WASM
        run: (cd e2e-tests/wasm; npm test)

  build-nostd:
    needs:
      - build

    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: e2e-tests/no-std

    steps:
      - uses: actions/checkout@v2

      - name: Install qemu
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-suggests --no-install-recommends qemu-system-arm

      - name: Cache cargo build
        uses: actions/cache@v1
        with:
          path: e2e-tests/no-std/target
          key: ${{ runner.os }}-nostd-cargo-build-target

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ env.nightly }}
          override: true
          components: rustfmt, clippy
          target: thumbv7m-none-eabi

      # Since it's impossible to include the `nostd` crate into the common workspace,
      # we need to perform fmt / clippy checks for it separately.
      - name: Format
        run: cargo fmt -- --check
      - name: Clippy
        run: cargo clippy --bin jwt-compact-nostd --all-features -- -D warnings

      - name: Run binary (ed25519)!
        run: cargo run --release --features ed25519
      - name: Run binary (rsa)!
        run: cargo run --release --features with_rsa

  document:
    needs:
      - build
      - build-msrv
      - build-wasm
      - build-nostd
    if: github.event_name == 'push'
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          persist-credentials: false

      - name: Install packages
        run: |
          sudo apt-get update
          sudo apt-get install -y --no-install-suggests --no-install-recommends libsodium-dev

      - name: Cache cargo build
        uses: actions/cache@v1
        with:
          path: target
          key: ${{ runner.os }}-cargo-build-target

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ env.nightly }}
          profile: minimal
          override: true

      - name: Build docs
        run: |
          cargo clean --doc && \
          cargo rustdoc -p jwt-compact --features exonum-crypto,es256k,with_rsa -- \
            --cfg docsrs -Z unstable-options \
            --extern-html-root-url base64=https://docs.rs/base64/~0.13 \
            --extern-html-root-url exonum-crypto=https://docs.rs/exonum-crypto/1.0.0 \
            --extern-html-root-url anyhow=https://docs.rs/anyhow/~1.0 \
            --extern-html-root-url secp256k1=https://docs.rs/secp256k1/~0.20 \
            --extern-html-root-url serde_json=https://docs.rs/serde_json/~1 \
            --extern-html-root-url serde_cbor=https://docs.rs/serde_cbor/~0.11 \
            --extern-html-root-url rsa=https://docs.rs/rsa/~0.5

      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@releases/v3
        with:
          ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
          BRANCH: gh-pages
          FOLDER: target/doc
          SINGLE_COMMIT: true