@@ -14,35 +14,41 @@ permissions:
1414
1515env :
1616 IMAGE_NAME : " test-prune-${{ github.run_number }}"
17- PACKAGES : |
18- ci-github-container/test-prune-${{ github.run_number }}
19- ${{ (github.event_name == 'workflow_dispatch' || github.event_name == 'push' && github.ref_name != github.event.repository.default_branch)
20- && ''
21- || format('ci-github-container/test-prune-{0}/cache', github.run_number)
22- }}
2317
2418jobs :
25- setup :
19+ arrange-prepare-variables :
20+ name : Arrange - Prepare variables
2621 runs-on : ubuntu-latest
2722 outputs :
28- tag : ${{ steps.generate-tag.outputs.tag }}
23+ tag : ${{ steps.prepare-variables.outputs.tag }}
24+ packages : ${{ steps.prepare-variables.outputs.packages }}
2925 steps :
30- - run : |
31- if [ -z "${{ secrets.GITHUB_TOKEN }}" ]; then
32- echo "GitHub token secrets is not set"
33- exit 1
34- fi
35-
36- - id : generate-tag
37- name : Generate random PR tag
38- run : |
39- # Generate a random tag to be deleted that cannot collide with an open PR tag
40- TAG="pr-$(( 1 + RANDOM % 210))"
41- echo "tag=$TAG" >> "$GITHUB_OUTPUT"
26+ - id : prepare-variables
27+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
28+ env :
29+ SECRETS_GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
30+ with :
31+ script : |
32+ if(!process.env.SECRETS_GITHUB_TOKEN) {
33+ return core.setFailed("GitHub token secrets is not set");
34+ }
4235
43- arrange :
36+ // Generate random PR tag
37+ core.setOutput("tag", `pr-${1 + Math.floor(Math.random() * 210)}`);
38+
39+ // Define expected packages
40+ const packages = [
41+ `ci-github-container/${process.env.IMAGE_NAME}`,
42+ ];
43+
44+ if (github.event_name === 'workflow_dispatch' || (github.event_name === 'push' && github.ref_name !== github.event.repository.default_branch)) {
45+ packages.push(`ci-github-container/${process.env.IMAGE_NAME}/cache`);
46+ }
47+ core.setOutput("packages", packages.join("\n"));
48+
49+ arrange-build-images :
4450 name : Arrange - Build images
45- needs : setup
51+ needs : arrange-prepare-variables
4652 uses : ./.github/workflows/docker-build-images.yml
4753 secrets :
4854 oci-registry-password : ${{ secrets.GITHUB_TOKEN }}
6369 arrange-verify :
6470 name : Arrange - Verify built images
6571 runs-on : ubuntu-latest
66- needs : arrange
72+ needs : [ arrange-prepare-variables, arrange-build-images]
6773 permissions :
6874 contents : read
6975 packages : read
7581 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
7682 env :
7783 IMAGE_NAME : ${{ env.IMAGE_NAME }}
78- BUILT_IMAGES : ${{ needs.arrange.outputs.built-images }}
84+ BUILT_IMAGES : ${{ needs.arrange-build-images.outputs.built-images }}
85+ PACKAGES : ${{ needs.arrange-prepare-variables.outputs.packages }}
7986 with :
8087 script : |
8188 const packages = process.env.PACKAGES.split("\n").map(packageName => packageName.trim()).filter(Boolean);
@@ -108,7 +115,7 @@ jobs:
108115 act :
109116 name : Act - Prune pull requests image tags
110117 runs-on : ubuntu-latest
111- needs : [setup , arrange, arrange-verify]
118+ needs : [arrange-prepare-variables , arrange-build-images , arrange-verify]
112119 permissions :
113120 packages : write
114121 steps :
@@ -124,8 +131,8 @@ jobs:
124131 env :
125132 BASE_IMAGE : ${{ needs.arrange-verify.outputs.base-image }}
126133 IMAGE_NAME : ${{ env.IMAGE_NAME }}
127- TAG_TO_DELETE : ${{ needs.setup .outputs.tag }}
128- BUILT_IMAGES : ${{ needs.arrange.outputs.built-images }}
134+ TAG_TO_DELETE : ${{ needs.arrange-prepare-variables .outputs.tag }}
135+ BUILT_IMAGES : ${{ needs.arrange-build-images .outputs.built-images }}
129136 run : |
130137 NEW_IMAGE="ghcr.io/hoverkraft-tech/ci-github-container/$IMAGE_NAME:$TAG_TO_DELETE"
131138
@@ -141,12 +148,13 @@ jobs:
141148 assert :
142149 name : Assert - Verify deleted image tags
143150 runs-on : ubuntu-latest
144- needs : [setup , arrange, act]
151+ needs : [arrange-prepare-variables , arrange-build-images , act]
145152 steps :
146153 - name : Assert - Ensure expected packages versions have been deleted
147154 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
148155 env :
149- TAG_TO_DELETE : ${{ needs.setup.outputs.tag }}
156+ TAG_TO_DELETE : ${{ needs.arrange-prepare-variables.outputs.tag }}
157+ PACKAGES : ${{ needs.arrange-prepare-variables.outputs.packages }}
150158 with :
151159 github-token : ${{ secrets.GITHUB_TOKEN }}
152160 script : |
@@ -189,7 +197,7 @@ jobs:
189197 env :
190198 IMAGE_NAME : ${{ env.IMAGE_NAME }}
191199 run : |
192- for IMAGE_TAG in $(echo '${{ needs.arrange.outputs.built-images }}' | jq -r '."${{ env.IMAGE_NAME }}".images[]'); do
200+ for IMAGE_TAG in $(echo '${{ needs.arrange-build-images .outputs.built-images }}' | jq -r '."${{ env.IMAGE_NAME }}".images[]'); do
193201 docker pull "$IMAGE_TAG"
194202
195203 if ! MANIFEST=$(docker manifest inspect "$IMAGE_TAG"); then
@@ -211,7 +219,7 @@ jobs:
211219 done
212220
213221 cleanup :
214- needs : assert
222+ needs : [arrange-prepare-variables, assert]
215223 runs-on : " ubuntu-latest"
216224 permissions :
217225 packages : write
@@ -221,6 +229,8 @@ jobs:
221229
222230 - name : Delete test packages
223231 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
232+ env :
233+ PACKAGES : ${{ needs.arrange-prepare-variables.outputs.packages }}
224234 with :
225235 github-token : ${{ secrets.GITHUB_TOKEN }}
226236 script : |
0 commit comments