|
| 1 | +name: CI (test image build for a PR with a Dockerfile change) |
| 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-dockerfile.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 | +
|
| 25 | + - name: Check if the `Dockerfile` has been changed in a PR |
| 26 | + id: check-dockerfile |
| 27 | + env: |
| 28 | + IS_PR: ${{ !!github.event.pull_request }} |
| 29 | + ANY_MODIFIED: ${{ steps.changed.outputs.any_modified }} |
| 30 | + run: | |
| 31 | + TEST_IMAGE_BUILD=$( |
| 32 | + if [[ $IS_PR == true ]] && [[ $ANY_MODIFIED == true ]]; then |
| 33 | + echo "true" |
| 34 | + else |
| 35 | + echo "false" |
| 36 | + fi |
| 37 | + ) |
| 38 | +
|
| 39 | + echo "is-pr=$IS_PR" >> "$GITHUB_OUTPUT" |
| 40 | + echo "changed=${ANY_MODIFIED:-false}" >> "$GITHUB_OUTPUT" |
| 41 | + echo "should-test=$TEST_IMAGE_BUILD" >> "$GITHUB_OUTPUT" |
| 42 | +
|
| 43 | + - name: Summarize findings |
| 44 | + run: | |
| 45 | + cat >> "$GITHUB_STEP_SUMMARY" <<EOF |
| 46 | + ## Findings |
| 47 | + PR triggered? \`${{ steps.check-dockerfile.outputs.is-pr }}\` |
| 48 | + PR includes a Dockerfile change? \`${{ steps.check-dockerfile.outputs.changed }}\` |
| 49 | + Should the image build be tested? \`${{ steps.check-dockerfile.outputs.should-test }}\` |
| 50 | + EOF |
| 51 | +
|
| 52 | + # |
| 53 | + # Based on: |
| 54 | + # - image-build.yaml |
| 55 | + # - konveyor/release-tools/.github/workflows/build-push-images.yaml@main |
| 56 | + # |
| 57 | + # Only test the image build, no push to quay is required. |
| 58 | + # |
| 59 | + test-image-build: |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: checks |
| 62 | + if: ${{ needs.checks.outputs.should-test == 'true' }} |
| 63 | + |
| 64 | + strategy: |
| 65 | + fail-fast: true |
| 66 | + matrix: |
| 67 | + architecture: |
| 68 | + - amd64 |
| 69 | + - arm64 |
| 70 | + |
| 71 | + steps: |
| 72 | + - name: Checkout merge commit for PR${{ github.event.pull_request.number }} |
| 73 | + uses: actions/checkout@v4 |
| 74 | + |
| 75 | + - name: Setup QEMU to be able to build on platform ${{ matrix.architecture }} |
| 76 | + if: ${{ matrix.architecture != 'amd64' }} |
| 77 | + uses: docker/setup-qemu-action@master |
| 78 | + with: |
| 79 | + platforms: ${{ matrix.architecture }} |
| 80 | + |
| 81 | + - name: Test build image on ${{ matrix.architecture }} |
| 82 | + id: test-build |
| 83 | + uses: redhat-actions/buildah-build@main |
| 84 | + with: |
| 85 | + image: "tackle2-ui" |
| 86 | + tags: pr${{ github.event.pull_request.number }}-${{ matrix.architecture }} |
| 87 | + extra-args: "--no-cache --rm --ulimit nofile=4096:4096" |
| 88 | + archs: ${{ matrix.architecture }} |
| 89 | + labels: "" |
| 90 | + containerfiles: "./Dockerfile" |
| 91 | + context: "." |
0 commit comments