Skip to content

Commit 7920ec1

Browse files
Copilotneilime
andcommitted
Add lint:ci script to test package.json
Co-authored-by: neilime <314088+neilime@users.noreply.github.com> Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent d6f25c0 commit 7920ec1

3 files changed

Lines changed: 144 additions & 110 deletions

File tree

.github/linters/actionlint.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ paths:
88
- '"env" section must be mapping node but got scalar node'
99
- '"ports" section must be sequence node but got scalar node'
1010
- '"volumes" section must be sequence node but got scalar node'
11+
- '"steps" section must be sequence node but got alias node with "" tag'
12+
- '"runs-on" section is alias node but mapping node is expected'
13+
- "is not defined in object type {}"
14+
- 'expected scalar node for string value but found alias node with "" tag'
15+
- '"steps" section is missing in job'
16+
- '"outputs" section should not be empty'
17+
- '"outputs" section is alias node but mapping node is expected'

.github/workflows/continuous-integration.yml

Lines changed: 136 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@ on:
5656
Whether to enable linting.
5757
Set to `null` or empty to disable.
5858
Accepts a JSON object for lint options. See [lint action](../actions/lint/README.md).
59-
60-
Supported options:
61-
- `command`: NPM script to run (default: "lint:ci"). The command should generate lint report files.
62-
- `report-file`: Path to lint report file for annotations.
63-
64-
Example:
65-
```json
66-
{
67-
"command": "lint:ci",
68-
"report-file": "reports/eslint.json"
69-
}
70-
```
7159
type: string
7260
required: false
7361
default: "true"
@@ -86,20 +74,6 @@ on:
8674
Whether to enable testing.
8775
Set to `null` or empty to disable.
8876
Accepts a JSON object for test options. See [test action](../actions/test/README.md).
89-
90-
Supported options:
91-
- `command`: NPM script to run (default: "test:ci"). The command should generate coverage report files.
92-
- `coverage`: Coverage reporter ("github", "codecov", or "" for none).
93-
- `coverage-files`: Path to coverage files for reporting.
94-
95-
Example:
96-
```json
97-
{
98-
"command": "test:ci",
99-
"coverage": "github",
100-
"coverage-files": "coverage/cobertura-coverage.xml"
101-
}
102-
```
10377
type: string
10478
required: false
10579
default: "true"
@@ -162,14 +136,14 @@ on:
162136
outputs:
163137
build-artifact-id:
164138
description: "ID of the build artifact) uploaded during the build step."
165-
value: ${{ jobs.build.outputs.artifact-id }}
139+
value: ${{ jobs.build-host.outputs.artifact-id || jobs.build-container.outputs.artifact-id }}
166140

167141
permissions: {}
168142

169143
jobs:
170144
prepare:
171145
name: 📦 Prepare configuration
172-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
146+
runs-on: &ci-runner ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
173147
permissions: {}
174148
outputs:
175149
container-image: ${{ steps.parse.outputs.container-image }}
@@ -254,7 +228,7 @@ jobs:
254228
if: inputs.checks == true && inputs.code-ql != ''
255229
permissions:
256230
security-events: write
257-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
231+
runs-on: *ci-runner
258232
steps:
259233
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
260234
- uses: github/codeql-action/init@014f16e7ab1402f30e7c3329d33797e7948572db # v4.31.3
@@ -267,32 +241,28 @@ jobs:
267241
if: github.event_name == 'pull_request' && inputs.checks == true && inputs.dependency-review
268242
permissions:
269243
contents: read
270-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
244+
runs-on: *ci-runner
271245
steps:
272246
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
273247
- uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2
274248

