Debian Codegraph @

.github/workflows/ci.yml

raw
1 # SPDX-License-Identifier: MPL-2.0
2
3 # Copyright (C) 2023-2025 Aleksa Sarai <[email protected]>
4 # Copyright (C) 2023-2025 SUSE LLC
5 #
6 # This Source Code Form is subject to the terms of the Mozilla Public
7 # License, v. 2.0. If a copy of the MPL was not distributed with this
8 # file, You can obtain one at https://mozilla.org/MPL/2.0/.
9
10 name: ci
11
12 on:
13 push:
14 tags:
15 - "v*"
16 branches:
17 - main
18 - "v*"
19 pull_request:
20 schedule:
21 - cron: "30 10 * * 0"
22
23 jobs:
24 lint:
25 runs-on: ubuntu-latest
26 steps:
27 - uses: actions/checkout@v5
28 - uses: actions/setup-go@v6
29 with:
30 go-version: '^1'
31 - name: golangci-lint
32 uses: golangci/golangci-lint-action@v8
33 with:
34 version: v2.1
35
36 test-build:
37 strategy:
38 fail-fast: false
39 matrix:
40 os:
41 - windows-latest
42 - ubuntu-latest
43 - macos-latest
44 go-arch:
45 - amd64
46 go-version:
47 - "1.18"
48 - "1.19"
49 - "1.20"
50 - "1.21"
51 - "1.22"
52 - "1.23"
53 - "^1"
54 include:
55 - os: ubuntu-latest
56 go-arch: "386"
57 go-version: "^1"
58 runs-on: ${{ matrix.os }}
59 steps:
60 - uses: actions/checkout@v5
61 - uses: actions/setup-go@v6
62 with:
63 go-version: ${{ matrix.go-version }}
64 check-latest: true
65 - name: set GOOARCH
66 run: echo "GOARCH=${{ matrix.go-arch }}" >>"$GITHUB_ENV"
67 - name: go build check
68 run: go build ./...
69 - name: go test build check
70 run: go test -run none ./...
71
72 test-windows:
73 strategy:
74 fail-fast: false
75 matrix:
76 go-version:
77 - "1.18"
78 - "1.20"
79 - "1.21"
80 - "oldstable"
81 - "stable"
82 runs-on: windows-latest
83 steps:
84 - uses: actions/checkout@v5
85 - uses: actions/setup-go@v6
86 with:
87 go-version: ${{ matrix.go-version }}
88 check-latest: true
89 - name: mkdir gocoverdir
90 # We can only use -test.gocoverdir for Go >= 1.20.
91 if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
92 run: |
93 # mktemp --tmpdir -d gocoverdir.XXXXXXXX
94 function New-TemporaryDirectory {
95 param (
96 [string] $Prefix
97 )
98 $parent = [System.IO.Path]::GetTempPath()
99 do {
100 [string] $guid = [System.Guid]::NewGuid()
101 $item = New-Item -Path "$parent" -Name "$Prefix.$guid" -ItemType "directory" -ErrorAction SilentlyContinue
102 } while (-not "$item")
103 return $item.FullName
104 }
105 $GOCOVERDIR = (New-TemporaryDirectory -Prefix "gocoverdir")
106 echo "GOCOVERDIR=$GOCOVERDIR" >>"$env:GITHUB_ENV"
107 - name: unit tests
108 run: |
109 if (Test-Path 'env:GOCOVERDIR') {
110 go test -v -cover -coverpkg=./... ./... -args '-test.gocoverdir' "$env:GOCOVERDIR"
111 } else {
112 go test -v -cover -coverpkg=./... -coverprofile codecov-coverage.txt ./...
113 }
114 - name: upload coverage artefact
115 # We can only use -test.gocoverdir for Go >= 1.20.
116 if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
117 uses: actions/upload-artifact@v4
118 with:
119 name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
120 path: ${{ env.GOCOVERDIR }}
121 - name: collate coverage data for codecov
122 if: ${{ env.GOCOVERDIR != '' }}
123 run: go tool covdata textfmt -i "$env:GOCOVERDIR" -o "codecov-coverage.txt"
124 - name: upload coverage to codecov
125 uses: codecov/codecov-action@v5
126 with:
127 token: ${{ secrets.CODECOV_TOKEN }}
128 slug: cyphar/filepath-securejoin
129
130 test-unix:
131 strategy:
132 fail-fast: false
133 matrix:
134 os:
135 - ubuntu-latest
136 - macos-latest
137 go-version:
138 - "1.18"
139 - "1.20"
140 - "1.21"
141 - "oldstable"
142 - "stable"
143 include:
144 # Make sure we test with a slightly older kernel (sadly we can't use
145 # really old images like Ubuntu 18.04). Ubuntu 22.04 uses Linux 6.8.
146 - os: ubuntu-22.04
147 go-version: "oldstable"
148 - os: ubuntu-22.04
149 go-version: "stable"
150 runs-on: ${{ matrix.os }}
151 steps:
152 - uses: actions/checkout@v5
153 - uses: actions/setup-go@v6
154 with:
155 go-version: ${{ matrix.go-version }}
156 check-latest: true
157 - name: mkdir gocoverdir
158 # We can only use -test.gocoverdir for Go >= 1.20.
159 if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
160 run: |
161 GOCOVERDIR="$(mktemp --tmpdir -d gocoverdir.XXXXXXXX)"
162 echo "GOCOVERDIR=$GOCOVERDIR" >>"$GITHUB_ENV"
163 - name: go test
164 run: |-
165 if [ -n "${GOCOVERDIR:-}" ]; then
166 go test -v -timeout=30m -cover -coverpkg=./... ./... -args -test.gocoverdir="$GOCOVERDIR"
167 else
168 go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage.txt ./...
169 fi
170 - name: sudo go test
171 run: |-
172 if [ -n "${GOCOVERDIR:-}" ]; then
173 sudo go test -v -timeout=30m -cover -coverpkg=./... ./... -args -test.gocoverdir="$GOCOVERDIR"
174 else
175 sudo go test -v -timeout=30m -cover -coverpkg=./... -coverprofile codecov-coverage-sudo.txt ./...
176 fi
177 - name: upload coverage artefact
178 # We can only use -test.gocoverdir for Go >= 1.20.
179 if: ${{ matrix.go-version != '1.18' && matrix.go-version != '1.19' }}
180 uses: actions/upload-artifact@v4
181 with:
182 name: coverage-${{ runner.os }}-${{ github.job }}-${{ strategy.job-index }}
183 path: ${{ env.GOCOVERDIR }}
184 - name: collate coverage data
185 if: ${{ env.GOCOVERDIR != '' }}
186 run: go tool covdata textfmt -i "$GOCOVERDIR" -o "codecov-coverage.txt"
187 - name: upload coverage to codecov
188 uses: codecov/codecov-action@v5
189 with:
190 token: ${{ secrets.CODECOV_TOKEN }}
191 slug: cyphar/filepath-securejoin
192
193 coverage:
194 runs-on: ubuntu-latest
195 needs:
196 - test-windows
197 - test-unix
198 steps:
199 - uses: actions/checkout@v5
200 - uses: actions/setup-go@v6
201 with:
202 go-version: "stable"
203 check-latest: true
204 - name: download all coverage
205 uses: actions/download-artifact@v5
206 with:
207 path: coverage
208 - name: generate coverage list
209 run: |
210 find coverage/
211 GOCOVERDIRS="$(printf '%s,' coverage/* | sed 's|,$||')"
212 echo "GOCOVERDIRS=$GOCOVERDIRS" >>"$GITHUB_ENV"
213 FULLCOVERAGE_FILE="$(mktemp --tmpdir fullcoverage.XXXXXXXX)"
214 echo "FULLCOVERAGE_FILE=$FULLCOVERAGE_FILE" >>"$GITHUB_ENV"
215 - name: compute coverage
216 run: go tool covdata percent -i "$GOCOVERDIRS"
217 - name: compute func coverage
218 run: go tool covdata func -i "$GOCOVERDIRS" | sort -k 3gr
219 - name: merge coverage
220 run: |
221 go tool covdata textfmt -i "$GOCOVERDIRS" -o "$FULLCOVERAGE_FILE"
222 go tool cover -html="$FULLCOVERAGE_FILE" -o "$FULLCOVERAGE_FILE.html"
223 - name: upload merged coverage
224 uses: actions/upload-artifact@v4
225 with:
226 name: fullcoverage-${{ github.job }}
227 path: ${{ env.FULLCOVERAGE_FILE }}
228 - name: upload coverage html
229 uses: actions/upload-artifact@v4
230 with:
231 name: fullcoverage-${{ github.job }}.html
232 path: ${{ env.FULLCOVERAGE_FILE }}.html
233
234 codespell:
235 runs-on: ubuntu-latest
236 steps:
237 - uses: actions/checkout@v5
238 - run: pip install codespell==v2.3.0
239 - run: codespell
240
241 complete:
242 runs-on: ubuntu-latest
243 needs:
244 - lint
245 - test-build
246 - test-windows
247 - test-unix
248 - coverage
249 - codespell
250 steps:
251 - run: echo "all done"