name: Test

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  bud:
    name: Test
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest]
        go: ['1.17', '1.18', '1.19']
        node: ['16']
        include:
          - os: ubuntu-latest
            go: 1.18
            node: 18
          - os: macos-latest
            go: 1.18
            node: 18
          - os: macos-latest
            go: 1.19
            node: 18

    steps:
      - name: Check out bud
        uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        id: go
        with:
          go-version: ${{ matrix.go }}
          cache: true
          cache-dependency-path: go.sum

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: ${{ matrix.node }}
          cache: 'npm'
          cache-dependency-path: |
            livebud/package-lock.json
            package-lock.json

      - name: Install bud node_modules
        run: npm ci

      - name: Install livebud node_modules
        run: npm ci
        working-directory: ./livebud

      - name: Install Go modules
        run: go mod download

      - name: Cached testdir snapshots
        uses: actions/cache@v3
        with:
          path: $TMPDIR/bud/snapshot
          key: ${{ runner.os }}

      - name: Run Go Format on Go 1.19
        if: matrix.go == '1.19'
        run: make go.fmt

      - name: Run CI (Ubuntu Linux)
        if: matrix.os == 'ubuntu-latest'
        run: make ci.ubuntu

      - name: Run CI (macOS)
        if: matrix.os == 'macos-latest'
        run: make ci.macos
