-
Notifications
You must be signed in to change notification settings - Fork 49
251 lines (218 loc) · 7.32 KB
/
Copy pathci.yml
File metadata and controls
251 lines (218 loc) · 7.32 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
---
name: CI
# ci.yml performs the Continuous Integration (CI) workflow and performs the
# following actions:
# - conditional GitHub automation lint
# - Go format/vet
# - conditional JS lint
# - conditional Lua lint
# - PR Go race tests
"on":
push:
branches:
- master
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
# Superseded CI runs cancel previous runs
concurrency:
group: >-
${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
detect-changes:
name: Detect CI Inputs
runs-on: ubuntu-24.04
timeout-minutes: 5
outputs:
automation_lint: >-
${{ steps.filter.outputs.automation_lint }}
go_lint: >-
${{ steps.filter.outputs.go_lint }}
go_tests: >-
${{ steps.filter.outputs.go_tests }}
js_lint: >-
${{ steps.filter.outputs.js_lint }}
lua_lint: >-
${{ steps.filter.outputs.lua_lint }}
steps:
# Depth 2 covers normal single-commit pushes and pull request merge
# parents; the script fetches the base commit for larger push ranges.
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
fetch-depth: 2
persist-credentials: false
- id: filter
name: Detect relevant inputs
env:
BASE_REF: >-
${{ github.event.pull_request.base.sha || github.event.before }}
EVENT_NAME: ${{ github.event_name }}
HEAD_REF: ${{ github.sha }}
run: |
set -eu
if [ -z "${BASE_REF}" ] || \
[ "${BASE_REF}" = "0000000000000000000000000000000000000000" ]; then
BASE_REF="$(git rev-parse HEAD^)"
fi
if ! git cat-file -e "${BASE_REF}^{commit}" 2>/dev/null; then
if ! git fetch --no-tags --depth=1 origin "${BASE_REF}" \
2>/dev/null; then
git fetch --no-tags --unshallow origin
fi
fi
changed_files="$(git diff --name-only "${BASE_REF}" "${HEAD_REF}")"
printf '%s\n' "${changed_files}"
if printf '%s\n' "${changed_files}" | \
grep -Eq '^(Makefile|\.jshintrc(\..*)?$|_datafiles/.*\.js$)'; then
echo "js_lint=true" >> "$GITHUB_OUTPUT"
else
echo "js_lint=false" >> "$GITHUB_OUTPUT"
fi
if printf '%s\n' "${changed_files}" | grep -Eq '^\.github/'; then
echo "automation_lint=true" >> "$GITHUB_OUTPUT"
else
echo "automation_lint=false" >> "$GITHUB_OUTPUT"
fi
lua_re='(^|/)[^/]+\.lua$'
lua_re="${lua_re}|^(Makefile|\.luacheckrc|\.github/workflows/ci\.yml)$"
if printf '%s\n' "${changed_files}" | grep -Eq "${lua_re}"; then
echo "lua_lint=true" >> "$GITHUB_OUTPUT"
else
echo "lua_lint=false" >> "$GITHUB_OUTPUT"
fi
go_re='(^|/)[^/]+\.go$'
go_re="${go_re}|^(go\.mod|go\.sum|Makefile)$"
# Module files can be embedded through go:embed, so data-only module
# asset changes still need Go validation.
go_re="${go_re}|^modules/[^/]+/files/"
go_re="${go_re}|^\.github/actions/(go-checks|setup-go)/"
go_re="${go_re}|^\.github/workflows/ci\.yml"
if printf '%s\n' "${changed_files}" | grep -Eq "${go_re}"; then
echo "go_lint=true" >> "$GITHUB_OUTPUT"
# Pull requests run race tests here; master pushes are covered by
# the prerelease validation workflow.
if [ "${EVENT_NAME}" = "pull_request" ]; then
echo "go_tests=true" >> "$GITHUB_OUTPUT"
else
echo "go_tests=false" >> "$GITHUB_OUTPUT"
fi
else
echo "go_lint=false" >> "$GITHUB_OUTPUT"
echo "go_tests=false" >> "$GITHUB_OUTPUT"
fi
automation-lint:
name: GitHub Automation Lint
runs-on: ubuntu-24.04
timeout-minutes: 10
needs: detect-changes
if: >-
needs.detect-changes.outputs.automation_lint == 'true'
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- name: Set up Go for actionlint
# actions/setup-go v6.4.0
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c
with:
go-version: '1.25.x'
cache: false
- name: Install automation linters
env:
ACTIONLINT_VERSION: v1.7.8
YAMLLINT_VERSION: 1.38.0
run: |
set -euo pipefail
go install \
"github.com/rhysd/actionlint/cmd/actionlint@${ACTIONLINT_VERSION}"
need_apt=false
if ! python3 -m pip --version >/dev/null 2>&1; then
need_apt=true
fi
if ! command -v shellcheck >/dev/null 2>&1; then
need_apt=true
fi
if [ "$need_apt" = "true" ]; then
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
python3-pip \
shellcheck
fi
python3 -m pip install --user "yamllint==${YAMLLINT_VERSION}"
- name: Run automation lint
run: |
set -euo pipefail
export PATH="$HOME/go/bin:$HOME/.local/bin:$PATH"
actionlint .github/workflows/*.yml
yamllint .github
shellcheck .github/scripts/*.sh
go-lint:
name: Go Format And Vet
runs-on: ubuntu-24.04
timeout-minutes: 20
needs: detect-changes
if: >-
needs.detect-changes.outputs.go_lint == 'true'
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- uses: ./.github/actions/setup-go
- name: Run Go lint checks
run: make validate
js-lint:
name: JavaScript Lint
runs-on: ubuntu-24.04
timeout-minutes: 10
needs: detect-changes
if: >-
needs.detect-changes.outputs.js_lint == 'true'
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- name: Set up Node.js
# actions/setup-node v6.4.0
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e
with:
node-version: '22'
- name: Run JavaScript lint checks
run: make js-lint
lua-lint:
name: Lua Lint
runs-on: ubuntu-24.04
timeout-minutes: 10
needs: detect-changes
if: >-
needs.detect-changes.outputs.lua_lint == 'true'
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- name: Run Lua lint checks
run: make lua-lint
test:
name: Go Tests
runs-on: ubuntu-24.04
timeout-minutes: 30
needs: detect-changes
if: >-
needs.detect-changes.outputs.go_tests == 'true'
steps:
# actions/checkout v6.0.3
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10
with:
persist-credentials: false
- uses: ./.github/actions/setup-go
- uses: ./.github/actions/go-checks