|
| 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-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 | + 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.changes.outputs.all_modified_files }} |
| 47 | + run: | |
| 48 | + cat >> "$GITHUB_STEP_SUMMARY" <<EOF |
| 49 | + ## Findings |
| 50 | + PR triggered? \`${{ steps.check-dockerfile.outputs.is-pr }}\` |
| 51 | + PR includes a build file related change? \`${{ steps.check-dockerfile.outputs.changed }}\` |
| 52 | + Should the image build be tested? \`${{ steps.check-dockerfile.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-${{ 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: "." |
0 commit comments