on: 
  pull_request:
    branches:
      - master
  push:
    branches:
      - master

jobs:
  integration-tests:
    strategy:
      matrix:
        go-version: [1.17.x]
        node-version: [16.x]
        platform: [ubuntu-latest]
    runs-on: ${{ matrix.platform }}
    steps:
      - id: go-cache-paths
        run: |
          echo "::set-output name=go-build::$(go env GOCACHE)"
          echo "::set-output name=go-mod::$(go env GOMODCACHE)"
      
      - uses: actions/setup-go@v2
        with:
          go-version: ${{ matrix.go-version }}
      - uses: actions/checkout@v2

      # cache go build cache
      - name: Cache go modules
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-build }}
          key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
          restore-keys: ${{ runner.os }}-go-build

      # cache go mod cache
      - name: Cache go modules
        uses: actions/cache@v2
        with:
          path: ${{ steps.go-cache-paths.outputs.go-mod }}
          key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
          restore-keys: ${{ runner.os }}-go-mod

      - name: Run build
        run: make build

      - name: Run integration tests
        run: ./scripts/run-integration-tests.sh