Skip to content

Commit b1e6791

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 b1e6791

File tree

3 files changed

+87
-61
lines changed

3 files changed

+87
-61
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: 69 additions & 48 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,56 +137,70 @@ 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
158168
if (isJson) {
159169
try {
160-
const container = JSON.parse(containerInput);
161-
162-
// Set image
163-
config.image = container.image || '';
164-
165-
// Add env if provided
166-
if (container.env && Object.keys(container.env).length > 0) {
167-
config.env = container.env;
168-
}
169-
170-
// Merge user options with default --user root:root
171-
if (container.options) {
172-
config.options = `${config.options} ${container.options}`;
173-
}
170+
const parsedContainer = JSON.parse(containerInput);
171+
container = {
172+
...container,
173+
...parsedContainer,
174+
options: `${container.options} ${parsedContainer.options || ''}`.trim()
175+
};
176+
174177
} catch (error) {
175-
core.setFailed(`Failed to parse container input as JSON: ${error.message}`);
176-
return;
178+
return core.setFailed(`Failed to parse container input as JSON: ${error.message}`,{ cause: error });
177179
}
178180
} else {
179181
// Simple string format - just the image name
180-
config.image = containerInput;
182+
container.image = containerInput;
181183
}
182184
183-
core.setOutput('config', JSON.stringify(config));
185+
core.debug(`Parsed container configuration: ${JSON.stringify(container)}`);
186+
187+
if (!container.image) {
188+
return core.setFailed('Container image must be specified in the container input.');
189+
}
190+
core.setOutput('container-image', container.image);
191+
192+
if (container.options) {
193+
core.setOutput('container-options', JSON.stringify(container.options));
194+
}
195+
196+
if (container.username) {
197+
core.setOutput('container-username', container.username);
198+
if(!process.env.CONTAINER_PASSWORD) {
199+
return core.setFailed('Container password must be provided when container username is specified.');
200+
}
201+
} else if (process.env.CONTAINER_PASSWORD) {
202+
return core.setFailed('Container username must be provided when container password is specified.');
203+
}
184204
185205
code-ql:
186206
name: 🛡️ CodeQL Analysis
@@ -208,9 +228,11 @@ jobs:
208228
setup:
209229
name: ⚙️ Setup
210230
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() }}
231+
needs: prepare
232+
container: &container-setup
233+
image: ${{ needs.prepare.outputs.container-image || '' }}
234+
options: ${{ fromJSON(needs.prepare.outputs.container-options && needs.prepare.outputs.container-options || '{}') }}
235+
credentials: ${{ fromJSON(needs.prepare.outputs.container-username && format('{"username":"{0}","password":"{1}"}',needs.prepare.outputs.container-username,secrets.container-password) || '{}') }}
214236
permissions:
215237
contents: read
216238
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
@@ -220,7 +242,7 @@ jobs:
220242
build-commands: ${{ steps.build-variables.outputs.commands }}
221243
build-artifact: ${{ steps.build-variables.outputs.artifact }}
222244
steps:
223-
- if: inputs.container == ''
245+
- if: needs.prepare.outputs.container-image == null
224246
uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
225247

226248
- id: build-variables
@@ -324,22 +346,21 @@ jobs:
324346
325347
lint:
326348
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 }}
349+
if: inputs.checks == true && inputs.lint
330350
needs:
331-
- parse-container
351+
- prepare
332352
- setup
353+
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
354+
container: *container-setup
333355
# jscpd:ignore-start
334356
permissions:
335357
contents: read
336358
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
337359
id-token: write
338360
steps:
339361
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
340-
if: inputs.container == ''
362+
if: needs.prepare.outputs.container-image == null
341363

342-
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
343364
- id: oidc
344365
uses: ChristopherHX/oidc@73eee1ff03fdfce10eda179f617131532209edbd # v3
345366
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
@@ -375,16 +396,16 @@ jobs:
375396
- uses: ./self-workflow/actions/lint
376397
with:
377398
working-directory: ${{ inputs.working-directory }}
378-
container: ${{ inputs.container != '' }}
399+
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
379400

380401
build:
381402
name: 🏗️ Build
382-
if: inputs.checks == true && always() && !cancelled() && !failure()
403+
if: inputs.checks == true
383404
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
405+
container: *container-setup
384406
# jscpd:ignore-start
385-
container: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config) || null }}
386407
needs:
387-
- parse-container
408+
- prepare
388409
- setup
389410
permissions:
390411
contents: read
@@ -394,7 +415,7 @@ jobs:
394415
artifact-id: ${{ steps.build.outputs.artifact-id }}
395416
steps:
396417
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
397-
if: needs.setup.outputs.build-commands && inputs.container == ''
418+
if: needs.setup.outputs.build-commands && needs.prepare.outputs.container-image == null
398419

399420
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
400421
- id: oidc
@@ -422,15 +443,15 @@ jobs:
422443
build-env: ${{ needs.setup.outputs.build-env }}
423444
build-secrets: ${{ secrets.build-secrets }}
424445
build-artifact: ${{ needs.setup.outputs.build-artifact }}
425-
container: ${{ inputs.container != '' }}
446+
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
426447

427448
test:
428449
name: 🧪 Test
429-
if: inputs.checks == true && inputs.test && always() && !cancelled() && !failure()
450+
if: inputs.checks == true && inputs.test
430451
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
431-
container: ${{ inputs.container != '' && fromJSON(needs.parse-container.outputs.config) || null }}
452+
container: *container-setup
432453
needs:
433-
- parse-container
454+
- prepare
434455
- setup
435456
- build
436457
permissions:
@@ -440,9 +461,9 @@ jobs:
440461
id-token: write
441462
steps:
442463
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
443-
if: inputs.container == ''
464+
if: needs.prepare.outputs.container-image == null
444465

445-
- if: needs.build.outputs.artifact-id && inputs.container == ''
466+
- if: needs.build.outputs.artifact-id && needs.prepare.outputs.container-image == null
446467
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
447468
with:
448469
artifact-ids: ${{ needs.build.outputs.artifact-id }}
@@ -491,7 +512,7 @@ jobs:
491512
- uses: ./self-workflow/actions/test
492513
with:
493514
working-directory: ${{ inputs.working-directory }}
494-
container: ${{ inputs.container != '' }}
515+
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
495516
coverage: ${{ steps.prepare-test-options.outputs.coverage }}
496-
coverage-files: ${{ steps.prepare-test-options.outputs['coverage-files'] }}
517+
coverage-files: ${{ steps.prepare-test-options.outputs.coverage-files }}
497518
github-token: ${{ github.token }}

0 commit comments

Comments
 (0)