-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
142 lines (127 loc) · 5.53 KB
/
action.yml
File metadata and controls
142 lines (127 loc) · 5.53 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: "Test"
description: "Action to test Node.js projects with support for coverage reporting and pull request annotations"
author: hoverkraft
branding:
icon: check-square
color: blue
inputs:
working-directory:
description: |
Working directory where test 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/package manager script command to run for testing.
This should be a script defined in your package.json.
The command should generate coverage report files in a standard format (Cobertura XML, lcov, etc.).
required: false
default: "test:ci"
coverage:
description: |
Code coverage reporter to use. Supported values:
- `github`: Parse coverage reports via [parse-ci-reports](https://hoverkraft-tech/ci-github-common/actions/parse-ci-reports) action, with GitHub summaries/PR comments
- `codecov`: Upload coverage to Codecov
- `""` or `null`: No coverage reporting
required: false
default: "github"
coverage-files:
description: |
Optional coverage report paths forwarded to the hoverkraft-tech/ci-github-common/actions/parse-ci-reports action.
Supports multiple formats (Cobertura, OpenCover, lcov, etc.).
Provide absolute paths or paths relative to the working directory.
Multiple entries can be separated by newlines, commas, or semicolons.
When omitted, the action falls back to "auto:test" detection (LCOV / Cobertura / Clover).
required: false
default: ""
github-token:
description: |
GitHub token for coverage PR comments.
Required when coverage is set to `github`.
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-test-action/ && cp -r $GITHUB_ACTION_PATH/../* ./self-test-action/
- id: setup-node
if: inputs.container != 'true'
uses: ./self-test-action/setup-node
with:
working-directory: ${{ inputs.working-directory }}
dependencies-cache: |
nx
jest
- id: get-package-manager
if: inputs.container == 'true'
uses: ./self-test-action/get-package-manager
with:
working-directory: ${{ inputs.working-directory }}
- id: run-test
name: 🧪 Run tests
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
RUN_TEST_COMMAND: ${{ inputs.container == 'true' && steps.get-package-manager.outputs.run-script-command || steps.setup-node.outputs.run-script-command }}
WORKING_DIRECTORY: ${{ inputs.working-directory }}
TEST_COMMAND: ${{ inputs.command }}
with:
script: |
const workingDirectory = process.env.WORKING_DIRECTORY || '.';
const runScriptCommand = process.env.RUN_TEST_COMMAND;
const testCommand = process.env.TEST_COMMAND || 'test:ci';
core.info(`🧪 Running test command: ${testCommand}...`);
try {
const result = await exec.getExecOutput(runScriptCommand, [testCommand], {
cwd: require('path').resolve(process.env.GITHUB_WORKSPACE, workingDirectory),
env: { ...process.env, CI: 'true' },
ignoreReturnCode: true
});
if (result.stdout) core.info(result.stdout);
if (result.stderr) core.warning(result.stderr);
core.setOutput('test-exit-code', result.exitCode);
if (result.exitCode !== 0) {
core.setFailed(`Tests failed with exit code ${result.exitCode}`);
}
} catch (error) {
core.setOutput('test-exit-code', 1);
core.setFailed(`Test execution error: ${error.message}`);
}
- name: 📊 Parse coverage reports
if: always() && inputs.coverage == 'github'
id: parse-coverage-reports
uses: hoverkraft-tech/ci-github-common/actions/parse-ci-reports@c314229c3ca6914f7023ffca7afc26753ab99b41 # 0.30.1
with:
report-paths: ${{ inputs.coverage-files || 'auto:test' }}
report-name: "Coverage Results"
output-format: "summary,markdown"
- name: 📊 Add coverage PR comment
if: always() && inputs.coverage == 'github' && github.event_name == 'pull_request' && steps.parse-coverage-reports.outputs.markdown
uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@c314229c3ca6914f7023ffca7afc26753ab99b41 # 0.30.1
with:
title: "Code Coverage Report"
body: ${{ steps.parse-coverage-reports.outputs.markdown }}
# Install dependencies for codecov in container mode
- name: Install Codecov dependencies
if: inputs.coverage == 'codecov' && inputs.container == 'true'
uses: pkgxdev/setup@f211ee4db3110b42e5a156282372527e7c1ed723 # v4.0.0
with:
+: git curl gnupg.org
- name: 📊 Upload coverage to Codecov
if: always() && inputs.coverage == 'codecov'
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
working-directory: ${{ inputs.working-directory }}
use_oidc: true
disable_telem: true
fail_ci_if_error: false
# FIXME: workaround until will be merged: https://github.com/actions/runner/pull/1684
- shell: bash
if: always()
run: rm -fr ./self-test-action