Skip to content

Commit 7a0c54b

Browse files
Copilotneilime
andcommitted
docs: add yml syntax highlighting to code block
Co-authored-by: neilime <314088+neilime@users.noreply.github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 893f457 commit 7a0c54b

File tree

3 files changed

+80
-48
lines changed

3 files changed

+80
-48
lines changed

.github/workflows/__shared-ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ on:
66
permissions: {}
77

88
jobs:
9-
linter:
10-
uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
11-
permissions:
12-
contents: read
13-
statuses: write
14-
actions: read
15-
security-events: write
9+
# linter:
10+
# uses: hoverkraft-tech/ci-github-common/.github/workflows/linter.yml@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
11+
# permissions:
12+
# contents: read
13+
# statuses: write
14+
# actions: read
15+
# security-events: write
1616

1717
test-action-dependencies-cache:
1818
name: Test action "dependencies-cache"
19-
needs: linter
19+
# needs: linter
2020
uses: ./.github/workflows/__test-action-dependencies-cache.yml
2121
permissions:
2222
contents: read
2323

2424
test-action-get-package-manager:
2525
name: Test action "get-package-manager"
26-
needs: linter
26+
# needs: linter
2727
uses: ./.github/workflows/__test-action-get-package-manager.yml
2828
permissions:
2929
contents: read
3030

3131
test-action-has-installed-dependencies:
3232
name: Test action "has-installed-dependencies"
33-
needs: linter
33+
# needs: linter
3434
uses: ./.github/workflows/__test-action-has-installed-dependencies.yml
3535
permissions:
3636
contents: read
3737

3838
test-action-setup-node:
3939
name: Test action "setup-node"
40-
needs: linter
40+
# needs: linter
4141
uses: ./.github/workflows/__test-action-setup-node.yml
4242
permissions:
4343
contents: read
4444

4545
test-workflow-continuous-integration:
4646
name: Test workflow "continuous-integration"
47-
needs: linter
47+
# needs: linter
4848
uses: ./.github/workflows/__test-workflow-continuous-integration.yml
4949
permissions:
5050
contents: read

.github/workflows/__test-workflow-continuous-integration.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ jobs:
128128
"NODE_ENV": "test",
129129
"CI": "true"
130130
},
131-
"options": "--cpus 1"
131+
"options": "--cpus 1",
132+
"credentials": {
133+
"username": "${{ github.actor }}"
134+
}
132135
}
133136
working-directory: /usr/src/app/
134137
build: |
@@ -137,6 +140,8 @@ jobs:
137140
}
138141
test: |
139142
{"coverage": "codecov"}
143+
secrets:
144+
container-password: ${{ secrets.GITHUB_TOKEN }}
140145

141146
assert-with-container-advanced:
142147
name: Assert - Ensure build artifact has been uploaded (with container advanced)

.github/workflows/continuous-integration.yml

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ on:
8888
Accepts either a string (container image name) or a JSON object with container options.
8989
9090
String format (simple):
91-
```
91+
```yml
9292
container: "node:18"
9393
```
9494
@@ -123,6 +123,12 @@ on:
123123
SECRET_EXAMPLE=$\{{ secrets.SECRET_EXAMPLE }}
124124
```
125125
required: false
126+
container-password:
127+
description: |
128+
Password for container registry authentication, if required.
129+
Used when the container image is hosted in a private registry.
130+
See https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/run-jobs-in-a-container#defining-credentials-for-a-container-registry.
131+
required: false
126132
outputs:
127133
build-artifact-id:
128134
description: "ID of the build artifact) uploaded during the build step."
@@ -131,27 +137,31 @@ on:
131137
permissions: {}
132138

