Skip to content

Commit ff371f0

Browse files
committed
ci: add test run for libpathrs
Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 01a8084 commit ff371f0

File tree

2 files changed

+89
-1
lines changed

2 files changed

+89
-1
lines changed

.github/workflows/ci.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,88 @@ jobs:
217217
token: ${{ secrets.CODECOV_TOKEN }}
218218
slug: cyphar/filepath-securejoin
219219

220+
test-libpathrs:
221+
strategy:
222+
fail-fast: false
223+
matrix:
224+
os:
225+
- ubuntu-22.04
226+
- ubuntu-latest
227+
go-version:
228+
- "1.18"
229+
- "oldstable"
230+
- "stable"
231+
runs-on: ${{ matrix.os }}
232+
steps:
233+
- uses: actions/checkout@v5
234+
235+
- uses: dtolnay/rust-toolchain@stable
236+
- name: find latest libpathrs release
237+
uses: actions/github-script@v8
238+
id: libpathrs-release-tarball
239+
with:
240+
result-encoding: string
241+
script: |-
242+
const latest_release = await github.rest.repos.getLatestRelease({
243+
owner: "cyphar",
244+
repo: "libpathrs",
245+
});
246+
console.log(latest_release);
247+
return latest_release.data.tarball_url;
248+
- name: install libpathrs
249+
run: |-
250+
mkdir -p /tmp/libpathrs
251+
cd /tmp/libpathrs
252+
253+
wget -O latest.tar.gz "${{ steps.libpathrs-release-tarball.outputs.result }}"
254+
tar xvf latest.tar.gz
255+
256+
cd *libpathrs-*/
257+
make release
258+
sudo ./install.sh --libdir=/usr/lib
259+
260+
- uses: actions/setup-go@v6
261+
with:
262+
go-version: ${{ matrix.go-version }}
263+
check-latest: true
264+
- name: mkdir gocoverdir
265+
# We can only use -test.gocoverdir for Go >= 1.20.
266+
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
267+
run: |
268+
GOCOVERDIR="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
269+
echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
270+
- name: go test
271+
run: |-
272+
pkgs=("./pathrs-lite" "./pathrs-lite/procfs")
273+
if [ -n "${GOCOVERDIR:-}" ]; then
274+
go test -v -timeout=30m -cover -coverpkg=./... "${pkgs[@]}" -args -test.gocoverdir="$GOCOVERDIR"
275+
else
276+
go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage.txt "${pkgs[@]}"
277+
fi
278+
- name: sudo go test
279+
run: |-
280+
pkgs=("./pathrs-lite" "./pathrs-lite/procfs")
281+
if [ -n "${GOCOVERDIR:-}" ]; then
282+
sudo go test -v -timeout=30m -cover -coverpkg=./... "${pkgs[@]}" -args -test.gocoverdir="$GOCOVERDIR"
283+
else
284+
sudo go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage-sudo.txt "${pkgs[@]}"
285+
fi
286+
- name: upload coverage artefact
287+
# We can only use -test.gocoverdir for Go >= 1.20.
288+
if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
289+
uses: actions/upload-artifact@v4
290+
with:
291+
name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
292+
path: ${{ env.GOCOVERDIR }}
293+
- name: collate coverage data
294+
if: ${{ env.GOCOVERDIR != '' }}
295+
run: go tool covdata textfmt -i "$GOCOVERDIR" -o "codecov-coverage.txt"
296+
- name: upload coverage to codecov
297+
uses: codecov/codecov-action@v5
298+
with:
299+
token: ${{ secrets.CODECOV_TOKEN }}
300+
slug: cyphar/filepath-securejoin
301+
220302
coverage:
221303
runs-on: ubuntu-latest
222304
needs:
@@ -272,6 +354,7 @@ jobs:
272354
- test-build
273355
- test-windows
274356
- test-unix
357+
- test-libpathrs
275358
- coverage
276359
- codespell
277360
steps:

hack/test.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ GO="${GO:-go}"
1818
silent=
1919
verbose=
2020
long=
21-
while getopts "svL" opt; do
21+
libpathrs=
22+
while getopts "svLl" opt; do
2223
case "$opt" in
2324
s)
2425
silent=1
@@ -29,6 +30,9 @@ while getopts "svL" opt; do
2930
L)
3031
long=1
3132
;;
33+
l)
34+
libpathrs=1
35+
;;
3236
*)
3337
echo "$0 [-s(ilent)]"
3438
exit 1
@@ -41,6 +45,7 @@ trap 'rm -rf $gocoverdir' EXIT
4145
test_args=("-count=1" "-cover" "-coverpkg=./...")
4246
[ -n "$verbose" ] && test_args+=("-v")
4347
[ -z "$long" ] && test_args+=("-short")
48+
[ -n "$libpathrs" ] && test_args+=("-tags" "libpathrs")
4449

4550
"$GO" test "${test_args[@]}" ./... -args -test.gocoverdir="$gocoverdir"
4651
sudo "$GO" test "${test_args[@]}" ./... -args -test.gocoverdir="$gocoverdir"

0 commit comments

Comments
 (0)