deno_plugin_num_cpus 0.1.2

Get the number of CPUs available on the current system for Deno.
name: ci

on: [push, pull_request]

jobs:
  build:
    name: ${{ matrix.kind }} ${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macOS-latest, ubuntu-latest, windows-latest]

      # Always run master branch builds to completion. This allows the cache to
      # stay mostly up-to-date in situations where a single job fails due to
      # e.g. a flaky test.
      # Don't fast-fail on tag build because publishing binaries shouldn't be
      # prevented if 'cargo publish' fails (which can be a false negative).
      fail-fast:
        ${{ github.event_name == 'pull_request' || (github.ref !=
        'refs/heads/master' && !startsWith(github.ref, 'refs/tags/')) }}

    env:
      CARGO_INCREMENTAL: 0
      RUST_BACKTRACE: full

    steps:
      - name: Clone repository
        uses: actions/checkout@v2

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

      - name: Install rust
        uses: hecrj/setup-rust-action@v1

      - name: Install clippy and rustfmt
        run: |
          rustup component add clippy
          rustup component add rustfmt

      - name: Log versions
        run: |
          rustc --version
          cargo --version

      - name: Configure cargo data directory
        # After this point, all cargo registry and crate data is stored in
        # $GITHUB_WORKSPACE/.cargo_home. This allows us to cache only the files
        # that are needed during the build process. Additionally, this works
        # around a bug in the 'cache' action that causes directories outside of
        # the workspace dir to be saved/restored incorrectly.
        run: echo "::set-env name=CARGO_HOME::$(pwd)/.cargo_home"

      - name: Cache
        uses: actions/cache@v2
        with:
          # Note: crates from the denoland/deno git repo always get rebuilt,
          # and their outputs ('deno', 'libdeno.rlib' etc.) are quite big,
          # so we cache only those subdirectories of target/{debug|release} that
          # contain the build output for crates that come from the registry.
          path: |-
            .cargo_home
            target/*/.*
            target/*/build
            target/*/deps
          key:
            ${{ matrix.config.os }}-${{ hashFiles('Cargo.lock') }}
          restore-keys: |
            ${{ matrix.config.os }}-

      - name: Run cargo fmt
        run: cargo fmt --all -- --check

      - name: Run cargo check
        run: cargo check --locked

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

      - name: Build release
        run: cargo build --release --locked

      - name: Run cargo test
        run: cargo test --locked

      - name: Release
        uses: softprops/action-gh-release@v1
        if: |
          startsWith(github.repository, 'justjavac') &&
          startsWith(github.ref, 'refs/tags/')
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          files: |
            target/release/libdeno_plugin_num_cpus.dylib
            target/release/libdeno_plugin_num_cpus.so
            target/release/deno_plugin_num_cpus.dll
          draft: true

      - name: Publish
        if: |
          startsWith(matrix.os, 'ubuntu') &&
          startsWith(github.repository, 'justjavac') &&
          startsWith(github.ref, 'refs/tags/')
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: |
          cargo publish