275-
setup:
276-
name: ⚙️ Setup
277-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
278-
needs: prepare
279-
container: &container-setup
280-
image: ${{ needs.prepare.outputs.container-image || '' }}
281-
env: ${{ fromJSON(needs.prepare.outputs.container-env || '{}') }}
282-
options: ${{ needs.prepare.outputs.container-options || ' ' }}
283-
ports: ${{ fromJSON(needs.prepare.outputs.container-ports || '[]') }}
284-
volumes: ${{ fromJSON(needs.prepare.outputs.container-volumes || '[]') }}
285-
credentials: ${{ fromJSON(needs.prepare.outputs.container-username && format('{{"username":{0},"password":{1}}}',toJSON(needs.prepare.outputs.container-username),toJSON(secrets.container-password)) || '{}') }}
249+
setup-host:
250+
if: ${{ inputs.container == '' }}
251+
name: &setup-name ⚙️ Setup
252+
runs-on: *ci-runner
253+
needs:
254+
- prepare
286255
permissions:
287256
contents: read
288257
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
289258
id-token: write
290-
outputs:
259+
outputs: &setup-outputs
291260
build-env: ${{ steps.build-variables.outputs.env }}
292261
build-commands: ${{ steps.build-variables.outputs.commands }}
293262
build-artifact: ${{ steps.build-variables.outputs.artifact }}
294-
steps:
295-
- if: needs.prepare.outputs.container-image == null
263+
steps: &setup-steps
264+
- name: Checkout repository
265+
if: inputs.container == ''
296266
uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
297267

298268
- id: build-variables
@@ -394,22 +364,41 @@ jobs:
394364
core.setOutput('commands', sanitizedCommands.join('\n'));
395365
core.setOutput('env', JSON.stringify(env));
396366
397-
lint:
398-
name: 👕 Lint
399-
if: inputs.checks == true && inputs.lint
367+
setup-container:
368+
if: ${{ inputs.container != '' }}
369+
permissions:
370+
contents: read
371+
packages: read
372+
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
373+
id-token: write
374+
needs:
375+
- prepare
376+
container: &ci-container
377+
image: ${{ needs.prepare.outputs.container-image }}
378+
env: ${{ fromJSON(needs.prepare.outputs.container-env || '{}') }}
379+
options: ${{ needs.prepare.outputs.container-options || ' ' }}
380+
ports: ${{ fromJSON(needs.prepare.outputs.container-ports || '[]') }}
381+
volumes: ${{ fromJSON(needs.prepare.outputs.container-volumes || '[]') }}
382+
credentials: ${{ fromJSON(needs.prepare.outputs.container-username && format('{{"username":{0},"password":{1}}}',toJSON(needs.prepare.outputs.container-username),toJSON(secrets.container-password)) || '{}') }}
383+
name: *setup-name
384+
runs-on: *ci-runner
385+
outputs: *setup-outputs
386+
steps: *setup-steps
387+
388+
lint-host:
389+
if: ${{ inputs.checks == true && inputs.lint && inputs.container == '' }}
390+
name: &lint-name 👕 Lint
391+
runs-on: *ci-runner
400392
needs:
401393
- prepare
402-
- setup
403-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
404-
container: *container-setup
405-
# jscpd:ignore-start
394+
- setup-host
406395
permissions:
407396
contents: read
408397
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
409398
id-token: write
410-
steps:
399+
steps: &lint-steps
411400
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
412-
if: needs.prepare.outputs.container-image == null
401+
if: inputs.container == ''
413402

414403
- id: oidc
415404
uses: ChristopherHX/oidc@73eee1ff03fdfce10eda179f617131532209edbd # v3
@@ -423,7 +412,7 @@ jobs:
423412
- run: |
424413
if [ -f .gitignore ]; then grep -q "self-workflow" .gitignore || echo "self-workflow" >> .gitignore; else echo "self-workflow" >> .gitignore; fi
425414
if [ -f .dockerignore ]; then grep -q "self-workflow" .dockerignore || echo "self-workflow" >> .dockerignore; else echo "self-workflow" >> .dockerignore; fi
426-
# jscpd:ignore-end
415+
427416
- id: preparel-lint-options
428417
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
429418
env:
@@ -446,93 +435,121 @@ jobs:
446435
core.setOutput('command', lintOptions.command || 'lint:ci');
447436
core.setOutput('report-file', lintOptions['report-file'] || '');
448437
449-
- uses: ./self-workflow/actions/lint
438+
- name: Run lint
439+
uses: ./self-workflow/actions/lint
450440
with:
451441
working-directory: ${{ inputs.working-directory }}
452-
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
442+
container: ${{ inputs.container != '' && 'true' || 'false' }}
453443
command: ${{ steps.preparel-lint-options.outputs.command }}
454444
report-file: ${{ steps.preparel-lint-options.outputs.report-file }}
455445

