on: push: branches: - master pull_request: branches: - master name: tests env: GO111MODULE: on permissions: contents: read jobs: test: permissions: actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows contents: read # for actions/checkout to fetch code strategy: matrix: go-version: [1.x, 1.17.x] platform: [ubuntu-latest] include: # include windows, but only with the latest Go version, since there # is very little in the library that is platform specific - go-version: 1.x platform: windows-latest # only update test coverage stats with the most recent go version on linux - go-version: 1.x platform: ubuntu-latest update-coverage: true runs-on: ${{ matrix.platform }} steps: - name: Cancel previous uses: styfle/cancel-workflow-action@a40b8845c0683271d9f53dfcb887a7e181d3918b #0.9.1 with: access_token: ${{ github.token }} - uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - uses: actions/checkout@v3 # Get values for cache paths to be used in later steps - id: cache-paths run: | echo "::set-output name=go-cache::$(go env GOCACHE)" echo "::set-output name=go-mod-cache::$(go env GOMODCACHE)" - name: Cache go modules uses: actions/cache@v3 with: path: | ${{ steps.cache-paths.outputs.go-cache }} ${{ steps.cache-paths.outputs.go-mod-cache }} key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} restore-keys: ${{ runner.os }}-go- - name: Ensure go generate produces a zero diff shell: bash run: go generate -x ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) - name: Run go test run: go test -v -race -coverprofile coverage.txt -covermode atomic ./... - name: Ensure integration tests build # don't actually run tests since they hit live GitHub API run: go test -v -tags=integration -run=^$ ./test/integration - name: Run scrape tests run: | cd scrape go test ./... - name: Upload coverage to Codecov if: ${{ matrix.update-coverage }} uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 #v3.1.0 - name: Ensure go generate produces a zero diff for update-urls shell: bash run: cd update-urls && go generate -x ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code) - name: Run go test for update-urls run: cd update-urls && go test -v -race ./...