-
-
Notifications
You must be signed in to change notification settings - Fork 116
127 lines (104 loc) · 3.89 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Workflow to run tests, publish coverage to codecov and run SonarCloud scan
name: Test
# Run for events in main repository (for forked repository look in test-for-fork.yml)
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
jobs:
test:
# don't run for forks
if: github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
github.event_name == 'workflow_dispatch'
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- name: Set up Go 1.20+
uses: actions/setup-go@v5
with:
go-version: "^1.20"
check-latest: true
- run: go version
# Checks-out repository under $GITHUB_WORKSPACE with tags and history (needed by "SonarCloud Scan" step)
- name: Full checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Full clone for SonarCloud
# Build everything
- name: Run a build
run: go build ./...
shell: bash
# Runs a single command using the runners shell, -p1 for `race: limit on 8128 simultaneously alive goroutines is exceeded, dying` at macos
- name: Run a test
run: go test -v -race ./... -coverpkg=./... -covermode=atomic -coverprofile=./coverage.txt -json > ./report.json
shell: bash
- name: Dump test report
if: always()
run: cat ./report.json
shell: bash
- name: Prepare upload files
run: |
mkdir -p ./outputs
cp ./coverage.txt ./outputs/${{ matrix.os }}.coverage.txt
cp ./report.json ./outputs/${{ matrix.os }}.report.json
shell: bash
- name: Upload coverage and report files
uses: actions/upload-artifact@v4
with:
name: ${{ hashFiles('./outputs') || 'none' }}
path: ./outputs
retention-days: 1
if-no-files-found: warn
coverage-sonar-cloud-scan:
needs: test
# The type of runner that the job will run on
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./outputs
- name: Prepare coverage and report files
run: |
mkdir -p .tmp/coverage
mkdir -p .tmp/report
find ./outputs -name "*.coverage.txt" -exec sh -c 'cp $1 .tmp/coverage/$(echo $1 | sed "s/[\/.]/-/g" ).coverage.txt' _ {} \;
find ./outputs -name "*.report.json" -exec sh -c 'cp $1 .tmp/report/$(echo $1 | sed "s/[\/.]/-/g" ).report.json' _ {} \;
- name: Code coverage
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: .tmp/
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# test on oldest supported major Go version
test1_20:
# don't run for forks
if: github.event_name == 'push' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.20
uses: actions/setup-go@v5
with:
go-version: "~1.20"
- run: go version
- name: Checkout
uses: actions/checkout@v4
- name: Run a build
run: go build ./...
- name: Run a test
run: go test -v -race ./... -coverpkg=./... -covermode=atomic -coverprofile=./coverage.txt