-
Notifications
You must be signed in to change notification settings - Fork 0
312 lines (312 loc) · 11.1 KB
/
pull-request.yml
File metadata and controls
312 lines (312 loc) · 11.1 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
name: Pull Request
on:
pull_request:
branches:
- main
- release/*
permissions:
contents: read
defaults:
run:
shell: bash
concurrency:
group: ${{github.event.pull_request.number}}
cancel-in-progress: true
jobs:
check-packages:
name: Check Packages
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
with:
ref: ${{github.head_ref}}
- name: Update packages
id: updates
run: bash .github/scripts/update-packages.sh
- name: Gather info
id: info
run: |
USER_NAME="github-actions[bot]"
USER_ID=$(gh api "/users/${USER_NAME}" --jq '.id')
USER_EMAIL="${USER_ID}+${USER_NAME}@users.noreply.github.com"
echo "commit-author=${USER_NAME} <${USER_EMAIL}>" >> "${GITHUB_OUTPUT}"
echo "title=Update packages for PR #${PR_NUMBER}" >> "${GITHUB_OUTPUT}"
env:
GITHUB_TOKEN: ${{github.token}}
PR_NUMBER: ${{github.event.pull_request.number}}
- name: Push changes
uses: peter-evans/create-pull-request@v8.1.0
id: changes
with:
token: ${{github.token}}
commit-message: ${{steps.info.outputs.title}}
author: ${{steps.info.outputs.commit-author}}
committer: ${{steps.info.outputs.commit-author}}
add-paths: packages/generated/install.txt
base: ${{github.event.pull_request.head.ref}}
branch: auto/update-packages/pr-${{github.event.pull_request.number}}
delete-branch: true
draft: true
title: ${{steps.info.outputs.title}}
body: ${{steps.updates.outputs.update-body}}
labels: |
dependencies
auto
- name: Report status
if: >
steps.changes.outputs.pull-request-operation == 'created' ||
steps.changes.outputs.pull-request-operation == 'updated'
uses: actions/github-script@v9.0.0
with:
script: core.setFailed('Build changes detected')
check-formatting-all:
name: Check Formatting (All)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
- name: Set up EditorConfig Checker
uses: editorconfig-checker/action-editorconfig-checker@v2.2.0
- name: Check formatting
run: editorconfig-checker
check-formatting-dockerfile:
name: Check Formatting (Dockerfile)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
- name: Check formatting
uses: hadolint/hadolint-action@v3.3.0
check-formatting-markdown:
name: Check Formatting (Markdown)
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
- name: Check formatting
uses: davidanson/markdownlint-cli2-action@v23.0.0
with:
globs: '**/*.md'
build-and-test:
name: Build & Test
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read
pull-requests: write
needs:
- check-packages
steps:
- name: Checkout
uses: actions/checkout@v6.0.2
- name: Determine info
id: info
run: |
PLATFORMS=(
linux/amd64
linux/arm/v7
linux/arm64
linux/ppc64le
linux/riscv64
linux/s390x
)
SAVE_IFS="$IFS"
IFS=","
PLATFORMS="${PLATFORMS[*]}"
IFS="$SAVE_IFS"
TEMP_IMAGE='ci'
echo "platforms=$PLATFORMS" >> $GITHUB_OUTPUT
echo "ci-image-tag=$TEMP_IMAGE:image" >> $GITHUB_OUTPUT
echo "ci-test-image-tag=$TEMP_IMAGE:test-image" >> $GITHUB_OUTPUT
- name: Set up Docker
uses: docker/setup-docker-action@v5.0.0
with:
daemon-config: |
{ "features": { "containerd-snapshotter": true } }
- name: Set up QEMU
uses: docker/setup-qemu-action@v4.0.0
with:
platforms: ${{steps.info.outputs.platforms}}
- name: Build image
uses: docker/build-push-action@v7.0.0
with:
context: .
platforms: ${{steps.info.outputs.platforms}}
tags: ${{steps.info.outputs.ci-image-tag}}
cache-from: type=gha
cache-to: type=gha,mode=max
load: true
- name: Build test image
uses: docker/build-push-action@v7.0.0
with:
context: ./test
build-contexts: |
ci:image=docker-image://${{steps.info.outputs.ci-image-tag}}
platforms: ${{steps.info.outputs.platforms}}
tags: ${{steps.info.outputs.ci-test-image-tag}}
cache-from: type=gha
cache-to: type=gha,mode=max
load: true
- name: Run tests
run: >
for PLATFORM in ${PLATFORMS//,/ }; do
echo "::group::Run test ($PLATFORM)"
docker run --rm \
--platform "$PLATFORM" \
-e 'TZ=America/Toronto' \
-e 'PUID=9999' -e 'PGID=9999' -e 'SGID=10000,10001' \
"$TEST_IMAGE_TAG"
echo '::endgroup::'
done
env:
TEST_IMAGE_TAG: ${{steps.info.outputs.ci-test-image-tag}}
PLATFORMS: ${{steps.info.outputs.platforms}}
- name: Hide outdated build details comments
uses: int128/hide-comment-action@v1.54.0
with:
starts-with: <!-- build details -->
- name: Create build details comment
id: image-details
run: |
# Determine the remote image tag to compare against
echo "::group::Determine remote image tag"
VERSION=$(grep -E '^FROM ubuntu:[a-z]+-[0-9]+$' Dockerfile)
VERSION=${VERSION##*:}
STREAM=${VERSION%-*}
REMOTE_IMAGE_TAG=$REMOTE_IMAGE:$STREAM
echo "Local image: $LOCAL_IMAGE_TAG"
echo "Remote image: $REMOTE_IMAGE_TAG"
echo "Platforms: $PLATFORMS"
if ! docker buildx imagetools inspect \
$REMOTE_IMAGE_TAG > /dev/null 2>&1; then
echo "::warning::Tag '$STREAM' not found, falling back to 'latest'"
REMOTE_IMAGE_TAG=$REMOTE_IMAGE:latest
echo "Remote image: $REMOTE_IMAGE_TAG"
fi
echo "::endgroup::"
# Build the comment body per platform
BODY=$'<!-- build details -->\n\n'
HAVE_REMOTE=true
FAILED_PLATFORMS=()
TOTAL_SIZE_NEW=0
TOTAL_SIZE_OLD=0
PLATFORM_BODIES=""
FMT='--to=iec --suffix=B --format=%.2f'
for PLATFORM in ${PLATFORMS//,/ }; do
echo "::group::$PLATFORM"
PULL_FAILED=false
# Local image size
SIZE_NEW=$(docker image inspect --platform=$PLATFORM \
-f '{{.Size}}' $LOCAL_IMAGE_TAG)
echo "Local size: $SIZE_NEW ($(echo $SIZE_NEW | numfmt $FMT))"
# Layer breakdown
DETAILS=$(
docker image history --platform=$PLATFORM \
--format 'table | {{.Size}} | {{.CreatedBy}} |' $LOCAL_IMAGE_TAG
)
DETAILS=${DETAILS#*$'\n'}
echo "Layer breakdown:"
echo "$DETAILS"
# Remote image size
if docker pull --platform=$PLATFORM $REMOTE_IMAGE_TAG; then
SIZE_OLD=$(
docker image inspect --platform=$PLATFORM -f '{{.Size}}' \
$REMOTE_IMAGE_TAG
)
echo "Remote size: $SIZE_OLD ($(echo $SIZE_OLD | numfmt $FMT))"
else
HAVE_REMOTE=false
FAILED_PLATFORMS+=("$PLATFORM")
PULL_FAILED=true
SIZE_OLD=$SIZE_NEW
echo "::warning::Failed to pull remote image for $PLATFORM," \
"using local as baseline"
fi
# Format size with difference
SIZE=$(echo $SIZE_NEW | numfmt $FMT)
DIFF=$(( SIZE_NEW - SIZE_OLD ))
echo "Difference: $DIFF bytes"
if (( DIFF > 0 )); then
SIZE+=" \`+$(echo $DIFF | numfmt $FMT)\`"
elif (( DIFF < 0 )); then
SIZE+=" \`$(echo $DIFF | numfmt $FMT)\`"
fi
echo "Formatted size: $SIZE"
# Accumulate totals
TOTAL_SIZE_NEW=$((TOTAL_SIZE_NEW + SIZE_NEW))
TOTAL_SIZE_OLD=$((TOTAL_SIZE_OLD + SIZE_OLD))
# Determine status indicator
if (( DIFF > 0 )); then
STATUS=":red_square:"
elif (( DIFF < 0 )); then
STATUS=":yellow_square:"
else
STATUS=":green_square:"
fi
# Append to platform bodies
PLATFORM_BODIES+=$'<details>\n'
PLATFORM_BODIES+="<summary><code>$PLATFORM</code>"
PLATFORM_BODIES+=" $STATUS</summary><br/>"$'\n\n'
if [[ "$PULL_FAILED" == "true" ]]; then
PLATFORM_BODIES+=$'> [!NOTE]\n'
PLATFORM_BODIES+=$'> Remote image unavailable.'
PLATFORM_BODIES+=$' Size comparison skipped'
PLATFORM_BODIES+=$' for this platform.\n\n'
fi
PLATFORM_BODIES+="**Size:** $SIZE"$'\n'
PLATFORM_BODIES+=$'\n#### Layers\n\n'
PLATFORM_BODIES+=$'| Size | Created By |\n'
PLATFORM_BODIES+=$'| ---- | ---------- |\n'
PLATFORM_BODIES+="$DETAILS"
PLATFORM_BODIES+=$'\n\n</details>\n\n'
echo "::endgroup::"
done
# Overall size summary
OVERALL_SIZE=$(echo $TOTAL_SIZE_NEW | numfmt $FMT)
OVERALL_DIFF=$((TOTAL_SIZE_NEW - TOTAL_SIZE_OLD))
if (( OVERALL_DIFF > 0 )); then
OVERALL_SIZE+=" \`+$(echo $OVERALL_DIFF | numfmt $FMT)\`"
elif (( OVERALL_DIFF < 0 )); then
OVERALL_SIZE+=" \`$(echo $OVERALL_DIFF | numfmt $FMT)\`"
fi
BODY+=$'## Build Details\n\n'
if [[ "$HAVE_REMOTE" != "true" ]]; then
BODY+=$'> [!WARNING]\n'
BODY+=$'> Size comparison may be inaccurate.'
BODY+=$' Failed to pull remote image for the following platforms:\n'
for FP in "${FAILED_PLATFORMS[@]}"; do
BODY+="> * \`$FP\`"$'\n'
done
BODY+=$'\n'
fi
BODY+="**Size:** $OVERALL_SIZE"$'\n'
BODY+=$'\n### Platforms\n\n'
BODY+="$PLATFORM_BODIES"
echo "::group::Report final image details"
docker image ls --tree 2>/dev/null
echo "::endgroup::"
gh pr comment "$PULL_REQUEST_NUMBER" --body "$BODY"
env:
REMOTE_IMAGE: ghcr.io/${{github.repository_owner}}/base-ubuntu
LOCAL_IMAGE_TAG: ${{steps.info.outputs.ci-image-tag}}
PLATFORMS: ${{steps.info.outputs.platforms}}
PULL_REQUEST_NUMBER: ${{github.event.pull_request.number}}
GITHUB_TOKEN: ${{github.token}}
label:
name: Label
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
pull-requests: write
steps:
- name: Apply labels
uses: actions/labeler@v6.0.1