-
Notifications
You must be signed in to change notification settings - Fork 3
196 lines (170 loc) · 4.81 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
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-22.04
outputs:
tools: ${{ steps.collect.outputs.tools }}
steps:
- 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}"
echo "tools=${TOOLS_JSON}" >>"${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-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install uniget
uses: uniget-org/uniget-action@v1
with:
prefix: helper
tools: gojq regclient
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
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@v3
if: always()
with:
name: logs.zip
path: "**/build.log"
success:
name: Build container images successfully
needs:
- build
runs-on: ubuntu-22.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
- success
runs-on: ubuntu-22.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@v3
- 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
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 }}