Skip to content

Commit fcf09a7

Browse files
committed
Move logic for determining if builder should rebuild to steps
1 parent 7170a09 commit fcf09a7

File tree

1 file changed

+60
-25
lines changed

1 file changed

+60
-25
lines changed

.github/workflows/collector-builder.yml

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
name: Determine if builder image needs to be built
2424
runs-on: ubuntu-24.04
2525
outputs:
26-
build-image: ${{ steps.changed.outputs.builder-changed }}
26+
build-image: ${{ steps.check-builder.outputs.build-image }}
27+
build-multiarch: ${{ steps.build-multiarch.outputs.build-multiarch }}
2728
collector-builder-tag: ${{ steps.builder-tag.outputs.collector-builder-tag }}
2829

2930
steps:
@@ -52,20 +53,68 @@ jobs:
5253
echo "COLLECTOR_BUILDER_TAG=${COLLECTOR_BUILDER_TAG}" >> "$GITHUB_ENV"
5354
echo "collector-builder-tag=${COLLECTOR_BUILDER_TAG}" >> "$GITHUB_OUTPUT"
5455
56+
- name: Check if the builder image should be built
57+
id: check-builder
58+
run: |
59+
function build_builder() {
60+
echo "build-image=$1" >> "$GITHUB_OUTPUT"
61+
exit 0
62+
}
63+
64+
if [[ "${{ steps.changed.outputs.builder-changed }}" == "true" ]]; then
65+
build_builder "true"
66+
fi
67+
68+
if [[ "${GITHUB_EVENT_NAME}" == "schedule" ]]; then
69+
build_builder "true"
70+
fi
71+
72+
if [[ "${GITHUB_EVENT_NAME}" == "push" ]]; then
73+
if [[ "${GITHUB_REF_TYPE}" == "tag" || "${GITHUB_REF_NAME}" == release-* ]]; then
74+
build_builder "true"
75+
fi
76+
77+
build_builder "false"
78+
fi
79+
80+
# If we got here, we are on a PR event
81+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'build-builder-image') }}" == "true" ]]; then
82+
build_builder "true"
83+
fi
84+
85+
build_builder "false"
86+
87+
- name: Specify if multiarch image should be built
88+
id: build-multiarch
89+
run: |
90+
function run_multiarch() {
91+
echo "build-multiarch=$1" >> "$GITHUB_OUTPUT"
92+
exit 0
93+
}
94+
95+
if [[ "${{ steps.check-builder.outputs.build-image }}" == "false" ]]; then
96+
run_multiarch "false"
97+
fi
98+
99+
if [[ "${GITHUB_EVENT_NAME}" == "pull_request" ]]; then
100+
# PRs only run multiarch on demand
101+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds') }}" == "true" ]]; then
102+
run_multiarch "true"
103+
fi
104+
run_multiarch "false"
105+
fi
106+
107+
# Events that are not on PRs always run multiarch
108+
run_multiarch "true"
109+
55110
build-builder-image:
56111
name: Build the builder image
57112
runs-on: ubuntu-24.04
58113
# Multiarch builds sometimes take for eeeeeeeeeever
59114
timeout-minutes: 480
60115
needs:
61116
- builder-needs-rebuilding
62-
if: |
63-
needs.builder-needs-rebuilding.outputs.build-image == 'true' ||
64-
(github.event_name == 'push' && (
65-
github.ref_type == 'tag' || startsWith(github.ref_name, 'release-')
66-
)) ||
67-
contains(github.event.pull_request.labels.*.name, 'build-builder-image') ||
68-
github.event_name == 'schedule'
117+
if: needs.builder-needs-rebuilding.outputs.build-image == 'true'
69118
strategy:
70119
fail-fast: false
71120
matrix:
@@ -118,14 +167,7 @@ jobs:
118167
timeout-minutes: 480
119168
needs:
120169
- builder-needs-rebuilding
121-
if: |
122-
needs.builder-needs-rebuilding.outputs.build-image == 'true' || (
123-
github.event_name == 'push' && (
124-
github.ref_type == 'tag' || startsWith(github.ref_name, 'release-')
125-
)) || (
126-
contains(github.event.pull_request.labels.*.name, 'build-builder-image') &&
127-
contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds')
128-
) || github.event_name == 'schedule'
170+
if: needs.builder-needs-rebuilding.outputs.build-multiarch == 'true'
129171
strategy:
130172
fail-fast: false
131173
matrix:
@@ -206,11 +248,7 @@ jobs:
206248
- build-builder-image-remote-vm
207249
name: Create Multiarch manifest
208250
runs-on: ubuntu-24.04
209-
if: |
210-
github.event_name != 'pull_request' || (
211-
needs.builder-needs-rebuilding.outputs.collector-builder-tag != 'master' &&
212-
contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds')
213-
)
251+
if : needs.builder-needs-rebuilding.outputs.build-multiarch == 'true'
214252
env:
215253
COLLECTOR_BUILDER_TAG: ${{ needs.builder-needs-rebuilding.outputs.collector-builder-tag }}
216254
ARCHS: amd64 ppc64le s390x arm64
@@ -250,10 +288,7 @@ jobs:
250288
- build-builder-image
251289
name: Retag x86 builder image
252290
runs-on: ubuntu-24.04
253-
if: |
254-
github.event_name == 'pull_request' &&
255-
needs.builder-needs-rebuilding.outputs.collector-builder-tag != 'master' &&
256-
!contains(github.event.pull_request.labels.*.name, 'run-multiarch-builds')
291+
if : needs.builder-needs-rebuilding.outputs.build-multiarch == 'false'
257292
env:
258293
COLLECTOR_BUILDER_TAG: ${{ needs.builder-needs-rebuilding.outputs.collector-builder-tag }}
259294
steps:

0 commit comments

Comments
 (0)