Debian Codegraph @

.github/workflows/test-go-task.yml

raw
1 # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/test-go-task.md
2 name: Test Go
3
4 # See: https://docs.github.com/actions/reference/workflows-and-actions/events-that-trigger-workflows
5 on:
6 create:
7 push:
8 paths:
9 - ".github/workflows/test-go-task.ya?ml"
10 - ".github/.?codecov.ya?ml"
11 - "dev/.?codecov.ya?ml"
12 - ".?codecov.ya?ml"
13 - "**/go.mod"
14 - "**/go.sum"
15 - "Taskfile.ya?ml"
16 - "**.go"
17 - "**/testdata/**"
18 pull_request:
19 paths:
20 - ".github/workflows/test-go-task.ya?ml"
21 - ".github/.?codecov.ya?ml"
22 - "dev/.?codecov.ya?ml"
23 - ".?codecov.ya?ml"
24 - "**/go.mod"
25 - "**/go.sum"
26 - "Taskfile.ya?ml"
27 - "**.go"
28 - "**/testdata/**"
29 schedule:
30 # Run periodically to catch breakage caused by external changes.
31 - cron: "0 11 * * WED"
32 workflow_dispatch:
33 repository_dispatch:
34
35 jobs:
36 run-determination:
37 runs-on: ubuntu-latest
38 outputs:
39 result: ${{ steps.determination.outputs.result }}
40 permissions: {}
41 steps:
42 - name: Determine if the rest of the workflow should run
43 id: determination
44 run: |
45 RELEASE_BRANCH_REGEX="refs/heads/[0-9]+.[0-9]+.x"
46 # The `create` event trigger doesn't support `branches` filters, so it's necessary to use Bash instead.
47 if [[
48 "${{ github.event_name }}" != "create" ||
49 "${{ github.ref }}" =~ $RELEASE_BRANCH_REGEX
50 ]]; then
51 # Run the other jobs.
52 RESULT="true"
53 else
54 # There is no need to run the other jobs.
55 RESULT="false"
56 fi
57
58 echo "result=$RESULT" >>$GITHUB_OUTPUT
59
60 test:
61 name: test (${{ matrix.module.path }} - ${{ matrix.operating-system }})
62 needs: run-determination
63 if: needs.run-determination.outputs.result == 'true'
64 permissions:
65 contents: read
66
67 strategy:
68 fail-fast: false
69
70 matrix:
71 operating-system:
72 - ubuntu-latest
73 - windows-latest
74 - macos-latest
75 module:
76 # TODO: add paths of all Go modules here
77 - path: ./
78 codecov-flags: unit
79
80 runs-on: ${{ matrix.operating-system }}
81
82 steps:
83 - name: Checkout repository
84 uses: actions/checkout@v7
85
86 - name: Install Go
87 uses: actions/setup-go@v7
88 with:
89 go-version-file: go.mod
90
91 - name: Run tests
92 env:
93 GO_MODULE_PATH: ${{ matrix.module.path }}
94 shell: bash
95 run: |
96 go tool \
97 github.com/go-task/task/v3/cmd/task go:test
98
99 - name: Send unit tests coverage to Codecov
100 if: runner.os == 'Linux'
101 uses: codecov/codecov-action@v7
102 with:
103 # A token is used to avoid intermittent spurious job failures caused by rate limiting.
104 token: d2497f03-291d-4e0c-9d31-d94614ed7c16
105 file: ${{ matrix.module.path }}coverage_unit.txt
106 flags: ${{ matrix.module.codecov-flags }}
107 fail_ci_if_error: ${{ github.repository == 'arduino/pluggable-discovery-protocol-handler' }}