@@ -102,23 +102,40 @@ jobs:
102102
103103 const builds = process.env.BUILDS ? process.env.BUILDS.split(',') : Object.keys(config.build);
104104 const push_to = process.env.PUSH_TO ? process.env.PUSH_TO.split(',') : Object.keys(config.push || {});
105+ const skip_push = process.env.SKIP_PUSH === 'true';
105106
106107 const flavors = builds.map(id => [id, config.build[id]]).filter(([id, flavor]) => flavor.skip !== true).map(([id, flavor]) => {
108+ const hooksDirectory = path.join('./deploy/build', flavor.directory, 'hooks');
109+ const testImagesHookScript = path.join(hooksDirectory, 'test-images.sh');
110+ const testImagesHookReport = path.join(hooksDirectory, 'test-images-report');
111+ const testImageEnabled = fs.existsSync(testImagesHookScript);
112+
107113 return {
108114 ...flavor,
109115 id,
116+ // We can skip the push only if we don't want to test the image below
117+ skip_push: skip_push && !testImageEnabled,
118+ skip_retag: skip_push,
110119 // Add metadata to the flavor object (will be used as matrix input)
111120 build_time: buildTime,
112121 image_tag: imageTag,
113122 image_tag_branch_name: imageTagBranchName,
114123 ecr_respositories: flavor.components.map(component => component.ecr_repository),
124+ test_images: {
125+ enabled: testImageEnabled,
126+ script_path: testImagesHookScript,
127+ report_path: testImagesHookReport,
128+ },
115129 components: flavor.components.map(component => {
116130 // Format build arguments as build-args string
117131 const formattedBuildArgs = component.build_args ?
118132 Object.entries(component.build_args).map(([key, value]) => `${key}=${value}`).join('\n') : '';
119133
120134 return {
121135 ...component,
136+ // We can skip the push only if we don't want to test the image below
137+ skip_push: skip_push && !testImageEnabled,
138+ skip_retag: skip_push,
122139 // Add metadata to the component object (will be used as matrix input),
123140 flavor,
124141 flavor_id: id,
@@ -143,6 +160,7 @@ jobs:
143160 console.log(result);
144161 return result;
145162 env :
163+ SKIP_PUSH : ${{ inputs.skip_push }}
146164 BUILDS : ${{ inputs.builds }}
147165 PUSH_TO : ${{ inputs.push_to }}
148166
@@ -282,6 +300,7 @@ jobs:
282300 continue-on-error : false
283301
284302 - name : Push image
303+ if : ${{ matrix.component.skip_push != true }}
285304 # Instead of the docker/build-push-action@v6 which will rebuild the image, just push it directly
286305 run : docker push ${{ matrix.component.image_ref }}
287306
@@ -292,6 +311,7 @@ jobs:
292311 test-images :
293312 name : Test images of flavor ${{ matrix.flavor.id || 'default' }}
294313 needs : [get-flavors, build-flavors]
314+ if : ${{ matrix.flavor.test_images.enabled == true }}
295315 strategy :
296316 fail-fast : false
297317 matrix :
@@ -304,13 +324,6 @@ jobs:
304324 ref : ${{ inputs.branch || github.sha }}
305325 token : ${{ secrets.CHECKOUT_TOKEN || github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }}
306326
307- - name : Checkout github-workflows repository
308- uses : actions/checkout@v5
309- with :
310- repository : datavisyn/github-workflows
311- ref : ${{ env.WORKFLOW_BRANCH }}
312- path : ./tmp/github-workflows
313-
314327 - name : Configure AWS Credentials
315328 uses :
aws-actions/[email protected] 316329 with :
@@ -325,9 +338,8 @@ jobs:
325338 shell : bash
326339 id : test-images
327340 run : |
328- hooks_folder="$(realpath -m "./deploy/build/${{ matrix.flavor.directory }}/hooks")"
329- test_images_hook="$hooks_folder/test-images.sh"
330- test_images_report="$hooks_folder/test-images-report"
341+ test_images_hook=$(jq -r '.test_images.script_path' <<< "$FLAVOR")
342+ test_images_report=$(jq -r '.test_images.report_path' <<< "$FLAVOR")
331343
332344 if [[ -f "$test_images_hook" ]]; then
333345 # Iterate through all components and store their image ref in an environment variable
@@ -369,7 +381,8 @@ jobs:
369381 retag-images :
370382 name : Retag images of flavor ${{ matrix.flavor.id || 'default' }}
371383 needs : [get-flavors, test-images]
372- if : ${{ inputs.skip_push != true }}
384+ # As test-images may be skipped, we need this if to ensure this job runs: https://github.com/actions/runner/issues/491#issuecomment-1507495166
385+ if : ${{ always() && !cancelled() && !failure() && matrix.flavor.skip_retag != true }}
373386 strategy :
374387 fail-fast : false
375388 matrix :
@@ -429,7 +442,7 @@ jobs:
429442 push-to-repositories :
430443 name : Push images to push targets
431444 # if? When should we do this? Always? Only for certain branches? If so, how should we define that, in the config.json?
432- if : ${{ inputs.skip_push != true && fromJson(needs.get-flavors.outputs.result).push_to != '' }}
445+ if : ${{ fromJson(needs.get-flavors.outputs.result).push_to != '' }}
433446 needs : [retag-images, get-flavors]
434447 uses : datavisyn/github-workflows/.github/workflows/build-docker-artifacts-trigger-push.yml@main
435448 secrets : inherit
0 commit comments