Skip to content

Commit f87ad0b

Browse files
committed
Added a workflow that runs when a Dockerfile has changed in a PR or push
Signed-off-by: Roland Asmann <[email protected]>
1 parent 3fae7bd commit f87ad0b

File tree

4 files changed

+72
-6
lines changed

4 files changed

+72
-6
lines changed

.github/actions/build-docker-image/action.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@ inputs:
1313
description: Labels to add to the image
1414
output:
1515
description: Controls what should be done with the image(s) after building
16-
required: true
1716
platforms:
1817
description: The platforms for which to build the image
1918
required: true
2019
tags:
2120
description: All tags for the image
22-
required: true
2321
target:
2422
description: Which stage in the Dockerfile to build
2523
required: true
@@ -35,8 +33,7 @@ runs:
3533
context: .
3634
file: ${{ inputs.dockerfile }}
3735
labels: ${{ inputs.labels }}
38-
outputs: type=${{ inputs.output }}
36+
outputs: ${{ inputs.output }}
3937
platforms: ${{ inputs.platforms }}
40-
push: ${{ inputs.action == 'push' }}
4138
tags: ${{ inputs.tags }}
4239
target: ${{ inputs.target }}

.github/actions/build-docker-images-generate-attach-sboms/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ runs:
5555
dockerfile: ${{ inputs.dockerfile }}
5656
docker-args: ${{ inputs.docker-args }}
5757
labels: ${{ steps.metadata.outputs.labels }}
58-
output: registry
58+
output: type=registry
5959
platforms: linux/amd64${{ inputs.build-arm == 'true' && ',linux/arm64' || '' }}
6060
tags: ${{ inputs.tags || steps.metadata.outputs.tags }}
6161
target: ${{ inputs.target }}

.github/actions/generate-attach-sbom/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ runs:
3030
with:
3131
dockerfile: ${{ inputs.dockerfile }}
3232
docker-args: ${{ inputs.docker-args }}
33-
output: docker,dest=${{ runner.temp }}/image.tar
33+
output: type=docker,dest=${{ runner.temp }}/image.tar
3434
platforms: ${{ inputs.platform }}
3535
tags: ${{ inputs.tag }}
3636
target: ${{ inputs.target }}

.github/workflows/build-image.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build image(s) on PR/push
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ci/images/**/Dockerfile.*
7+
push:
8+
paths:
9+
- ci/images/**/Dockerfile.*
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
13+
cancel-in-progress: true
14+
15+
permissions: {}
16+
17+
jobs:
18+
filter:
19+
if: github.repository == 'CycloneDX/cdxgen'
20+
runs-on: ubuntu-24.04
21+
outputs:
22+
imagefiles: ${{ steps.changed.outputs.files }}
23+
steps:
24+
- name: Get changed files
25+
id: changed
26+
uses: actions/github-script@v7
27+
with:
28+
script: |
29+
const response = await github.rest.repos.compareCommits({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
base: context.payload.before,
33+
head: context.payload.after
34+
});
35+
const files = response.data.files
36+
.map(f => f.filename)
37+
.filter(f => f.includes("Dockerfile"));
38+
core.setOutput("files", JSON.stringify(files));
39+
image:
40+
if: github.repository == 'CycloneDX/cdxgen'
41+
needs: filter
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
imagefile: ${{ fromJson(needs.filter.outputs.imagefiles) }}
46+
platform: [ amd64, arm64 ]
47+
# Some images don't work on linux/arm64
48+
exclude:
49+
- imagefile: ci/images/Dockerfile.dotnet7
50+
platform: arm64
51+
- imagefile: ci/images/Dockerfile.dotnet8
52+
platform: arm64
53+
- imagefile: ci/images/Dockerfile.dotnet9
54+
platform: arm64
55+
- imagefile: ci/images/Dockerfile.ruby25
56+
platform: arm64
57+
- imagefile: ci/images/debian/Dockerfile.ruby26
58+
platform: arm64
59+
runs-on: ${{ matrix.platform == 'amd64' && 'ubuntu-24.04' || 'ubuntu-24.04-arm' }}
60+
steps:
61+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
62+
with:
63+
persist-credentials: false
64+
- name: Build image
65+
uses: ./.github/actions/build-docker-image
66+
with:
67+
dockerfile: ${{ matrix.imagefile }}
68+
platforms: ${{ matrix.platform }}
69+
target: cdxgen

0 commit comments

Comments
 (0)