Skip to content

Commit

Permalink
✨ Test image build on Dockerfile change
Browse files Browse the repository at this point in the history
Signed-off-by: Scott J Dickerson <[email protected]>
  • Loading branch information
sjd78 committed May 10, 2024
1 parent 4884439 commit 411cf9f
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 3 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/ci-Dockerfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: CI (test image build for a PR with a Dockerfile change)

on:
pull_request:
branches:
- "main"
- "release-*"

jobs:
checks:
runs-on: ubuntu-latest
outputs:
should_test: ${{ steps.check-dockerfile.outputs.should-test == 'true' }}

steps:
- uses: actions/checkout@v4

- name: What files changed?
id: changed
uses: tj-actions/changed-files@v44
with:
files: |
Dockerfile
- name: Check if the `Dockerfile` has been changed in a PR
id: check-dockerfile
env:
IS_PR: ${{ !!github.event.pull_request }}
ANY_MODIFIED: ${{ steps.changed.outputs.any_modified }}
run: |
TEST_IMAGE_BUILD=$(
if [[ $IS_PR == true ]] && [[ $ANY_MODIFIED == true ]]; then
echo "true"
else
echo "false"
fi
)
echo "is-pr=$IS_PR" >> "$GITHUB_OUTPUT"
echo "changed=${ANY_MODIFIED:-false}" >> "$GITHUB_OUTPUT"
echo "should-test=$TEST_IMAGE_BUILD" >> "$GITHUB_OUTPUT"
- name: Summarize findings
env:
CHANGED_OUTPUT: ${{ toJson(steps.changed.outputs) }}
run: |
cat >> "$GITHUB_STEP_SUMMARY" <<EOF
## changed-files action output:
\`\`\`json
$(echo "$CHANGED_OUTPUT" | jq --sort-keys '.')
\`\`\`
PR triggered? \`${{ steps.check-dockerfile.outputs.is-pr }}\`
PR includes a Dockerfile change? \`${{ steps.check-dockerfile.outputs.changed }}\`
Should the image build be tested? \`${{ steps.check-dockerfile.outputs.should-test }}\`
EOF
#
# Based on:
# - image-build.yaml
# - konveyor/release-tools/.github/workflows/build-push-images.yaml@main
#
# Only test the image build, no push to quay is required.
#
test-image-build:
runs-on: ubuntu-latest
needs: checks
if: ${{ needs.checks.outputs.should-test }}

strategy:
fail-fast: true
matrix:
architecture:
- amd64
- arm64

steps:
- name: Checkout merge commit for PR${{ github.event.pull_request.number }}
uses: actions/checkout@v4

- name: Test build image on ${{ matrix.architecture }}
id: test-build
uses: redhat-actions/buildah-build@main
with:
image: "tackle2-ui"
tags: PR${{ github.event.pull_request.number }}-${{ matrix.architecture }}
extra-args: "--no-cache --rm --ulimit nofile=4096:4096"
archs: ${{ matrix.architecture }}
labels: ""
containerfiles: "./Dockerfile"
context: "."
7 changes: 4 additions & 3 deletions .github/workflows/ci-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ on:
workflow_dispatch:

jobs:
unit-test-lookup-image:
unit-test-lookups:
runs-on: ubuntu-latest
outputs:
builder-image: ${{ steps.grepBuilder.outputs.builder }}

steps:
- uses: actions/checkout@v4

Expand All @@ -33,10 +34,10 @@ jobs:
unit-test:
runs-on: ubuntu-latest
needs: unit-test-lookup-image
needs: unit-test-lookups

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

steps:
- uses: actions/checkout@v4
Expand Down

0 comments on commit 411cf9f

Please sign in to comment.