-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
113 lines (101 loc) · 4.13 KB
/
action.yml
File metadata and controls
113 lines (101 loc) · 4.13 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
name: "Lint"
description: "Action to lint Node.js projects with support for pull request reporting and annotations"
author: hoverkraft
branding:
icon: check-circle
color: blue
inputs:
working-directory:
description: |
Working directory where lint commands are executed.
Can be absolute or relative to the repository root.
required: false
default: "."
container:
description: "Whether running in container mode (skips checkout and node setup)"
required: false
default: "false"
command:
description: |
npm/pnpm/Yarn script command to run for linting.
This should be a script defined in your `package.json`.
The command should generate lint report files in a standard format.
required: false
default: "lint:ci"
report-file:
description: |
Optional lint report path forwarded to the [parse-ci-reports](https://hoverkraft-tech/ci-github-common/actions/parse-ci-reports) action.
Provide an absolute path or one relative to the working directory.
When omitted, the action falls back to `auto:lint` detection.
required: false
default: ""
path-mapping:
description: |
Optional path mapping to adjust file paths in test and coverage reports.
See the [parse-ci-reports documentation](https://hoverkraft-tech/ci-github-common/actions/parse-ci-reports) for details.
required: false
default: ""
runs:
using: "composite"
steps:
- shell: bash
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
run: mkdir -p ./self-lint-action/ && cp -r $GITHUB_ACTION_PATH/../* ./self-lint-action/
- id: setup-node
if: inputs.container != 'true'
uses: ./self-lint-action/setup-node
with:
working-directory: ${{ inputs.working-directory }}
dependencies-cache: |
nx
prettier
- id: get-package-manager
if: inputs.container == 'true'
uses: ./self-lint-action/get-package-manager
with:
working-directory: ${{ inputs.working-directory }}
- id: run-lint
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
RUN_LINT_COMMAND: ${{ inputs.container == 'true' && steps.get-package-manager.outputs.run-script-command || steps.setup-node.outputs.run-script-command }}
WORKING_DIRECTORY: ${{ inputs.working-directory }}
LINT_COMMAND: ${{ inputs.command }}
with:
script: |
const fs = require('node:fs');
const workingDirectory = process.env.WORKING_DIRECTORY;
if (!fs.existsSync(workingDirectory)) {
core.setFailed(`The specified working directory does not exist: ${workingDirectory}`);
return;
}
core.debug(`Running in working directory: ${workingDirectory}`);
process.chdir(workingDirectory);
const runScriptCommand = process.env.RUN_LINT_COMMAND;
const lintCommand = process.env.LINT_COMMAND || 'lint:ci';
core.info(`👕 Running lint command: ${lintCommand}...`);
try {
const exitCode = await exec.exec(runScriptCommand, [lintCommand], {
cwd: workingDirectory,
ignoreReturnCode: true
});
core.setOutput('lint-exit-code', exitCode);
if (exitCode !== 0) {
core.setFailed(`Linting failed with exit code ${exitCode}`);
}
} catch (error) {
core.setOutput('lint-exit-code', 1);
core.setFailed(`Linting error: ${error.message}`);
}
- name: 📊 Parse lint reports
if: always()
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@c314229c3ca6914f7023ffca7afc26753ab99b41 # 0.30.1
with:
working-directory: ${{ inputs.working-directory }}
report-paths: ${{ inputs.report-file || 'auto:lint' }}
path-mapping: ${{ inputs.path-mapping }}
report-name: "Lint Results"
output-format: "annotations,summary"
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
- shell: bash
if: always()
run: rm -fr ./self-lint-action