Repository navigation
365 lines (346 loc) · 11.8 KB
/
Copy pathci.yml
File metadata and controls
365 lines (346 loc) · 11.8 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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# SPDX-License-Identifier: MPL-2.0
# Copyright (C) 2023-2025 Aleksa Sarai <cyphar@cyphar.com>
# Copyright (C) 2023-2025 SUSE LLC
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
name: ci
on:
push:
tags:
- "v*"
branches:
- main
- "v*"
pull_request:
schedule:
- cron: "30 10 * * 0"
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
# We need libpathrs so that golangci-lint can typecheck
# "cyphar.com/go-pathrs" (the package needs to be buildable).
- uses: dtolnay/rust-toolchain@stable
- name: find latest libpathrs release
uses: actions/github-script@v8
id: libpathrs-release-tarball
with:
result-encoding: string
script: |-
const latest_release = await github.rest.repos.getLatestRelease({
owner: "cyphar",
repo: "libpathrs",
});
console.log(latest_release);
return latest_release.data.tarball_url;
- name: install libpathrs
run: |-
mkdir -p /tmp/libpathrs
cd /tmp/libpathrs
wget -O latest.tar.gz "${{ steps.libpathrs-release-tarball.outputs.result }}"
tar xvf latest.tar.gz
cd *libpathrs-*/
make release
sudo ./install.sh --libdir=/usr/lib
- uses: actions/setup-go@v6
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.12
build:
strategy:
fail-fast: false
matrix:
go-version:
- "1.18"
- "1.19"
- "1.20"
- "1.21"
- "1.22"
- "1.23"
# TODO: add 1.24 here once Go 1.26 is out.
- oldstable
- stable
go-arch:
- amd64
os:
- windows-latest
- ubuntu-latest
- macos-latest
include:
- go-version: stable
go-arch: "386"
os: ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: set GOARCH
run: echo "GOARCH=${{ matrix.go-arch }}" >>"$GITHUB_ENV"
- name: go build check
run: go build ./...
- name: go test build check
run: go test -run none ./...
windows:
strategy:
fail-fast: false
matrix:
go-version:
- "1.18"
- "1.20"
- "1.21"
- "oldstable"
- "stable"
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: mkdir gocoverdir
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
run: |
# mktemp --tmpdir -d gocoverdir.XXXXXXXX
function New-TemporaryDirectory {
param (
[string] $Prefix
)
$parent = [System.IO.Path]::GetTempPath()
do {
[string] $guid = [System.Guid]::NewGuid()
$item = New-Item -Path "$parent" -Name "$Prefix.$guid" -ItemType "directory" -ErrorAction SilentlyContinue
} while (-not "$item")
return $item.FullName
}
$GOCOVERDIR = (New-TemporaryDirectory -Prefix "gocoverdir")
echo "GOCOVERDIR=$GOCOVERDIR" >>"$env:GITHUB_ENV"
- name: unit tests
run: |
if (Test-Path 'env:GOCOVERDIR') {
go test -v -cover -coverpkg=./... ./... -args '-test.gocoverdir' "$env:GOCOVERDIR"
} else {
go test -v -cover -coverpkg=./... -coverprofile codecov-coverage.txt ./...
}
- name: upload coverage artefact
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
uses: actions/upload-artifact@v6
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
path: ${{ env.GOCOVERDIR }}
- name: collate coverage data for codecov
if: ${{ env.GOCOVERDIR != '' }}
run: go tool covdata textfmt -i "$env:GOCOVERDIR" -o "codecov-coverage.txt"
- name: upload coverage to codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: cyphar/filepath-securejoin
unix:
strategy:
fail-fast: false
matrix:
go-version:
- "1.18"
- "1.20"
- "1.21"
- "oldstable"
- "stable"
os:
- ubuntu-latest
- macos-latest
include:
# Make sure we test with a slightly older kernel (sadly we can't use
# really old images like Ubuntu 18.04). Ubuntu 22.04 uses Linux 6.8.
- go-version: "oldstable"
os: ubuntu-22.04
- go-version: "stable"
os: ubuntu-22.04
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: mkdir gocoverdir
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
run: |
GOCOVERDIR="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
- name: go test
run: |-
if [ -n "${GOCOVERDIR:-}" ]; then
go test -v -timeout=30m -cover -coverpkg=./... ./... -args -test.gocoverdir="$GOCOVERDIR"
else
go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage.txt ./...
fi
- name: sudo go test
run: |-
if [ -n "${GOCOVERDIR:-}" ]; then
sudo go test -v -timeout=30m -cover -coverpkg=./... ./... -args -test.gocoverdir="$GOCOVERDIR"
else
sudo go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage-sudo.txt ./...
fi
- name: upload coverage artefact
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
uses: actions/upload-artifact@v6
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
path: ${{ env.GOCOVERDIR }}
- name: collate coverage data
if: ${{ env.GOCOVERDIR != '' }}
run: go tool covdata textfmt -i "$GOCOVERDIR" -o "codecov-coverage.txt"
- name: upload coverage to codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: cyphar/filepath-securejoin
libpathrs:
strategy:
fail-fast: false
matrix:
go-version:
- "1.18"
- "oldstable"
- "stable"
os:
- ubuntu-22.04
- ubuntu-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- name: find latest libpathrs release
uses: actions/github-script@v8
id: libpathrs-release-tarball
with:
result-encoding: string
script: |-
const latest_release = await github.rest.repos.getLatestRelease({
owner: "cyphar",
repo: "libpathrs",
});
console.log(latest_release);
return latest_release.data.tarball_url;
- name: install libpathrs
run: |-
mkdir -p /tmp/libpathrs
cd /tmp/libpathrs
wget -O latest.tar.gz "${{ steps.libpathrs-release-tarball.outputs.result }}"
tar xvf latest.tar.gz
cd *libpathrs-*/
make release
sudo ./install.sh --libdir=/usr/lib
- uses: actions/setup-go@v6
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: mkdir gocoverdir
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
run: |
GOCOVERDIR="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
- name: go test
run: |-
pkgs=("./pathrs-lite" "./pathrs-lite/procfs")
if [ -n "${GOCOVERDIR:-}" ]; then
go test -v -timeout=30m -cover -coverpkg=./... "${pkgs[@]}" -args -test.gocoverdir="$GOCOVERDIR"
else
go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage.txt "${pkgs[@]}"
fi
- name: sudo go test
run: |-
pkgs=("./pathrs-lite" "./pathrs-lite/procfs")
if [ -n "${GOCOVERDIR:-}" ]; then
sudo go test -v -timeout=30m -cover -coverpkg=./... "${pkgs[@]}" -args -test.gocoverdir="$GOCOVERDIR"
else
sudo go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage-sudo.txt "${pkgs[@]}"
fi
- name: upload coverage artefact
# We can only use -test.gocoverdir for Go >= 1.20.
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
uses: actions/upload-artifact@v6
with:
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
path: ${{ env.GOCOVERDIR }}
- name: collate coverage data
if: ${{ env.GOCOVERDIR != '' }}
run: go tool covdata textfmt -i "$GOCOVERDIR" -o "codecov-coverage.txt"
- name: upload coverage to codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: cyphar/filepath-securejoin
coverage:
runs-on: ubuntu-latest
needs:
- windows
- unix
- libpathrs
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: "stable"
check-latest: true
- name: download all coverage
uses: actions/download-artifact@v7
with:
path: coverage
- name: generate coverage list
run: |
find coverage/
GOCOVERDIRS="$(printf '%s,' coverage/* | sed 's|,$||')"
echo "GOCOVERDIRS=$GOCOVERDIRS" >>"$GITHUB_ENV"
FULLCOVERAGE_FILE="$(mktemp --tmpdir fullcoverage.XXXXXXXX)"
echo "FULLCOVERAGE_FILE=$FULLCOVERAGE_FILE" >>"$GITHUB_ENV"
- name: compute coverage
run: go tool covdata percent -i "$GOCOVERDIRS"
- name: compute func coverage
run: go tool covdata func -i "$GOCOVERDIRS" | sort -k 3gr
- name: merge coverage
run: |
go tool covdata textfmt -i "$GOCOVERDIRS" -o "$FULLCOVERAGE_FILE"
go tool cover -html="$FULLCOVERAGE_FILE" -o "$FULLCOVERAGE_FILE.html"
- name: upload merged coverage
uses: actions/upload-artifact@v6
with:
name: fullcoverage-${{ github.job }}
path: ${{ env.FULLCOVERAGE_FILE }}
- name: upload coverage html
uses: actions/upload-artifact@v6
with:
name: fullcoverage-${{ github.job }}.html
path: ${{ env.FULLCOVERAGE_FILE }}.html
codespell:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- run: pip install codespell==v2.4.1
- run: codespell
complete:
runs-on: ubuntu-latest
needs:
- lint
- build
- windows
- unix
- libpathrs
- coverage
- codespell
steps:
- run: echo "all done"