-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__test-action-get-image-metadata.yml
More file actions
156 lines (129 loc) · 5.79 KB
/
Copy path__test-action-get-image-metadata.yml
File metadata and controls
156 lines (129 loc) · 5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
---
name: Test for "docker/get-image-metadata" action
run-name: Test for "docker/get-image-metadata" action
on: # yamllint disable-line rule:truthy
workflow_call:
permissions: {}
jobs:
tests:
name: Test for "docker/get-image-metadata" action
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Act
id: get-image-metadata
uses: ./actions/docker/get-image-metadata
with:
oci-registry: ghcr.io
image: application-test
- name: Assert - Check get image metadata outputs
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
IMAGE_OUTPUT: ${{ steps.get-image-metadata.outputs.image }}
LABELS_OUTPUT: ${{ steps.get-image-metadata.outputs.labels }}
ANNOTATIONS_OUTPUT: ${{ steps.get-image-metadata.outputs.annotations }}
TAGS_OUTPUT: ${{ steps.get-image-metadata.outputs.tags }}
with:
script: |
const assert = require("assert");
const pullRequestNumber = context.payload.pull_request?.number;
const refName = process.env.GITHUB_REF_NAME;
const defaultBranch = context.payload.repository?.default_branch;
const imageOutput = process.env.IMAGE_OUTPUT;
assert(imageOutput.length, `"image" output is empty`);
assert.equal(imageOutput,"ghcr.io/hoverkraft-tech/ci-github-container/application-test", `"image" output is not valid`);
const labelsOutput = process.env.LABELS_OUTPUT;
assert(labelsOutput.length, `"labels" output is empty`);
assert(
labelsOutput.startsWith("org.opencontainers.image.created"),
`"labels" "org.opencontainers.image.created" output is not valid`
);
const expectedLabels = "org.opencontainers.image.source=https://github.com/hoverkraft-tech/ci-github-container\n" +
"org.opencontainers.image.title=ci-github-container\n" +
"org.opencontainers.image.url=https://github.com/hoverkraft-tech/ci-github-container\n";
assert(
labelsOutput.includes(expectedLabels),
`"labels" output is not valid`
);
const annotationsOutput = process.env.ANNOTATIONS_OUTPUT;
assert(annotationsOutput.length, `"annotations" output is empty`);
const expectedManifestAnnotations = expectedLabels.split("\n").map(line => {
if (line.length === 0) return line;
return `manifest:${line}`;
}).join("\n");
assert(
annotationsOutput.includes(expectedManifestAnnotations),
`"annotations - manifest" output is not valid`
);
const expectedManifestDescriptorAnnotations = expectedLabels.split("\n").map(line => {
if (line.length === 0) return line;
return `manifest-descriptor:${line}`;
}).join("\n");
assert(
annotationsOutput.includes(expectedManifestDescriptorAnnotations),
`"annotations - manifest-descriptor" output is not valid`
);
const tagsOutput = process.env.TAGS_OUTPUT;
assert(tagsOutput.length, `"tags" output is empty`);
const tags = tagsOutput.split("\n").filter(Boolean);
assert(tags.length, `"tags" output is empty`);
const expectedTags = [];
if (context.eventName === "pull_request") {
const shortSha = context.sha.substring(0, 7);
const prShaTag = `pr-${pullRequestNumber}-${shortSha}`;
const prTag = `pr-${pullRequestNumber}`;
expectedTags.push(prShaTag, prTag);
} else {
const refTag = refName;
expectedTags.push(refTag);
const isTag = context.ref.startsWith('refs/tags/');
const isPushOnDefaultBranch = context.eventName === "push" && !isTag && refTag === defaultBranch;
if (isPushOnDefaultBranch) {
expectedTags.push("latest");
}
}
assert.equal(
tags.length,
expectedTags.length,
`"tags" output must contain ${expectedTags.length} tags for ${context.eventName} event`
);
for(const expectedTag of expectedTags) {
const fullTag = `ghcr.io/hoverkraft-tech/ci-github-container/application-test:${expectedTag}`;
assert(
tags.includes(fullTag),
`Expected tag "${fullTag}" not found in "tags" output`
);
}
tests-with-given-tag:
name: Test for "docker/get-image-metadata" action with given tag
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
persist-credentials: false
- name: Act
id: get-image-metadata
uses: ./actions/docker/get-image-metadata
with:
oci-registry: ghcr.io
image: application-test
tag: 1.0.0
- name: Assert - Check get image metadata outputs
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
TAGS_OUTPUT: ${{ steps.get-image-metadata.outputs.tags }}
with:
script: |
const assert = require("assert");
const tagsOutput = process.env.TAGS_OUTPUT;
assert(tagsOutput.length, `"tags" output is empty`);
assert.equal(
tagsOutput,
"ghcr.io/hoverkraft-tech/ci-github-container/application-test:1.0.0"
);