Skip to content

Commit 7265949

Browse files
jiridanekopenshift-merge-bot[bot]
authored andcommitted
RHOAIENG-16076: tests(gha): use the same registry, tag, and output image name in all branches
1 parent f3c4028 commit 7265949

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

.github/workflows/build-notebooks-TEMPLATE.yaml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ jobs:
2020
build:
2121
runs-on: ubuntu-22.04
2222
env:
23+
# We don't push here when building PRs, so we can use the same IMAGE_REGISTRY in all branches of the workflow
24+
IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images"
2325
# GitHub image registry used for storing $(CONTAINER_ENGINE)'s cache
2426
CACHE: "ghcr.io/${{ github.repository }}/workbench-images/build-cache"
2527
TRIVY_VERSION: 0.57.1
@@ -115,6 +117,15 @@ jobs:
115117
systemctl --user start homebrew.podman.service
116118
echo "PODMAN_SOCK=/run/user/${UID}/podman/podman.sock" >> $GITHUB_ENV
117119
120+
- name: Calculate image name and tag
121+
id: calculated_vars
122+
run: |
123+
SANITIZED_REF_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/_/g')
124+
IMAGE_TAG="${SANITIZED_REF_NAME}_${{ github.sha }}"
125+
126+
echo "IMAGE_TAG=${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
127+
echo "OUTPUT_IMAGE=${{ env.IMAGE_REGISTRY}}:${{ inputs.target }}-${IMAGE_TAG}" >> "$GITHUB_OUTPUT"
128+
118129
- name: "pull_request|schedule: resolve target if Trivy scan should run"
119130
id: resolve-target
120131
if: ${{ fromJson(inputs.github).event_name == 'pull_request' || fromJson(inputs.github).event_name == 'schedule' }}
@@ -128,15 +139,15 @@ jobs:
128139
TARGET="$FS_SCAN_FOLDER"
129140
TYPE="fs"
130141
else
131-
TARGET="ghcr.io/${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.sha }}"
142+
TARGET="${{ steps.calculated_vars.outputs.OUTPUT_IMAGE }}"
132143
TYPE="image"
133144
fi
134145
elif [[ "$EVENT_NAME" == "schedule" ]]; then
135146
if [[ -n "$FS_SCAN_FOLDER" ]]; then
136147
TARGET="$FS_SCAN_FOLDER"
137148
TYPE="fs"
138149
else
139-
TARGET="ghcr.io/${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.ref_name }}_${{ github.sha }}"
150+
TARGET="${{ steps.calculated_vars.outputs.OUTPUT_IMAGE }}"
140151
TYPE="image"
141152
fi
142153
fi
@@ -172,12 +183,10 @@ jobs:
172183
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
173184
- name: "push|schedule: make ${{ inputs.target }}"
174185
run: |
175-
SANITIZED_REF_NAME=$(echo "${{ github.ref_name }}" | sed 's/[^a-zA-Z0-9._-]/_/g')
176-
export IMAGE_TAG="${SANITIZED_REF_NAME}_${{ github.sha }}"
177186
make ${{ inputs.target }}
178187
if: ${{ fromJson(inputs.github).event_name == 'push' || fromJson(inputs.github).event_name == 'schedule' }}
179188
env:
180-
IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images"
189+
IMAGE_TAG: "${{ steps.calculated_vars.outputs.IMAGE_TAG }}"
181190
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
182191
# dependent images were already built and pushed, so just let podman pull it
183192
BUILD_DEPENDENT_IMAGES: "no"
@@ -188,8 +197,7 @@ jobs:
188197
make ${{ inputs.target }}
189198
if: "${{ fromJson(inputs.github).event_name == 'pull_request' }}"
190199
env:
191-
IMAGE_TAG: "${{ github.sha }}"
192-
IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images"
200+
IMAGE_TAG: "${{ steps.calculated_vars.outputs.IMAGE_TAG }}"
193201
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }}"
194202
# We don't have access to image registry, so disable pushing
195203
PUSH_IMAGES: "no"
@@ -275,7 +283,7 @@ jobs:
275283
EOF
276284
working-directory: tests/browser
277285
env:
278-
TEST_TARGET: "ghcr.io/${{ github.repository }}/workbench-images:${{ inputs.target }}-${{ github.sha }}"
286+
TEST_TARGET: "${{ steps.calculated_vars.outputs.OUTPUT_IMAGE }}"
279287
- uses: actions/upload-artifact@v4
280288
if: ${{ !cancelled() && fromJson(inputs.github).event_name == 'pull_request' && contains(inputs.target, 'codeserver') }}
281289
with:

0 commit comments

Comments
 (0)