name: "CI"

on:
  push:
    branches: [master]
  pull_request:

# For auto-approving/merging PRs.
permissions:
  pull-requests: write
  contents: write

jobs:
  check:
    name: "Checks and Tests"
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        node-version: [14.x, 16.x, 18.x]

    steps:
      - name: "Run Yarn Basic Checks"
        uses: SkynetLabs/.github/.github/actions/yarn-basic-checks@master
        with:
          node-version: ${{ matrix.node-version }}
          build: false
        env:
          # Use the pro server if an API key is found, otherwise use siasky.net.
          # This is for PRs run from forks, which do not have access to secrets.
          #
          # Ternary syntax. See https://github.com/actions/runner/issues/409#issuecomment-752775072.
          SKYNET_JS_INTEGRATION_TEST_SERVER: ${{ secrets.SKYNET_API_KEY && 'https://skynetpro.net' || 'https://siasky.net' }}
          SKYNET_JS_INTEGRATION_TEST_SKYNET_API_KEY: ${{ secrets.SKYNET_API_KEY }}

  # Auto-merge Dependabot PRs. Requires also `.github/.kodiak.toml`.
  # See https://hackmd.io/@SkynetLabs/ryFfInNXc.
  dependabot:
    name: "Approve and Merge Dependabot PRs"
    # - Must be a PR.
    # - The latest actor must be Dependabot. This prevents other users from
    #   sneaking in changes into the PR.
    if: ${{ github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' }}
    runs-on: ubuntu-latest

    steps:
      - name: "Run Auto-Approval and Auto-Merge"
        uses: SkynetLabs/.github/.github/actions/dependabot-approve-and-merge@master
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
