Skip to content

Commit 569e37d

Browse files
committed
chore: remove use of extrapolation in scripts
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent bcbbcaf commit 569e37d

14 files changed

+131
-59
lines changed

.github/workflows/__test-action-docker-build-image.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ jobs:
4242

4343
- name: Assert - Check built image output
4444
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
45+
env:
46+
BUILT_IMAGE_OUTPUT: ${{ steps.build-image.outputs.built-image }}
4547
with:
4648
script: |
4749
const assert = require("assert");
50+
const pullRequestNumber = context.payload.pull_request?.number;
51+
const refName = process.env.GITHUB_REF_NAME;
52+
const defaultBranch = context.payload.repository?.default_branch;
4853
49-
const builtImageOutput = ${{ toJSON(steps.build-image.outputs.built-image) }};
54+
const builtImageOutput = process.env.BUILT_IMAGE_OUTPUT;
5055
assert(builtImageOutput, `"built-image" output is empty`);
5156
5257
let builtImage;
@@ -111,20 +116,20 @@ jobs:
111116
112117
const expectedTags = [];
113118
let expectedImageVersion;
114-
if (`${{ github.event_name }}` === "pull_request") {
115-
const shortSha = `${{ github.sha }}`.substring(0, 7);
116-
const prShaTag = `pr-${{ github.event.pull_request.number }}-${shortSha}`;
117-
const prTag = `pr-${{ github.event.pull_request.number }}`;
119+
if (context.eventName === "pull_request") {
120+
const shortSha = context.sha.substring(0, 7);
121+
const prShaTag = `pr-${pullRequestNumber}-${shortSha}`;
122+
const prTag = `pr-${pullRequestNumber}`;
118123
119124
expectedTags.push(prShaTag, prTag);
120125
expectedImageVersion = prTag;
121126
} else {
122-
const refTag = `${{ github.ref_name }}`;
127+
const refTag = refName;
123128
expectedTags.push(refTag);
124129
expectedImageVersion = refTag;
125130
126-
const isTag = `${{ github.ref }}`.startsWith('refs/tags/');
127-
const isPushOnDefaultBranch = `${{ github.event_name }}` === "push" && !isTag && refTag === "${{ github.event.repository.default_branch }}";
131+
const isTag = context.ref.startsWith('refs/tags/');
132+
const isPushOnDefaultBranch = context.eventName === "push" && !isTag && refTag === defaultBranch;
128133
129134
if (isPushOnDefaultBranch) {
130135
expectedTags.push("latest");
@@ -202,11 +207,13 @@ jobs:
202207

203208
- name: Assert - Check built image output
204209
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
210+
env:
211+
BUILT_IMAGE_OUTPUT: ${{ steps.build-image.outputs.built-image }}
205212
with:
206213
script: |
207214
const assert = require("assert");
208215
209-
const builtImageOutput = ${{ toJSON(steps.build-image.outputs.built-image) }};
216+
const builtImageOutput = process.env.BUILT_IMAGE_OUTPUT;
210217
assert(builtImageOutput, `"built-image" output is empty`);
211218
212219
let builtImage;
@@ -303,11 +310,13 @@ jobs:
303310
304311
- name: Assert - Check built image output
305312
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
313+
env:
314+
BUILT_IMAGE_OUTPUT: ${{ steps.build-image.outputs.built-image }}
306315
with:
307316
script: |
308317
const assert = require("assert");
309318
310-
const builtImageOutput = ${{ toJSON(steps.build-image.outputs.built-image) }};
319+
const builtImageOutput = process.env.BUILT_IMAGE_OUTPUT;
311320
assert(builtImageOutput, `"built-image" output is empty`);
312321
313322
let builtImage;

.github/workflows/__test-action-docker-prune-pull-requests-image-tags.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ jobs:
114114
const packagePayload = {
115115
package_type: 'container',
116116
package_name: packageName,
117-
org: process.env.GITHUB_REPOSITORY_OWNER,
117+
org: context.repo.owner,
118118
};
119119
120120
// Ensure that package exists
@@ -192,7 +192,7 @@ jobs:
192192
const packagePayload = {
193193
package_type: 'container',
194194
package_name: packageName,
195-
org: process.env.GITHUB_REPOSITORY_OWNER,
195+
org: context.repo.owner,
196196
};
197197
198198
// Ensure that package still exists
@@ -267,6 +267,6 @@ jobs:
267267
return github.rest.packages.deletePackageForOrg({
268268
package_type: 'container',
269269
package_name: packageName,
270-
org: process.env.GITHUB_REPOSITORY_OWNER,
270+
org: context.repo.owner,
271271
});
272272
}));

.github/workflows/__test-action-get-image-metadata.yml

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,23 @@ jobs:
2727

