Skip to content

Commit 441d0b9

Browse files
committed
🌱 [backport release-0.3] Test image build when build related files change (konveyor#1907)
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 reveal 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 Backport-of: konveyor#1907 Note: build architectures updated to match the settings on the backport target branch Signed-off-by: Scott J Dickerson <[email protected]>
1 parent 61dae23 commit 441d0b9

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

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

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 [[ -n "$MODIFIED_FILES" ]]; 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+
- "ppc64le"
81+
- "s390x"
82+
83+
concurrency:
84+
group: test-image-build-${{ matrix.architecture }}_${{ github.ref }}
85+
cancel-in-progress: true
86+
87+
steps:
88+
- name: Checkout merge commit for PR${{ github.event.pull_request.number }}
89+
uses: actions/checkout@v4
90+
91+
- name: Setup QEMU to be able to build on ${{ matrix.architecture }}
92+
if: ${{ matrix.architecture != 'amd64' }}
93+
uses: docker/setup-qemu-action@master
94+
with:
95+
platforms: ${{ matrix.architecture }}
96+
97+
- name: Test build image on ${{ matrix.architecture }}
98+
id: test-build
99+
uses: redhat-actions/buildah-build@main
100+
with:
101+
image: "tackle2-ui"
102+
tags: pr${{ github.event.pull_request.number }}-${{ matrix.architecture }}
103+
extra-args: "--no-cache --rm --ulimit nofile=4096:4096"
104+
archs: ${{ matrix.architecture }}
105+
labels: ""
106+
containerfiles: "./Dockerfile"
107+
context: "."

0 commit comments

Comments
 (0)