-
Notifications
You must be signed in to change notification settings - Fork 3
298 lines (259 loc) · 7.75 KB
/
check.yml
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
name: Check
on:
pull_request:
types:
- opened
- synchronize
paths:
- tools/**
- .github/workflows/*
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
collect:
name: Collect tools
permissions:
pull-requests: read
runs-on: ubuntu-24.04
outputs:
tools: ${{ steps.collect.outputs.tools }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: gojq regclient
- name: Collect
id: collect
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR: ${{ github.event.pull_request.number }}
run: |
set -o errexit -o pipefail
echo "### This is PR ${PR}"
TOOLS="$(
gh api --paginate "repos/${GITHUB_REPOSITORY}/pulls/${PR}/files" \
| helper/usr/local/bin/jq --raw-output '.[] | select(.status != "removed") | .filename' \
| grep -E '^tools/[^/]+/' \
| cut -d/ -f2 \
| uniq \
| xargs echo
)"
echo "### Got TOOLS=${TOOLS}."
TOOLS_JSON="$(
echo -n "${TOOLS}" \
| tr ' ' '\n' \
| helper/usr/local/bin/jq --raw-input '.' \
| helper/usr/local/bin/jq --slurp --compact-output '.'
)"
echo " JSON: ${TOOLS_JSON}"
TOOLS_JSON_LEN="$(
echo -n "${TOOLS_JSON}" \
| jq 'length'
)"
echo " TOOLS_JSON_LEN=${TOOLS_JSON_LEN}"
if test "${TOOLS_JSON_LEN}" -ge 256; then
echo "### Too many tools to process: ${TOOLS_JSON_LEN}."
echo "### Fallback to last commit"
TOOLS="$(
git log -1 --pretty=format: --name-only --diff-filter=d \
| grep ^tools/ \
| cut -d/ -f2 \
| sort \
| uniq \
| xargs echo
)"
echo "### Got tools=${TOOLS}."
if test -z "${TOOLS}"; then
echo "### No tools to process."
TOOLS_JSON="[]"
TOOLS_JSON_LEN=0
else
TOOLS_JSON="$(
echo -n "${TOOLS}" \
| tr ' ' '\n' \
| helper/usr/local/bin/jq --raw-input '.' \
| helper/usr/local/bin/jq --slurp --compact-output '.'
)"
echo " JSON: ${TOOLS_JSON}"
TOOLS_JSON_LEN="$(
echo -n "${TOOLS_JSON}" \
| jq 'length'
)"
echo " TOOLS_JSON_LEN=${TOOLS_JSON_LEN}"
fi
fi
echo "tools=${TOOLS_JSON}" >>"${GITHUB_OUTPUT}"
echo "tools_len=${TOOLS_JSON_LEN}" >>"${GITHUB_OUTPUT}"
build:
name: Build container image
needs:
- collect
strategy:
fail-fast: false
matrix:
tool: ${{ fromJSON(needs.collect.outputs.tools) }}
permissions:
packages: write
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: gojq regclient
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: uniget-bot
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container image
run: |
echo "### Building ${{ matrix.tool }}"
make ${{ matrix.tool }}--push
- name: Store logs
uses: actions/upload-artifact@v4
if: always()
with:
name: ${{ matrix.tool }}-build.log.zip
path: "**/build.log"
success:
name: Build container images successfully
needs:
- build
runs-on: ubuntu-24.04
steps:
- run: |
true
visibility:
name: Check visibility
needs:
- collect
- build
strategy:
fail-fast: false
matrix:
tool: ${{ fromJSON(needs.collect.outputs.tools) }}
uses: ./.github/workflows/check-visibility.yml
with:
name: ${{ matrix.tool }}
collect_versions:
name: Collect versions for tools
needs:
- collect
runs-on: ubuntu-24.04
outputs:
tools_with_version: ${{ steps.extract_versions.outputs.tools_with_version }}
env:
tools: ${{ needs.collect.outputs.tools }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: yq gojq
- name: Extract versions
id: extract_versions
run: |
echo "Processing tools: ${tools}."
tools_with_version=""
TOOLS_RAW="$(
echo "${tools}" \
| helper/usr/local/bin/jq --raw-output '.[]'
)"
for TOOL in ${TOOLS_RAW}; do
echo "${TOOL}"
VERSION="$( helper/usr/local/bin/yq '.version' "tools/${TOOL}/manifest.yaml" )"
echo "${VERSION}"
tools_with_version="${tools_with_version}${TOOL}:${VERSION} "
done
echo "tools_with_version=${tools_with_version}."
tools_with_version_json="$(
echo -n "${tools_with_version}" \
| tr ' ' '\n' \
| helper/usr/local/bin/jq --raw-input '.' \
| helper/usr/local/bin/jq --slurp --compact-output '.'
)"
echo "JSON: ${tools_with_version_json}"
echo "tools_with_version=${tools_with_version_json}" >>"${GITHUB_OUTPUT}"
scan:
name: Scan container images
needs:
- collect_versions
- success
permissions:
security-events: write
pull-requests: write
packages: read
strategy:
fail-fast: false
matrix:
tool_with_version: ${{ fromJSON(needs.collect_versions.outputs.tools_with_version) }}
uses: ./.github/workflows/scan.yml
with:
name_and_version: ${{ matrix.tool_with_version }}
secrets:
DOCKERHUB_USER: ${{ secrets.DOCKERHUB_USER }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
version:
name: Test version extraction
needs:
- collect_versions
- success
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
tool_with_version: ${{ fromJSON(needs.collect_versions.outputs.tools_with_version) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
- name: Test version extraction
run: |
TOOL_WITH_VERSION="${{ matrix.tool_with_version }}"
TOOL="$( echo "${TOOL_WITH_VERSION}" | cut -d: -f1 )"
VERSION="$( echo "${TOOL_WITH_VERSION}" | cut -d: -f2 )"
export TOOL
export VERSION
bash scripts/test.sh
test:
name: Smoke test
needs:
- collect_versions
- success
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
tool_with_version: ${{ fromJSON(needs.collect_versions.outputs.tools_with_version) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Smoke test
run: |
TOOL_WITH_VERSION="${{ matrix.tool_with_version }}"
TOOL="$( echo "${TOOL_WITH_VERSION}" | cut -d: -f1 )"
VERSION="$( echo "${TOOL_WITH_VERSION}" | cut -d: -f2 )"
if ! test -f "tools/${TOOL}/test.sh"; then
echo "No test script for ${TOOL}."
exit 0
fi
name="${TOOL}" version="${VERSION}" bash "tools/${TOOL}/test.sh"