...
1on:
2 push:
3 branches:
4 - master
5 pull_request:
6 branches:
7 - master
8
9name: tests
10env:
11 GO111MODULE: on
12
13permissions:
14 contents: read
15
16jobs:
17 test:
18 permissions:
19 actions: write # for styfle/cancel-workflow-action to cancel/stop running workflows
20 contents: read # for actions/checkout to fetch code
21 strategy:
22 matrix:
23 go-version: [1.x, 1.17.x]
24 platform: [ubuntu-latest]
25 include:
26 # include windows, but only with the latest Go version, since there
27 # is very little in the library that is platform specific
28 - go-version: 1.x
29 platform: windows-latest
30
31 # only update test coverage stats with the most recent go version on linux
32 - go-version: 1.x
33 platform: ubuntu-latest
34 update-coverage: true
35 runs-on: ${{ matrix.platform }}
36
37 steps:
38 - name: Cancel previous
39 uses: styfle/cancel-workflow-action@a40b8845c0683271d9f53dfcb887a7e181d3918b #0.9.1
40 with:
41 access_token: ${{ github.token }}
42
43 - uses: actions/setup-go@v3
44 with:
45 go-version: ${{ matrix.go-version }}
46 - uses: actions/checkout@v3
47
48 # Get values for cache paths to be used in later steps
49 - id: cache-paths
50 run: |
51 echo "::set-output name=go-cache::$(go env GOCACHE)"
52 echo "::set-output name=go-mod-cache::$(go env GOMODCACHE)"
53
54 - name: Cache go modules
55 uses: actions/cache@v3
56 with:
57 path: |
58 ${{ steps.cache-paths.outputs.go-cache }}
59 ${{ steps.cache-paths.outputs.go-mod-cache }}
60 key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
61 restore-keys: ${{ runner.os }}-go-
62
63 - name: Ensure go generate produces a zero diff
64 shell: bash
65 run: go generate -x ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
66
67 - name: Run go test
68 run: go test -v -race -coverprofile coverage.txt -covermode atomic ./...
69
70 - name: Ensure integration tests build
71 # don't actually run tests since they hit live GitHub API
72 run: go test -v -tags=integration -run=^$ ./test/integration
73
74 - name: Run scrape tests
75 run: |
76 cd scrape
77 go test ./...
78
79 - name: Upload coverage to Codecov
80 if: ${{ matrix.update-coverage }}
81 uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 #v3.1.0
82
83 - name: Ensure go generate produces a zero diff for update-urls
84 shell: bash
85 run: cd update-urls && go generate -x ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
86
87 - name: Run go test for update-urls
88 run: cd update-urls && go test -v -race ./...
View as plain text