|
1 | 1 | name: Build image(s) on PR |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + push: |
5 | 5 | paths: |
6 | 6 | - ci/images/Dockerfile.* |
7 | 7 |
|
8 | 8 | permissions: {} |
9 | 9 |
|
10 | 10 | jobs: |
| 11 | + detect-changes: |
| 12 | + if: github.repository == 'CycloneDX/cdxgen' |
| 13 | + runs-on: ubuntu-24.04 |
| 14 | + outputs: |
| 15 | + imagefiles: ${{ steps.changed.outputs.files }} |
| 16 | + steps: |
| 17 | + - name: Get changed files |
| 18 | + id: changed |
| 19 | + uses: actions/github-script@v7 |
| 20 | + with: |
| 21 | + script: | |
| 22 | + const response = await github.rest.repos.compareCommits({ |
| 23 | + owner: context.repo.owner, |
| 24 | + repo: context.repo.repo, |
| 25 | + base: context.payload.before, |
| 26 | + head: context.payload.after |
| 27 | + }); |
| 28 | + const files = response.data.files |
| 29 | + .map(f => f.filename) |
| 30 | + .filter(f => f.includes("Dockerfile")); |
| 31 | + core.setOutput("files", JSON.stringify(files)); |
11 | 32 | image: |
12 | 33 | if: github.repository == 'CycloneDX/cdxgen' |
| 34 | + needs: detect-changes |
13 | 35 | strategy: |
14 | 36 | fail-fast: false |
15 | 37 | matrix: |
16 | | - imagefile: ${{ github.event.head_commit.modified }} |
17 | | - runner: [ubuntu-24.04, ubuntu-24.04-arm] |
| 38 | + imagefile: ${{ fromJson(needs.detect-changes.outputs.imagefiles) }} |
| 39 | + runner: [ ubuntu-24.04, ubuntu-24.04-arm ] |
18 | 40 | include: |
19 | 41 | - runner: ubuntu-24.04 |
20 | 42 | platform: linux/amd64 |
21 | 43 | - runner: ubuntu-24.04-arm |
22 | 44 | platform: linux/arm64 |
23 | 45 | runs-on: ${{ matrix.runner }} |
24 | 46 | steps: |
| 47 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 48 | + with: |
| 49 | + persist-credentials: false |
25 | 50 | - name: Build image |
26 | | - if: ${{ contains(matrix.imagefile, 'Dockerfile') }} |
27 | 51 | uses: ./.github/actions/build-docker-image |
28 | 52 | with: |
29 | 53 | dockerfile: ${{ matrix.imagefile }} |
|
0 commit comments