name: Draft release
on:
  push:
    branches:
      - master

jobs:
  compilation-check:
    name: Build and test binaries
    strategy:
      matrix:
        rust_toolchain: [stable]
        os: [ubuntu-latest, macOS-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout source
        uses: actions/checkout@v2

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

      - name: Check compilation with default features
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --all --bins --examples --tests

      - name: Check compilation with no features
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --all --bins --examples --tests --no-default-features

      - name: cargo +${{ matrix.rust_toolchain }} test ${{ matrix.os }}
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all

      - name: cargo publish --dry-run
        uses: actions-rs/cargo@v1
        with:
          command: publish
          args: --dry-run

  wasm-compilation-check:
    strategy:
      matrix:
        rust_toolchain: [stable]
    name: Compilation check for wasm target
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v2

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.rust_toolchain }}
          target: wasm32-unknown-unknown
          override: true

      - name: Check compilation for wasm target
        uses: actions-rs/cargo@v1
        with:
          command: check
          args: --lib --target wasm32-unknown-unknown

  draft-release:
    name: Draft Release
    needs: [compilation-check, wasm-compilation-check]
    runs-on: ubuntu-latest
    steps:
      - name: Checkout source
        uses: actions/checkout@v2

      - name: Draft Release
        id: draft_release
        uses: release-drafter/release-drafter@v5
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
