-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
195 lines (172 loc) · 7.46 KB
/
action.yml
File metadata and controls
195 lines (172 loc) · 7.46 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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"
coverage:
description: |
Code coverage reporter to use. Supported values:
- `github`: Use ReportGenerator for PR comments with coverage reports
- `codecov`: Upload coverage to Codecov
- `""` or `null`: No coverage reporting
required: false
default: "github"
coverage-files:
description: |
Path to coverage files for reporting.
Supports multiple formats (Cobertura, OpenCover, lcov, etc.).
Can be a single file or multiple files separated by semicolons.
If not specified, auto-detection will be attempted for common paths:
- coverage/cobertura-coverage.xml, coverage/coverage.xml
- coverage/lcov.info
- coverage/clover.xml
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 }}
with:
script: |
const workingDirectory = process.env.WORKING_DIRECTORY || '.';
const runScriptCommand = process.env.RUN_TEST_COMMAND;
try {
const result = await exec.getExecOutput(runScriptCommand, ['test:ci'], {
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}`);
}
# Auto-detect coverage files if not specified
- id: detect-coverage-files
if: always() && inputs.coverage == 'github'
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
WORKING_DIRECTORY: ${{ inputs.working-directory }}
COVERAGE_FILES: ${{ inputs.coverage-files }}
with:
script: |
const path = require('node:path');
const fs = require('node:fs');
const workingDirectory = process.env.WORKING_DIRECTORY || '.';
const workDir = path.resolve(process.env.GITHUB_WORKSPACE, workingDirectory);
if (process.env.COVERAGE_FILES && process.env.COVERAGE_FILES.trim() !== '') {
core.info(`Using specified coverage files: ${process.env.COVERAGE_FILES}`);
core.setOutput('coverage-files', process.env.COVERAGE_FILES);
return;
}
// Common coverage file paths
const commonPaths = [
'coverage/cobertura-coverage.xml',
'coverage/coverage.xml',
'coverage/lcov.info',
'coverage/clover.xml',
'coverage/coverage-final.json',
'test-results/coverage.xml',
'test-results/cobertura-coverage.xml'
];
for (const filePath of commonPaths) {
const fullPath = path.join(workDir, filePath);
if (fs.existsSync(fullPath)) {
core.info(`Auto-detected coverage file: ${fullPath}`);
core.setOutput('coverage-files', fullPath);
return;
}
}
core.warning('No coverage file auto-detected');
# ReportGenerator for PR comments with coverage reports
- name: 📊 Generate coverage report
if: always() && inputs.coverage == 'github' && steps.detect-coverage-files.outputs.coverage-files
uses: danielpalme/ReportGenerator-GitHub-Action@dcdfb6e704e87df6b2ed0cf123a6c9f69e364869 # v5.5.0
with:
reports: ${{ steps.detect-coverage-files.outputs.coverage-files }}
targetdir: ${{ runner.temp }}/coveragereport-${{ github.run_id }}
reporttypes: MarkdownSummaryGithub
sourcedirs: ${{ inputs.working-directory }}
- if: always() && inputs.coverage == 'github'
id: get-coverage-report-summary
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
env:
SUMMARY_FILE: ${{ runner.temp }}/coveragereport-${{ github.run_id }}/SummaryGithub.md
with:
script: |
const fs = require('fs');
const summaryFilePath = process.env.SUMMARY_FILE;
if (!fs.existsSync(summaryFilePath)) {
return core.setFailed(`Coverage summary file not found: ${summaryFilePath}`);
}
const summaryContent = fs.readFileSync(summaryFilePath, 'utf8');
core.summary.addRaw(summaryContent).write();
core.setOutput('summary-content', summaryContent);
- name: 📊 Add coverage PR comment
if: always() && steps.get-coverage-report-summary.outputs.summary-content && github.event_name == 'pull_request'
uses: hoverkraft-tech/ci-github-common/actions/create-or-update-comment@1127e708e4072515056a4b0d26bcb0653646cedc # 0.30.0
with:
title: "Code Coverage Report"
body: ${{ steps.get-coverage-report-summary.outputs.summary-content }}
# 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