133139
jobs:
134-
parse-container:
135-
name: 📦 Parse Container Configuration
136-
if: inputs.container != ''
140+
prepare:
141+
name: 📦 Prepare configuration
137142
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
138143
permissions: {}
139144
outputs:
140-
config: ${{ steps.parse.outputs.config }}
145+
container-image: ${{ steps.parse.outputs.container-image }}
146+
container-options: ${{ steps.parse.outputs.container-options }}
147+
container-username: ${{ steps.parse.outputs.container-username }}
141148
steps:
142149
- id: parse
143150
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
144151
env:
145152
CONTAINER_INPUT: ${{ inputs.container }}
153+
CONTAINER_PASSWORD: ${{ secrets.container-password }}
146154
with:
147155
script: |
148156
const containerInput = process.env.CONTAINER_INPUT.trim();
157+
if (!containerInput) {
158+
return;
159+
}
149160
150161
// Check if input is a JSON object or a simple string
151162
const isJson = containerInput.startsWith('{');
152163
153-
let config = {
154-
image: '',
164+
let container = {
155165
options: '--user root:root'
156166
};
157167
@@ -160,27 +170,43 @@ jobs:
160170
const container = JSON.parse(containerInput);
161171
162172
// Set image
163-
config.image = container.image || '';
173+
container.image = container.image || '';
164174
165175
// Add env if provided
166176
if (container.env && Object.keys(container.env).length > 0) {
167-
config.env = container.env;
177+
container.env = container.env;
168178
}
169179
170180
// Merge user options with default --user root:root
171181
if (container.options) {
172-
config.options = `${config.options} ${container.options}`;
182+
container.options = `${container.options} ${container.options}`;
173183
}
174184
} catch (error) {
175185
core.setFailed(`Failed to parse container input as JSON: ${error.message}`);
176186
return;
177187
}
178188
} else {
179189
// Simple string format - just the image name
180-
config.image = containerInput;
190+
container.image = containerInput;
191+
}
192+
193+
if (!container.image) {
194+
return core.setFailed('Container image must be specified in the container input.');
181195
}
196+
core.setOutput('container-image', container.image);
182197
183-
core.setOutput('config', JSON.stringify(config));
198+
if (container.options) {
199+
core.setOutput('container-options', JSON.stringify(container.options));
200+
}
201+
202+
if (container.username) {
203+
core.setOutput('container-username', container.username);
204+
if(!process.env.CONTAINER_PASSWORD) {
205+
return core.setFailed('Container password must be provided when container username is specified.');
206+
}
207+
} else if (process.env.CONTAINER_PASSWORD) {
208+
return core.setFailed('Container username must be provided when container password is specified.');
209+
}
184210
185211
code-ql:
186212
name: 🛡️ CodeQL Analysis
@@ -208,9 +234,11 @@ jobs:
208234
setup:
209235
name: ⚙️ Setup
210236
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
211-
container: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config) || null }}
212-
needs: parse-container
213-
if: ${{ always() && !cancelled() && !failure() }}
237+
needs: prepare
238+
container: &container-setup
239+
image: ${{ needs.prepare.outputs.container-image || '' }}
240+
options: ${{ needs.prepare.outputs.container-options && fromJSON(needs.prepare.outputs.container-options) || null }}
241+
credentials: ${{ fromJSON(needs.prepare.outputs.container-username && format('{"username":"{0}","password":"{1}"}',needs.prepare.outputs.container-username,secrets.container-password) || '{}') }}
214242
permissions:
215243
contents: read
216244
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
@@ -220,7 +248,7 @@ jobs:
220248
build-commands: ${{ steps.build-variables.outputs.commands }}
221249
build-artifact: ${{ steps.build-variables.outputs.artifact }}
222250
steps:
223-
- if: inputs.container == ''
251+
- if: needs.prepare.outputs.container-image == null
224252
uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
225253

226254
- id: build-variables
@@ -324,22 +352,21 @@ jobs:
324352
325353
lint:
326354
name: 👕 Lint
327-
if: inputs.checks == true && inputs.lint && always() && !cancelled() && !failure()
328-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
329-
container: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config) || null }}
355+
if: inputs.checks == true && inputs.lint
330356
needs:
331-
- parse-container
357+
- prepare
332358
- setup
359+
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
360+
container: *container-setup
333361
# jscpd:ignore-start
334362
permissions:
335363
contents: read
336364
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
337365
id-token: write
338366
steps:
339367
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
340-
if: inputs.container == ''
368+
if: needs.prepare.outputs.container-image == null
341369

342-
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
343370
- id: oidc
344371
uses: ChristopherHX/oidc@73eee1ff03fdfce10eda179f617131532209edbd # v3
345372
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -375,16 +402,16 @@ jobs:
375402
- uses: ./self-workflow/actions/lint
376403
with:
377404
working-directory: ${{ inputs.working-directory }}
378-
container: ${{ inputs.container != '' }}
405+
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
379406

380407
build:
381408
name: 🏗️ Build
382-
if: inputs.checks == true && always() && !cancelled() && !failure()
409+
if: inputs.checks == true
383410
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
411+
container: *container-setup
384412
# jscpd:ignore-start
385-
container: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config) || null }}
386413
needs:
387-
- parse-container
414+
- prepare
388415
- setup
389416
permissions:
390417
contents: read
@@ -394,7 +421,7 @@ jobs:
394421
artifact-id: ${{ steps.build.outputs.artifact-id }}
395422
steps:
396423
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
397-
if: needs.setup.outputs.build-commands && inputs.container == ''
424+
if: needs.setup.outputs.build-commands && needs.prepare.outputs.container-image == null
398425

399426
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
400427
- id: oidc
@@ -422,15 +449,15 @@ jobs:
422449
build-env: ${{ needs.setup.outputs.build-env }}
423450
build-secrets: ${{ secrets.build-secrets }}
424451
build-artifact: ${{ needs.setup.outputs.build-artifact }}
425-
container: ${{ inputs.container != '' }}
452+
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
426453

427454
test:
428455
name: 🧪 Test
429-
if: inputs.checks == true && inputs.test && always() && !cancelled() && !failure()
456+
if: inputs.checks == true && inputs.test
430457
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
431-
container: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config) || null }}
458+
container: *container-setup
432459
needs:
433-
- parse-container
460+
- prepare
434461
- setup
435462
- build
436463
permissions:
@@ -440,9 +467,9 @@ jobs:
440467
id-token: write
441468
steps:
442469
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
443-
if: inputs.container == ''
470+
if: needs.prepare.outputs.container-image == null
444471

445-
- if: needs.build.outputs.artifact-id && inputs.container == ''
472+
- if: needs.build.outputs.artifact-id && needs.prepare.outputs.container-image == null
446473
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
447474
with:
448475
artifact-ids: ${{ needs.build.outputs.artifact-id }}
@@ -491,7 +518,7 @@ jobs:
491518
- uses: ./self-workflow/actions/test
492519
with:
493520
working-directory: ${{ inputs.working-directory }}
494-
container: ${{ inputs.container != '' }}
521+
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
495522
coverage: ${{ steps.prepare-test-options.outputs.coverage }}
496-
coverage-files: ${{ steps.prepare-test-options.outputs['coverage-files'] }}
523+
coverage-files: ${{ steps.prepare-test-options.outputs.coverage-files }}
497524
github-token: ${{ github.token }}

0 commit comments

Comments
 (0)