name: Build & Test

on:
  pull_request:
  workflow_dispatch:
  workflow_call:
  schedule:
    - cron: "0 5 * * 4" # 5 o'clock utc on thursdays

jobs:
  build-test-native:
    name: build and test native
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
        feature:
          - ring
          - openssl
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust }}
          override: true
      - run: rustup component add clippy

      - name: check
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --no-default-features --features ${{ matrix.feature }}

      - name: check (benches)
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --benches --no-default-features --features ${{ matrix.feature }}

      - name: check (tests)
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --tests --no-default-features --features ${{ matrix.feature }}

      - name: test
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --no-default-features --features ${{ matrix.feature }}

      - name: clippy
        uses: actions-rs/cargo@v1
        with:
          command: clippy
          args: --all-targets --no-default-features --features ${{ matrix.feature }} -- -Dwarnings

      # test packaging to avoid surprisis at release time
      - name: package
        uses: actions-rs/cargo@v1
        with:
          command: package

  
  build-wasm:
    name: build wasm32
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          target: wasm32-unknown-unknown 
      - name: build
        uses: actions-rs/cargo@v1
        with:
          command: build
          args: --target wasm32-unknown-unknown --features ring