Skip to content

Commit a31c0f2

Browse files
committed
✨ Test image build when build related files change
If the workflow is run from a PR, and the PR includes a change to the `Dockerfile` or `package-lock.json`, then run image builds for all of our target platforms. The images are built but not pushed to any repository. We want to be reasonably sure that any major build file changes will not cause the image-build-and-push on PR merge workflow to break. Doing the image build here should show up most problems much earlier. For example, a npm version update in the build container could break github action `nofiles` or network access capabilities for the npm install. See konveyor#1742, konveyor#1746, and konveyor#1781 for some other examples of when this check could have caught issues before a PR merge. Supports: konveyor#1883 Signed-off-by: Scott J Dickerson <[email protected]>
1 parent 4f4ed7b commit a31c0f2

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

.github/workflows/ci-image-build.yml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: CI (test image build for a PR with build related changes)
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- "main"
7+
- "release-*"
8+
9+
jobs:
10+
checks:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
should-test: ${{ steps.check-changes.outputs.should-test }}
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: What files changed?
19+
id: changed
20+
uses: tj-actions/changed-files@v44
21+
with:
22+
files: |
23+
Dockerfile
24+
package-lock.json
25+
26+
- name: Check if build related files have been changed in a PR
27+
id: check-changes
28+
env:
29+
IS_PR: ${{ !!github.event.pull_request }}
30+
ANY_MODIFIED: ${{ steps.changed.outputs.any_modified }}
31+
run: |
32+
TEST_IMAGE_BUILD=$(
33+
if [[ $IS_PR == true ]] && [[ $ANY_MODIFIED == true ]]; then
34+
echo "true"
35+
else
36+
echo "false"
37+
fi
38+
)
39+
40+
echo "is-pr=$IS_PR" >> "$GITHUB_OUTPUT"
41+
echo "changed=${ANY_MODIFIED:-false}" >> "$GITHUB_OUTPUT"
42+
echo "should-test=$TEST_IMAGE_BUILD" >> "$GITHUB_OUTPUT"
43+
44+
- name: Summarize findings
45+
env:
46+
MODIFIED_FILES: ${{ steps.changed.outputs.all_modified_files }}
47+
run: |
48+
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
49+
## Findings
50+
PR triggered? \`${{ steps.check-changes.outputs.is-pr }}\`
51+
PR includes a build file related change? \`${{ steps.check-changes.outputs.changed }}\`
52+
Should the image build be tested? \`${{ steps.check-changes.outputs.should-test }}\`
53+
EOF
54+
55+
if [[ "${MODIFIED_FILES}" -ne "" ]]; then
56+
echo "## Build related modified files" >> "$GITHUB_STEP_SUMMARY"
57+
for file in ${MODIFIED_FILES}; do
58+
echo " - \`$file\`" >> "$GITHUB_STEP_SUMMARY"
59+
done
60+
fi
61+
62+
#
63+
# Based on:
64+
# - image-build.yaml
65+
# - konveyor/release-tools/.github/workflows/build-push-images.yaml@main
66+
#
67+
# Only test the image build, no push to quay is required.
68+
#
69+
test-image-build:
70+
runs-on: ubuntu-latest
71+
needs: checks
72+
if: ${{ needs.checks.outputs.should-test == 'true' }}
73+
74+
strategy:
75+
fail-fast: true
76+
matrix:
77+
architecture: # keep this list in sync with `image-build.yaml`
78+
- amd64
79+
- arm64
80+
81+
concurrency:
82+
group: test-image-build-${{ matrix.architecture }}_${{ github.ref }}
83+
cancel-in-progress: true
84+
85+
steps:
86+
- name: Checkout merge commit for PR${{ github.event.pull_request.number }}
87+
uses: actions/checkout@v4
88+
89+
- name: Setup QEMU to be able to build on ${{ matrix.architecture }}
90+
if: ${{ matrix.architecture != 'amd64' }}
91+
uses: docker/setup-qemu-action@master
92+
with:
93+
platforms: ${{ matrix.architecture }}
94+
95+
- name: Test build image on ${{ matrix.architecture }}
96+
id: test-build
97+
uses: redhat-actions/buildah-build@main
98+
with:
99+
image: "tackle2-ui"
100+
tags: pr${{ github.event.pull_request.number }}-${{ matrix.architecture }}
101+
extra-args: "--no-cache --rm --ulimit nofile=4096:4096"
102+
archs: ${{ matrix.architecture }}
103+
labels: ""
104+
containerfiles: "./Dockerfile"
105+
context: "."

.github/workflows/ci-repo.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ on:
1717
workflow_dispatch:
1818

1919
jobs:
20-
unit-test-lookup-image:
20+
unit-test-lookups:
2121
runs-on: ubuntu-latest
2222
outputs:
2323
builder-image: ${{ steps.grepBuilder.outputs.builder }}
24+
2425
steps:
2526
- uses: actions/checkout@v4
2627

@@ -33,10 +34,10 @@ jobs:
3334
3435
unit-test:
3536
runs-on: ubuntu-latest
36-
needs: unit-test-lookup-image
37+
needs: unit-test-lookups
3738

3839
# Use the same container as the Dockerfile's "FROM * as builder"
39-
container: ${{ needs.unit-test-lookup-image.outputs.builder-image }}
40+
container: ${{ needs.unit-test-lookups.outputs.builder-image }}
4041

4142
steps:
4243
- uses: actions/checkout@v4

.github/workflows/image-build.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ jobs:
2020
registry: "quay.io/sdickers"
2121
image_name: "tackle2-ui"
2222
containerfile: "./Dockerfile"
23+
24+
# keep the architectures in sync with `ci-image-build.yml`
2325
architectures: '[ "amd64", "arm64" ]'
26+
2427
# 2023-03-19: currently needed for npm@10
2528
extra-args: "--ulimit nofile=4096:4096"
29+
2630
secrets:
2731
registry_username: ${{ secrets.QUAY_PUBLISH_ROBOT }}
2832
registry_password: ${{ secrets.QUAY_PUBLISH_TOKEN }}

0 commit comments

Comments
 (0)