-
Notifications
You must be signed in to change notification settings - Fork 0
236 lines (236 loc) · 9.8 KB
/
Copy pathci.yml
File metadata and controls
236 lines (236 loc) · 9.8 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
name: CI
permissions:
contents: read
on: pull_request
concurrency:
group: ${{github.workflow_ref}}
cancel-in-progress: true
jobs:
lint:
name: Lint
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: Brightspace/third-party-actions@actions/checkout
- name: Set up node
uses: Brightspace/setup-node@main
with:
node-version-file: .nvmrc
cache: npm
d2l-registry-token: ${{ secrets.D2L_PACKAGE_REGISTRY_AUTH_TOKEN }}
- name: Install dependencies
run: npm ci
- parallel:
- name: Lint (ESLint)
run: npm run lint:eslint
- name: Lint (EditorConfig)
run: npm run lint:editorconfig
licenses:
name: Check Licenses
timeout-minutes: 5
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: Brightspace/third-party-actions@actions/checkout
- name: Set up node
uses: Brightspace/setup-node@main
with:
node-version-file: .nvmrc
cache: npm
d2l-registry-token: ${{ secrets.D2L_PACKAGE_REGISTRY_AUTH_TOKEN }}
- name: Install dependencies
run: npm ci
- name: Check licenses
run: npm run license-check
test:
name: Test
timeout-minutes: 15
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: Brightspace/third-party-actions@actions/checkout
- name: Set up node
uses: Brightspace/setup-node@main
with:
node-version-file: .nvmrc
cache: npm
d2l-registry-token: ${{ secrets.D2L_PACKAGE_REGISTRY_AUTH_TOKEN }}
- name: Install dependencies (npm)
run: npm ci
- name: Install dependencies (Playwright)
run: npx playwright install --with-deps
- name: Setup dependencies (WebdriverIO)
run: |
/usr/bin/chromedriver --version
echo "CHROMEDRIVER_PATH=/usr/bin/chromedriver" >> $GITHUB_ENV
- name: Run tests
id: tests
run: npm run test:all
- name: Generate coverage info
if: >
!cancelled() && github.actor != 'dependabot[bot]' && (
steps.tests.conclusion == 'failure' ||
steps.tests.outcome == 'success'
)
id: coverage
run: |
SOURCE='./coverage/lcov-report/'
if [ ! -f "$SOURCE/index.html" ]; then
echo "No coverage report found."
exit 1
fi
COMMON_PATH="$GITHUB_REPOSITORY/$GITHUB_RUN_ID/$GITHUB_RUN_ATTEMPT/$GITHUB_JOB"
DESTINATION="s3://test-reporting-coverage/$COMMON_PATH/"
URL="https://test-reporting.d2l.dev/coverage/$COMMON_PATH/"
echo "destination=$DESTINATION" >> $GITHUB_OUTPUT
echo "source=$SOURCE" >> $GITHUB_OUTPUT
echo "url=$URL" >> $GITHUB_OUTPUT
- name: Assume role
if: (!cancelled()) && steps.coverage.outputs.source != ''
uses: Brightspace/third-party-actions@aws-actions/configure-aws-credentials
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws-session-token: ${{secrets.AWS_SESSION_TOKEN}}
aws-region: us-east-1
role-to-assume: arn:aws:iam::427469055187:role/github+Brightspace+test-reporting-node
role-duration-seconds: 3600
- name: Upload coverage
if: (!cancelled()) && steps.coverage.outputs.source != ''
uses: BrightspaceUI/actions/publish-to-s3@main
with:
bucket-path: ${{steps.coverage.outputs.destination}}
publish-directory: ${{steps.coverage.outputs.source}}
- name: Report test results (Unit)
if: (!cancelled()) && github.actor != 'dependabot[bot]'
uses: Brightspace/test-reporting-action@main
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws-session-token: ${{secrets.AWS_SESSION_TOKEN}}
- name: Report test results (Validation)
if: (!cancelled()) && github.actor != 'dependabot[bot]'
uses: Brightspace/test-reporting-action@main
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws-session-token: ${{secrets.AWS_SESSION_TOKEN}}
report-path: ./d2l-test-report-validation.json
- name: Upload test reports and generate summary
id: summary
if: >
!cancelled() && (
steps.tests.conclusion == 'failure' ||
steps.tests.outcome == 'success'
)
uses: Brightspace/third-party-actions@actions/github-script
with:
script: |
const { existsSync } = await import('node:fs');
const { join } = await import('node:path');
const { pathToFileURL } = await import('node:url');
const { env } = await import('node:process');
const {
COVERAGE_REPORT_URL: coverageReportUrl,
REPORT_VALIDATION_RESULTS: reportValidationResultsPath,
GITHUB_SERVER_URL,
GITHUB_REPOSITORY,
GITHUB_RUN_ID,
GITHUB_WORKSPACE
} = env;
const artifactEntry = join(GITHUB_WORKSPACE, 'node_modules', '@actions', 'artifact', 'lib', 'artifact.js');
const { DefaultArtifactClient } = await import(pathToFileURL(artifactEntry).href);
const client = new DefaultArtifactClient();
const reportFile = (framework) => `d2l-test-report-${framework.replace('@', '').replace('/', '-')}.json`;
// Reconstruct per-framework validation results from report details
const validationResults = {};
if (existsSync(reportValidationResultsPath)) {
const reportData = require(reportValidationResultsPath);
if (reportData.details && Array.isArray(reportData.details)) {
for (const detail of reportData.details) {
const nameParts = detail.name.split(' > ');
if (nameParts.length === 3 && nameParts[0] === 'report validation') {
const framework = nameParts[1];
const check = nameParts[2];
if (['exists', 'schema', 'contents'].includes(check)) {
validationResults[framework] = validationResults[framework] || {
exists: false,
schema: false,
contents: false
};
validationResults[framework][check] = detail.status === 'passed';
}
}
}
}
}
// Upload each report up front so summary generation has no async gaps
const reportArtifactUrls = {};
for (const framework of Object.keys(validationResults)) {
const file = reportFile(framework);
if (existsSync(file)) {
const { id } = await client.uploadArtifact(file, [file], process.cwd(), { skipArchive: true });
reportArtifactUrls[framework] = `${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/artifacts/${id}`;
}
}
const { summary } = core;
summary.clear();
summary.addHeading('Coverage Report', 3);
if (coverageReportUrl) {
summary.addLink('Report', coverageReportUrl);
} else {
summary.addRaw('No coverage report generated.', true);
summary.addEOL();
}
summary.addHeading('Report Validation', 3);
if (Object.keys(validationResults).length > 0) {
for (const [framework, result] of Object.entries(validationResults)) {
const { exists, schema, contents } = result;
const reportArtifactUrl = reportArtifactUrls[framework];
const failed = !exists || !schema || !contents;
const headerIcon = failed ? ':red_circle:' : ':green_circle:';
const header = `<code>${framework}</code> ${headerIcon}`;
let body = '<br/>\n\n';
if (exists) {
const schemaIcon = schema ? ':green_circle:' : ':red_circle:';
const contentsIcon = contents ? ':green_circle:' : ':red_circle:';
body += `Schema: ${schema ? '**PASSED**' : '**FAILED**'} ${schemaIcon}\n`;
body += `Contents: ${contents ? '**PASSED**' : '**FAILED**'} ${contentsIcon}\n`;
if (reportArtifactUrl) {
body += `\n[Report](${reportArtifactUrl})\n`;
}
} else {
body += 'No report generated :fire:';
}
body += '\n\n';
summary.addDetails(header, body);
}
} else {
summary.addRaw('No report validation results found :fire:', true);
}
const report = summary.stringify();
core.setOutput('report', report);
await summary.write({ overwrite: true });
env:
COVERAGE_REPORT_URL: ${{steps.coverage.outputs.url}}
REPORT_VALIDATION_RESULTS: ./d2l-test-report-validation.json
- name: Leave comment
if: (!cancelled()) && steps.summary.outcome == 'success'
uses: BrightspaceUI/actions/comment-on-pr@main
with:
message: ${{steps.summary.outputs.report}}
post-mode: hide-previous
label:
name: Label
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
timeout-minutes: 5
steps:
- name: Apply labels
uses: Brightspace/third-party-actions@actions/labeler