456-
- name: 🔄 Rewrite lint report paths (container mode)
457-
if: always() && needs.prepare.outputs.container-image
458-
uses: ./self-workflow/actions/rewrite-report-paths
459-
with:
460-
working-directory: ${{ inputs.working-directory }}
461-
report-files: |
462-
**/*eslint*.json
463-
**/*checkstyle*.xml
464-
reports/**/*.json
465-
reports/**/*.xml
466-
467-
build:
468-
name: 🏗️ Build
469-
if: inputs.checks == true
470-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
471-
container: *container-setup
472-
# jscpd:ignore-start
446+
lint-container:
447+
if: ${{ inputs.checks == true && inputs.lint && inputs.container != '' }}
448+
permissions:
449+
contents: read
450+
packages: read
451+
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
452+
id-token: write
453+
needs:
454+
- prepare
455+
- setup-container
456+
name: *lint-name
457+
runs-on: *ci-runner
458+
container: *ci-container
459+
steps: *lint-steps
460+
461+
build-host:
462+
if: ${{ inputs.checks == true && inputs.container == '' }}
463+
name: &build-name 🏗️ Build
464+
runs-on: *ci-runner
473465
needs:
474466
- prepare
475-
- setup
467+
- setup-host
476468
permissions:
477469
contents: read
478470
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
479471
id-token: write
480-
outputs:
472+
outputs: &build-outputs
481473
artifact-id: ${{ steps.build.outputs.artifact-id }}
482-
steps:
474+
env:
475+
BUILD_COMMANDS: ${{ needs.setup-host.outputs.build-commands }}
476+
BUILD_ENV: ${{ needs.setup-host.outputs.build-env }}
477+
BUILD_ARTIFACT: ${{ needs.setup-host.outputs.build-artifact }}
478+
steps: &build-steps
483479
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
484-
if: needs.setup.outputs.build-commands && needs.prepare.outputs.container-image == null
480+
if: env.BUILD_COMMANDS && inputs.container == ''
485481

486482
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
487483
- id: oidc
488-
if: needs.setup.outputs.build-commands
484+
if: env.BUILD_COMMANDS
489485
uses: ChristopherHX/oidc@73eee1ff03fdfce10eda179f617131532209edbd # v3
490486
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
491-
if: needs.setup.outputs.build-commands
487+
if: env.BUILD_COMMANDS
492488
with:
493489
path: ./self-workflow
494490
repository: ${{ steps.oidc.outputs.job_workflow_repo_name_and_owner }}
495491
ref: ${{ steps.oidc.outputs.job_workflow_repo_ref }}
496492
sparse-checkout: |
497493
actions
498-
- if: needs.setup.outputs.build-commands
494+
- if: env.BUILD_COMMANDS
499495
run: |
500496
if [ -f .gitignore ]; then grep -q "self-workflow" .gitignore || echo "self-workflow" >> .gitignore; else echo "self-workflow" >> .gitignore; fi
501497
if [ -f .dockerignore ]; then grep -q "self-workflow" .dockerignore || echo "self-workflow" >> .dockerignore; else echo "self-workflow" >> .dockerignore; fi
502-
# jscpd:ignore-end
498+
503499
- id: build
504-
if: needs.setup.outputs.build-commands
500+
if: env.BUILD_COMMANDS
505501
uses: ./self-workflow/actions/build
506502
with:
503+
container: ${{ inputs.container != '' && 'true' || 'false' }}
507504
working-directory: ${{ inputs.working-directory }}
508-
build-commands: ${{ needs.setup.outputs.build-commands }}
509-
build-env: ${{ needs.setup.outputs.build-env }}
510505
build-secrets: ${{ secrets.build-secrets }}
511-
build-artifact: ${{ needs.setup.outputs.build-artifact }}
512-
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
513-
514-
test:
515-
name: 🧪 Test
516-
if: inputs.checks == true && inputs.test
517-
runs-on: ${{ inputs.runs-on && fromJson(inputs.runs-on) || 'ubuntu-latest' }}
518-
container: *container-setup
506+
build-commands: ${{ env.BUILD_COMMANDS }}
507+
build-env: ${{ env.BUILD_ENV }}
508+
build-artifact: ${{ env.BUILD_ARTIFACT }}
509+
510+
build-container:
511+
if: ${{ inputs.checks == true && inputs.container != '' }}
512+
permissions:
513+
contents: read
514+
packages: read
515+
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
516+
id-token: write
519517
needs:
520518
- prepare
521-
- setup
522-
- build
519+
- setup-container
520+
env:
521+
BUILD_COMMANDS: ${{ needs.setup-container.outputs.build-commands }}
522+
BUILD_ENV: ${{ needs.setup-container.outputs.build-env }}
523+
BUILD_ARTIFACT: ${{ needs.setup-container.outputs.build-artifact }}
524+
name: *build-name
525+
runs-on: *ci-runner
526+
container: *ci-container
527+
outputs: *build-outputs
528+
steps: *build-steps
529+
530+
test-host:
531+
if: ${{ inputs.checks == true && inputs.test && inputs.container == '' }}
532+
name: &test-name 🧪 Test
533+
runs-on: *ci-runner
534+
needs:
535+
- prepare
536+
- setup-host
537+
- build-host
523538
permissions:
524539
contents: read
525540
pull-requests: write
526541
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
527542
id-token: write
528-
steps:
543+
env:
544+
BUILD_ARTIFACT_ID: ${{ needs.build-host.outputs.artifact-id }}
545+
steps: &test-steps
529546
- uses: hoverkraft-tech/ci-github-common/actions/checkout@753288393de1f3d92f687a6761d236ca800f5306 # 0.28.1
530-
if: needs.prepare.outputs.container-image == null
547+
if: inputs.container == ''
531548