2828
- name: Assert - Check get image metadata ouputs
2929
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
30+
env:
31+
IMAGE_OUTPUT: ${{ steps.get-image-metadata.outputs.image }}
32+
LABELS_OUTPUT: ${{ steps.get-image-metadata.outputs.labels }}
33+
ANNOTATIONS_OUTPUT: ${{ steps.get-image-metadata.outputs.annotations }}
34+
TAGS_OUTPUT: ${{ steps.get-image-metadata.outputs.tags }}
3035
with:
3136
script: |
3237
const assert = require("assert");
38+
const pullRequestNumber = context.payload.pull_request?.number;
39+
const refName = process.env.GITHUB_REF_NAME;
40+
const defaultBranch = context.payload.repository?.default_branch;
3341
34-
const imageOutput = `${{ steps.get-image-metadata.outputs.image }}`;
42+
const imageOutput = process.env.IMAGE_OUTPUT;
3543
assert(imageOutput.length, `"image" output is empty`);
3644
assert.equal(imageOutput,"ghcr.io/hoverkraft-tech/ci-github-container/application-test", `"image" output is not valid`);
3745
38-
const labelsOutput = `${{ steps.get-image-metadata.outputs.labels }}`;
46+
const labelsOutput = process.env.LABELS_OUTPUT;
3947
assert(labelsOutput.length, `"labels" output is empty`);
4048
assert(
4149
labelsOutput.startsWith("org.opencontainers.image.created"),
@@ -51,7 +59,7 @@ jobs:
5159
`"labels" output is not valid`
5260
);
5361
54-
const annotationsOutput = `${{ steps.get-image-metadata.outputs.annotations }}`;
62+
const annotationsOutput = process.env.ANNOTATIONS_OUTPUT;
5563
assert(annotationsOutput.length, `"annotations" output is empty`);
5664
5765
const expectedManifestAnnotations = expectedLabels.split("\n").map(line => {
@@ -74,26 +82,26 @@ jobs:
7482
`"annotations - manifest-descriptor" output is not valid`
7583
);
7684
77-
const tagsOutput = `${{ steps.get-image-metadata.outputs.tags }}`;
85+
const tagsOutput = process.env.TAGS_OUTPUT;
7886
assert(tagsOutput.length, `"tags" output is empty`);
7987
8088
const tags = tagsOutput.split("\n").filter(Boolean);
8189
assert(tags.length, `"tags" output is empty`);
8290
8391
const expectedTags = [];
8492
85-
if (`${{ github.event_name }}` === "pull_request") {
86-
const shortSha = `${{ github.sha }}`.substring(0, 7);
87-
const prShaTag = `pr-${{ github.event.pull_request.number }}-${shortSha}`;
88-
const prTag = `pr-${{ github.event.pull_request.number }}`;
93+
if (context.eventName === "pull_request") {
94+
const shortSha = context.sha.substring(0, 7);
95+
const prShaTag = `pr-${pullRequestNumber}-${shortSha}`;
96+
const prTag = `pr-${pullRequestNumber}`;
8997
9098
expectedTags.push(prShaTag, prTag);
9199
} else {
92-
const refTag = `${{ github.ref_name }}`;
100+
const refTag = refName;
93101
expectedTags.push(refTag);
94102
95-
const isTag = `${{ github.ref }}`.startsWith('refs/tags/');
96-
const isPushOnDefaultBranch = `${{ github.event_name }}` === "push" && !isTag && refTag === "${{ github.event.repository.default_branch }}";
103+
const isTag = context.ref.startsWith('refs/tags/');
104+
const isPushOnDefaultBranch = context.eventName === "push" && !isTag && refTag === defaultBranch;
97105
98106
if (isPushOnDefaultBranch) {
99107
expectedTags.push("latest");
@@ -103,7 +111,7 @@ jobs:
103111
assert.equal(
104112
tags.length,
105113
expectedTags.length,
106-
`"tags" output must contain ${expectedTags.length} tags for ${{ github.event_name }} event`
114+
`"tags" output must contain ${expectedTags.length} tags for ${context.eventName} event`
107115
);
108116
109117
for(const expectedTag of expectedTags) {
@@ -134,11 +142,13 @@ jobs:
134142

135143
- name: Assert - Check get image metadata ouputs
136144
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
145+
env:
146+
TAGS_OUTPUT: ${{ steps.get-image-metadata.outputs.tags }}
137147
with:
138148
script: |
139149
const assert = require("assert");
140150
141-
const tagsOutput = `${{ steps.get-image-metadata.outputs.tags }}`;
151+
const tagsOutput = process.env.TAGS_OUTPUT;
142152
assert(tagsOutput.length, `"tags" output is empty`);
143153
assert.equal(
144154
tagsOutput,

.github/workflows/__test-action-get-image-name.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ jobs:
2626

2727
- name: Check get image name ouputs
2828
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
29+
env:
30+
IMAGE_NAME_OUTPUT: ${{ steps.get-image-name.outputs.image-name }}
31+
FULL_IMAGE_NAME_OUTPUT: ${{ steps.get-image-name.outputs.image-name-with-registry }}
2932
with:
3033
script: |
3134
/* jscpd:ignore-start */
3235
const assert = require("assert");
3336
34-
const imageNameOutput = `${{ steps.get-image-name.outputs.image-name }}`;
35-
const fullImageNameOutput = `${{ steps.get-image-name.outputs.image-name-with-registry }}`;
37+
const imageNameOutput = process.env.IMAGE_NAME_OUTPUT;
38+
const fullImageNameOutput = process.env.FULL_IMAGE_NAME_OUTPUT;
3639
3740
assert(imageNameOutput.length, `"image-name" output is empty`);
3841
assert.equal(
@@ -68,13 +71,16 @@ jobs:
6871

6972
- name: Check get image name ouput
7073
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
74+
env:
75+
IMAGE_NAME_OUTPUT: ${{ steps.get-image-name.outputs.image-name }}
76+
FULL_IMAGE_NAME_OUTPUT: ${{ steps.get-image-name.outputs.image-name-with-registry }}
7177
with:
7278
script: |
7379
/* jscpd:ignore-start */
7480
const assert = require("assert");
7581
76-
const imageNameOutput = `${{ steps.get-image-name.outputs.image-name }}`;
77-
const fullImageNameOutput = `${{ steps.get-image-name.outputs.image-name-with-registry }}`;
82+
const imageNameOutput = process.env.IMAGE_NAME_OUTPUT;
83+
const fullImageNameOutput = process.env.FULL_IMAGE_NAME_OUTPUT;
7884
7985
assert(imageNameOutput.length, `"image-name" output is empty`);
8086
assert.equal(

.github/workflows/__test-action-helm-parse-chart-uri.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,19 @@ jobs:
2626

2727
- name: Assert - Check parse chart URI ouputs
2828
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
29+
env:
30+
REPOSITORY_OUTPUT: ${{ steps.parse-chart-uri.outputs.repository }}
31+
NAME_OUTPUT: ${{ steps.parse-chart-uri.outputs.name }}
32+
VERSION_OUTPUT: ${{ steps.parse-chart-uri.outputs.version }}
2933
with:
3034
script: |
3135
const assert = require("assert");
3236
33-
const repositoryOutput = `${{ steps.parse-chart-uri.outputs.repository }}`;
37+
const repositoryOutput = process.env.REPOSITORY_OUTPUT;
3438
assert.equal(repositoryOutput,"ghcr.io/my-org/my-repo/charts/application", `"repository" output is not valid`);
3539
36-
const nameOutput = `${{ steps.parse-chart-uri.outputs.name }}`;
40+
const nameOutput = process.env.NAME_OUTPUT;
3741
assert.equal(nameOutput,"my-repo", `"name" output is not valid`);
3842
39-
const versionOutput = `${{ steps.parse-chart-uri.outputs.version }}`;
43+
const versionOutput = process.env.VERSION_OUTPUT;
4044
assert.equal(versionOutput,"0.1.0", `"version" output is not valid`);

.github/workflows/__test-workflow-docker-build-images-building.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ jobs:
5555
steps:
5656
- name: Check built images ouput
5757
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
58+
env:
59+
BUILT_IMAGES_OUTPUT: ${{ needs.act-build-images-args-secrets.outputs.built-images }}
5860
with:
5961
script: |
6062
const assert = require("assert");
6163
62-
const builtImagesOutput = `${{ needs.act-build-images-args-secrets.outputs.built-images }}`;
64+
const builtImagesOutput = process.env.BUILT_IMAGES_OUTPUT;
6365
assert(builtImagesOutput.length, `"built-images" output is empty`);
6466
6567
// Check if is valid Json

.github/workflows/__test-workflow-docker-build-images-caching.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,31 @@ jobs:
141141
env:
142142
BUILT_IMAGES: ${{ needs[matrix.cache-type == 'registry' && 'act-build-images-registry' || 'act-build-images-gha' ].outputs.built-images }}
143143
EXPECTED_IMAGE: ghcr.io/${{ github.repository }}/${{ matrix.image-name }}
144+
IMAGE_NAME: ${{ matrix.image-name }}
144145
with:
145146
script: |
146147
const assert = require("assert");
148+
const pullRequestNumber = context.payload.pull_request?.number;
149+
const refName = process.env.GITHUB_REF_NAME;
147150
148151
let expectedTag;
149152
150-
const isPullRequest = `${{ github.event_name }}` === "pull_request";
153+
const isPullRequest = context.eventName === "pull_request";
151154
if (isPullRequest) {
152-
const shortSha = `${{ github.sha }}`.substring(0, 7);
153-
expectedTag = `pr-${{ github.event.pull_request.number }}-${shortSha}`;
155+
const shortSha = context.sha.substring(0, 7);
156+
expectedTag = `pr-${pullRequestNumber}-${shortSha}`;
154157
} else {
155-
expectedTag = `${{ github.ref_name }}`;
158+
expectedTag = refName;
156159
}
157160
158161
const builtImages = JSON.parse(process.env.BUILT_IMAGES);
159162
160-
const imageName = `${{ matrix.image-name }}`;
163+
const imageName = process.env.IMAGE_NAME;
161164
assert(builtImages[imageName], `"built-images" output does not contain "${imageName}" image`);
162165
163166
const digest = builtImages[imageName].digest;
164-
assert(digest.length, `"built-images" output does not contain digest for "${{ matrix.image-name }}" image`);
165-
assert.match(digest, /^sha256:[0-9a-f]{64}$/, `"built-images" output does not contain valid digest for "${{ matrix.image-name }}" image`);
167+
assert(digest.length, `"built-images" output does not contain digest for "${imageName}" image`);
168+
assert.match(digest, /^sha256:[0-9a-f]{64}$/, `"built-images" output does not contain valid digest for "${imageName}" image`);
166169
167170
const expectedImage = process.env.EXPECTED_IMAGE;
168171
const expectedImageTag = `${expectedImage}:${expectedTag}@${digest}`;
@@ -182,6 +185,14 @@ jobs:
182185
EXPECTED_CACHE_TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
183186
with:
184187
script: |
188+
const shouldAssertCache = context.eventName === 'pull_request'
189+
|| (context.eventName === 'push' && !context.ref.startsWith('refs/tags/'));
190+
191+
if (!shouldAssertCache) {
192+
core.info(`Skipping cache assertion for ${context.eventName} on ${context.ref}.`);
193+
return;
194+
}
195+
185196
const expectedCacheImage = `${process.env.EXPECTED_IMAGE}/cache:${process.env.EXPECTED_CACHE_TAG}`;
186197
const expectedPlatforms = JSON.parse(process.env.EXPECTED_PLATFORMS);
187198
const expectedCacheImages = expectedPlatforms.map(platform => `${expectedCacheImage}-${platform.replace('/', '-')}`);

.github/workflows/__test-workflow-docker-build-images-multi-registry.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ jobs:
5959
with:
6060
script: |
6161
const assert = require("assert");
62-
const sha = `${{ github.sha }}`;
62+
const sha = context.sha;
63+
const pullRequestNumber = context.payload.pull_request?.number;
64+
const refName = process.env.GITHUB_REF_NAME;
6365
6466
const builtImages = JSON.parse(process.env.BUILT_IMAGES);
6567
const builtImage = builtImages["test-multi-registry-inputs"];
@@ -68,9 +70,9 @@ jobs:
6870
assert.equal(builtImage.registry, "ghcr.io", `"registry" output is not valid`);
6971
assert.match(builtImage.digest, /^sha256:[0-9a-f]{64}$/, `"digest" output is not valid`);
7072
71-
const expectedTag = `${{ github.event_name }}` === "pull_request"
72-
? `pr-${{ github.event.pull_request.number }}-${sha.substring(0, 7)}`
73-
: `${{ github.ref_name }}`;
73+
const expectedTag = context.eventName === "pull_request"
74+
? `pr-${pullRequestNumber}-${sha.substring(0, 7)}`
75+
: refName;
7476
7577
const expectedImage = `${process.env.EXPECTED_IMAGE}:${expectedTag}@${builtImage.digest}`;
7678
assert.equal(builtImage.images[0], expectedImage, `"image" output is not valid`);
@@ -84,5 +86,13 @@ jobs:
8486
EXPECTED_CACHE_TAG: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref_name }}
8587
with:
8688
script: |
89+
const shouldAssertCache = context.eventName === "pull_request"
90+
|| (context.eventName === "push" && !context.ref.startsWith("refs/tags/"));
91+
92+
if (!shouldAssertCache) {
93+
core.info(`Skipping cache assertion for ${context.eventName} on ${context.ref}.`);
94+
return;
95+
}
96+
8797
const cacheImage = `${process.env.EXPECTED_CACHE_IMAGE}:${process.env.EXPECTED_CACHE_TAG}-linux-amd64`;
8898
await exec.exec("docker", ["manifest", "inspect", cacheImage]);

.github/workflows/__test-workflow-docker-build-images-platforms-and-signing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ jobs:
144144
{
145145
package_type: "container",
146146
package_name: `ci-github-container/${process.env.IMAGE_NAME}`,
147-
org: `${{ github.repository_owner }}`,
147+
org: context.repo.owner,
148148
per_page: 100
149149
}
150150
);

0 commit comments

Comments
 (0)