-
Notifications
You must be signed in to change notification settings - Fork 3
162 lines (158 loc) · 5.66 KB
/
Copy pathtest.yml
File metadata and controls
162 lines (158 loc) · 5.66 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# Copyright 2024 Marc-Antoine Ruel. All rights reserved.
# Use of this source code is governed under the Apache License, Version 2.0
# that can be found in the LICENSE file.
# Run tests and linters on main and release changes, pull requests, and automation requests.
on:
push:
branches: [main, "v*"]
pull_request:
branches: [main, "v*"]
workflow_dispatch:
name: Run tests
jobs:
# Runs go test both with code coverage sent to codecov, race detector and
# benchmarks. At the end do a quick check to ensure the tests to not leave
# files in the tree.
test:
name: "test: ${{matrix.os}}"
runs-on: "${{matrix.os}}"
continue-on-error: true
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
PYTHONDONTWRITEBYTECODE: x
steps:
- name: Turn off git core.autocrlf
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf false
- uses: actions/checkout@v6
with:
fetch-depth: 2
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: "go install necessary tools"
if: always()
run: |
go install github.com/maruel/pat/cmd/ba@latest
- name: "Check: go test -cover (full)"
# Only run costly tests on linux.
if: matrix.os == 'ubuntu-latest'
env:
# Make sure we don't get throttled calling github apis.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: go test -timeout=600s -covermode=count -coverprofile coverage.txt -bench=. -benchtime=1x ./...
- name: "Check: go test -cover (light)"
if: matrix.os == 'windows-latest' || matrix.os == 'macos-latest'
env:
# Make sure we don't get throttled calling github apis.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: go test -timeout=600s -covermode=count -coverprofile coverage.txt -bench=. -benchtime=1x ./...
# Don't send code coverage if anything failed to reduce spam.
- uses: codecov/codecov-action@v6
with:
token: ${{secrets.CODECOV_TOKEN}}
- name: "Cleanup"
if: always()
run: rm -f coverage.txt codecov codecov.*
- name: "Check: tree is clean"
if: always()
run: |
# Nothing should have changed in the tree up to that point and no
# unsuspected file was created.
TOUCHED=$(git status --porcelain)
if ! test -z "$TOUCHED"; then
echo "Oops, something touched these files, please cleanup:"
echo "$TOUCHED"
git diff
false
fi
# Run linters. This workflow can be merged with the test_all one if desired
# to cut on runtime, at the cost of latency. I dislike waiting for results
# so I prefer to run them in parallel.
lint:
name: "lint: ${{matrix.os}}"
runs-on: "${{matrix.os}}"
continue-on-error: true
defaults:
run:
shell: bash
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
PYTHONDONTWRITEBYTECODE: x
steps:
- name: Turn off git core.autocrlf
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf false
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- name: "go install golangci-lint"
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
- name: "Check: golangci-lint"
run: golangci-lint run ./...
- name: "go install necessary tools (ubuntu)"
if: always() && matrix.os == 'ubuntu-latest'
run: |
go install github.com/google/addlicense@latest
- name: "Check: no executable was committed (ubuntu)"
if: always() && matrix.os == 'ubuntu-latest'
run: |
if find . -type f -not -path './.git/*' -not -path './cache/*' -not -path './py/venv/*' -not -name '*.sh' -not -name '*.py' -not -name '*.go' -perm /111 | grep -e . ; then
echo 'Do not commit executables beside shell scripts'
false
fi
- name: "Check: addlicense; all sources have a license header (ubuntu)"
if: always() && matrix.os == 'ubuntu-latest'
run: addlicense -ignore default_config.yml -ignore "examples/**" -ignore "**/testdata/**" -check .
- name: "Check: go generate doesn't modify files"
if: always()
run: |
go generate ./...
# Also test for untracked files. go generate should not generate ignored
# files either.
TOUCHED=$(git status --porcelain --ignored)
if ! test -z "$TOUCHED"; then
echo "go generate created these files, please fix:"
echo "$TOUCHED"
false
fi
- name: "Check: go mod tidy doesn't modify files"
if: always()
run: |
go mod tidy
TOUCHED=$(git status --porcelain --ignored)
if ! test -z "$TOUCHED"; then
echo "go mod tidy was not clean, please update:"
git diff
false
fi
codeql:
name: "codeql: ${{matrix.os}}"
runs-on: "${{matrix.os}}"
continue-on-error: true
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
permissions:
security-events: write
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version-file: go.mod
- uses: github/codeql-action/init@v4
with:
languages: go
- uses: github/codeql-action/autobuild@v4
- uses: github/codeql-action/analyze@v4