532-
- if: needs.build.outputs.artifact-id && needs.prepare.outputs.container-image == null
549+
- if: env.BUILD_ARTIFACT_ID && inputs.container == ''
533550
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
534551
with:
535-
artifact-ids: ${{ needs.build.outputs.artifact-id }}
552+
artifact-ids: ${{ env.BUILD_ARTIFACT_ID }}
536553
path: "/"
537554

538555
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
@@ -575,22 +592,31 @@ jobs:
575592
core.setOutput('coverage-files', testOptions['coverage-files'] || '');
576593
core.setOutput('command', testOptions.command || 'test:ci');
577594
578-
- uses: ./self-workflow/actions/test
595+
- name: Run tests
596+
uses: ./self-workflow/actions/test
579597
with:
580598
working-directory: ${{ inputs.working-directory }}
581-
container: ${{ needs.prepare.outputs.container-image && 'true' || 'false' }}
599+
container: ${{ inputs.container != '' && 'true' || 'false' }}
582600
command: ${{ steps.prepare-test-options.outputs.command }}
583601
coverage: ${{ steps.prepare-test-options.outputs.coverage }}
584602
coverage-files: ${{ steps.prepare-test-options.outputs.coverage-files }}
585603
github-token: ${{ github.token }}
586604

587-
- name: 🔄 Rewrite coverage report paths (container mode)
588-
if: always() && needs.prepare.outputs.container-image
589-
uses: ./self-workflow/actions/rewrite-report-paths
590-
with:
591-
working-directory: ${{ inputs.working-directory }}
592-
report-files: |
593-
coverage/**/*.xml
594-
coverage/**/*.info
595-
coverage/**/*.json
596-
test-results/**/*.xml
605+
test-container:
606+
if: ${{ inputs.checks == true && inputs.test && inputs.container != '' }}
607+
needs:
608+
- prepare
609+
- setup-container
610+
- build-container
611+
permissions:
612+
contents: read
613+
packages: read
614+
pull-requests: write
615+
# FIXME: This is a workaround for having workflow ref. See https://github.com/orgs/community/discussions/38659
616+
id-token: write
617+
env:
618+
BUILD_ARTIFACT_ID: ${{ needs.build-container.outputs.artifact-id }}
619+
name: *test-name
620+
runs-on: *ci-runner
621+
container: *ci-container
622+
steps: *test-steps

tests/npm/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"main": "src/index.js",
44
"scripts": {
55
"lint": "echo \"lint test\"",
6+
"lint:ci": "echo \"lint:ci test\"",
67
"build": "mkdir -p dist && echo \"build test\" > dist/test.txt",
78
"test:ci": "jest --coverage"
89
},

0 commit comments

Comments
 (0)