Skip to content

Commit a9809af

Browse files
committed
fix(continuous-integration): report path
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
1 parent 531b2a4 commit a9809af

File tree

7 files changed

+203
-423
lines changed

7 files changed

+203
-423
lines changed

.github/workflows/continuous-integration.md

Lines changed: 120 additions & 68 deletions
Large diffs are not rendered by default.

.github/workflows/continuous-integration.yml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ 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+
It should generate lint reports in standard formats.
60+
61+
Example:
62+
63+
```json:package.json
64+
{
65+
"lint:ci": "eslint . --output-file eslint-report.json --format json"
66+
}
67+
```
5968
type: string
6069
required: false
6170
default: "true"
@@ -79,6 +88,15 @@ on:
7988
Whether to enable testing.
8089
Set to `null` or empty to disable.
8190
Accepts a JSON object for test options. See [test action](../actions/test/README.md).
91+
If coverage is enabled, it should generate test and coverage reports in standard formats.
92+
93+
Example:
94+
95+
```json:package.json
96+
{
97+
"test:ci": "vitest run --reporter=default --reporter=junit --outputFile=junit.xml --coverage.enabled --coverage.reporter=lcov --coverage.reporter=text"
98+
}
99+
```
82100
type: string
83101
required: false
84102
default: "true"
@@ -111,6 +129,9 @@ on:
111129
"volumes": ["/tmp:/tmp", "/cache:/cache"],
112130
"credentials": {
113131
"username": "myusername"
132+
},
133+
pathMapping: {
134+
"/app": "./relative/path/to/app"
114135
}
115136
}
116137
```
@@ -123,6 +144,7 @@ on:
123144
- `ports` (array)
124145
- `volumes` (array)
125146
- `credentials` (object with `username`).
147+
- `pathMapping` (object) path mapping from container paths to repository paths. Defaults is working directory is mapped with repository root.
126148
127149
See https://docs.github.com/en/actions/how-tos/write-workflows/choose-where-workflows-run/run-jobs-in-a-container.
128150
@@ -171,12 +193,14 @@ jobs:
171193
container-ports: ${{ steps.parse.outputs.container-ports }}
172194
container-volumes: ${{ steps.parse.outputs.container-volumes }}
173195
container-username: ${{ steps.parse.outputs.container-username }}
196+
path-mapping: ${{ steps.parse.outputs.path-mapping }}
174197
steps:
175198
- id: parse
176199
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
177200
env:
178201
CONTAINER_INPUT: ${{ inputs.container }}
179202
CONTAINER_PASSWORD: ${{ secrets.container-password }}
203+
WORKING_DIRECTORY: ${{ inputs.working-directory }}
180204
with:
181205
script: |
182206
const containerInput = process.env.CONTAINER_INPUT.trim();
@@ -192,16 +216,26 @@ jobs:
192216
options: '--user root:root'
193217
};
194218
219+
let pathMapping = {
220+
[process.env.WORKING_DIRECTORY || '.']: process.env.GITHUB_WORKSPACE,
221+
};
222+
195223
if (isJson) {
196224
try {
197-
const parsedContainer = JSON.parse(containerInput);
225+
const {pathMapping: parsedPathMapping, ...parsedContainer} = JSON.parse(containerInput);
198226
core.debug(`Parsed container input as JSON: ${JSON.stringify(parsedContainer)}`);
227+
199228
container = {
200229
...container,
201230
...parsedContainer,
202231
options: `${container.options} ${parsedContainer.options || ''}`.trim()
203232
};
204233
234+
core.debug(`Parsed path mapping: ${JSON.stringify(parsedPathMapping)}`);
235+
if (parsedPathMapping){
236+
pathMapping = parsedPathMapping;
237+
}
238+
205239
} catch (error) {
206240
return core.setFailed(`Failed to parse container input as JSON: ${error.message}`,{ cause: error });
207241
}
@@ -242,6 +276,16 @@ jobs:
242276
return core.setFailed('Container credentials username must be provided when container password is specified.');
243277
}
244278
279+
core.debug(`Parsed path mapping: ${JSON.stringify(pathMapping)}`);
280+
if (!pathMapping || typeof pathMapping !== 'object' || Object.keys(pathMapping).length === 0){
281+
return core.setFailed('At least one path mapping must be specified in the container configuration.');
282+
}
283+
284+
core.setOutput('path-mapping', Object.entries(pathMapping).reduce((acc, [containerPath, repoPath]) => {
285+
acc += `${acc?',' : ''}${containerPath}:${repoPath}`;
286+
return acc;
287+
}, ""));
288+
245289
code-ql:
246290
name: 🛡️ CodeQL Analysis
247291
if: inputs.checks == true && inputs.code-ql != ''
@@ -449,6 +493,7 @@ jobs:
449493
container: ${{ inputs.container != '' && 'true' || 'false' }}
450494
command: ${{ steps.preparel-lint-options.outputs.command }}
451495
report-file: ${{ steps.preparel-lint-options.outputs.report-file }}
496+
path-mapping: ${{ needs.prepare.outputs.path-mapping || '' }}
452497

453498
build:
454499
if: inputs.checks == true
@@ -559,7 +604,7 @@ jobs:
559604
testOptions.coverage = 'github';
560605
}
561606
core.setOutput('coverage', testOptions.coverage );
562-
core.setOutput('coverage-files', testOptions['coverage-files'] || '');
607+
core.setOutput('report-file', testOptions['report-file'] || '');
563608
core.setOutput('command', testOptions.command || 'test:ci');
564609
565610
- name: Run tests
@@ -569,5 +614,6 @@ jobs:
569614
container: ${{ inputs.container != '' && 'true' || 'false' }}
570615
command: ${{ steps.prepare-test-options.outputs.command }}
571616
coverage: ${{ steps.prepare-test-options.outputs.coverage }}
572-
coverage-files: ${{ steps.prepare-test-options.outputs.coverage-files }}
617+
report-file: ${{ steps.prepare-test-options.outputs.report-file }}
618+
path-mapping: ${{ needs.prepare.outputs.path-mapping || '' }}
573619
github-token: ${{ secrets.github-token || github.token }}

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ _Actions for continuous integration steps: build, lint, and test._
2828

2929
#### - [Test](actions/test/README.md)
3030

31-
#### - [Rewrite Report Paths](actions/rewrite-report-paths/README.md)
32-
3331
### Dependencies
3432

3533
_Actions dedicated to caching and validating Node.js dependencies._

actions/lint/action.yml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,20 @@ inputs:
2020
description: |
2121
NPM/package manager script command to run for linting.
2222
This should be a script defined in your package.json.
23-
The command should generate lint report files in a standard format (ESLint JSON or Checkstyle XML).
23+
The command should generate lint report files in a standard format.
2424
required: false
2525
default: "lint:ci"
2626
report-file:
2727
description: |
2828
Optional lint report path forwarded to the [parse-ci-reports](https://hoverkraft-tech/ci-github-common/actions/parse-ci-reports) action.
2929
Provide an absolute path or one relative to the working directory.
30-
When omitted, the action falls back to "auto:lint" detection (ESLint JSON / Checkstyle XML).
30+
When omitted, the action falls back to "auto:lint" detection.
31+
required: false
32+
default: ""
33+
path-mapping:
34+
description: |
35+
Optional path mapping to adjust file paths in test and coverage reports.
36+
See the [parse-ci-reports documentation](https://hoverkraft-tech/ci-github-common/actions/parse-ci-reports) for details.
3137
required: false
3238
default: ""
3339

@@ -61,25 +67,22 @@ runs:
6167
LINT_COMMAND: ${{ inputs.command }}
6268
with:
6369
script: |
64-
const workingDirectory = process.env.WORKING_DIRECTORY || '.';
70+
const workingDirectory = process.env.WORKING_DIRECTORY;
6571
const runScriptCommand = process.env.RUN_LINT_COMMAND;
6672
const lintCommand = process.env.LINT_COMMAND || 'lint:ci';
6773
6874
core.info(`👕 Running lint command: ${lintCommand}...`);
6975
7076
try {
71-
const result = await exec.getExecOutput(runScriptCommand, [lintCommand], {
72-
cwd: require('path').resolve(process.env.GITHUB_WORKSPACE, workingDirectory),
77+
const exitCode = await exec.exec(runScriptCommand, [lintCommand], {
78+
cwd: workingDirectory,
7379
ignoreReturnCode: true
7480
});
7581
76-
if (result.stdout) core.info(result.stdout);
77-
if (result.stderr) core.warning(result.stderr);
82+
core.setOutput('lint-exit-code', exitCode);
7883
79-
core.setOutput('lint-exit-code', result.exitCode);
80-
81-
if (result.exitCode !== 0) {
82-
core.setFailed(`Linting failed with exit code ${result.exitCode}`);
84+
if (exitCode !== 0) {
85+
core.setFailed(`Linting failed with exit code ${exitCode}`);
8386
}
8487
} catch (error) {
8588
core.setOutput('lint-exit-code', 1);
@@ -90,7 +93,9 @@ runs:
9093
if: always()
9194
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@c314229c3ca6914f7023ffca7afc26753ab99b41 # 0.30.1
9295
with:
96+
working-directory: ${{ inputs.working-directory }}
9397
report-paths: ${{ inputs.report-file || 'auto:lint' }}
98+
path-mapping: ${{ inputs.path-mapping }}
9499
report-name: "Lint Results"
95100
output-format: "annotations,summary"
96101

actions/rewrite-report-paths/README.md

Lines changed: 0 additions & 175 deletions
This file was deleted.

0 commit comments

Comments
 (0)