-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
371 additions
and
21 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { getContext, getInputs, makeLogger, setFailed } from './github.js'; | ||
import { getReport } from './report.js'; | ||
|
||
(async() => { | ||
const logger = makeLogger(); | ||
|
||
try { | ||
getContext(logger); | ||
await getInputs(logger); | ||
} catch (err) { | ||
logger.endGroup(); | ||
const context = getContext(logger); | ||
const inputs = await getInputs(logger); | ||
|
||
await getReport(logger, context, inputs); | ||
} catch (err) { | ||
setFailed(err.message); | ||
|
||
logger.endGroup(); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import Ajv from 'ajv'; | ||
import addFormats from 'ajv-formats'; | ||
import fs from 'fs/promises'; | ||
|
||
const ajv = new Ajv({ verbose: true }); | ||
|
||
addFormats(ajv, ['uuid', 'uri']); | ||
|
||
const schema = { | ||
type: 'object', | ||
properties: { | ||
reportId: { type: 'string', format: 'uuid' }, | ||
reportVersion: { type: 'integer', const: 1 }, | ||
summary: { | ||
type: 'object', | ||
properties: { | ||
githubOrganization: { type: 'string', pattern: '[A-Za-z0-9_.-]+' }, | ||
githubRepository: { type: 'string', pattern: '[A-Za-z0-9_.-]+' }, | ||
githubWorkflow: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
githubRunId: { type: 'integer', minimum: 0 }, | ||
githubRunAttempt: { type: 'integer', minimum: 1 }, | ||
gitBranch: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
gitSha: { type: 'string', pattern: '([A-Fa-f0-9]{40})' }, | ||
lmsBuild: { type: 'string', pattern: '([0-9]{2}\\.){3}[0-9]{5}' }, | ||
lmsInstance: { type: 'string', format: 'uri' }, | ||
operatingSystem: { type: 'string', enum: ['windows', 'linux', 'mac'] }, | ||
framework: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
started: { type: 'integer', minimum: 0 }, | ||
totalDuration: { type: 'integer', minimum: 0 }, | ||
status: { type: 'string', enum: ['passed', 'failed'] }, | ||
countPassed: { type: 'integer', minimum: 0 }, | ||
countFailed: { type: 'integer', minimum: 0 }, | ||
countSkipped: { type: 'integer', minimum: 0 }, | ||
countFlaky: { type: 'integer', minimum: 0 }, | ||
}, | ||
required: [ | ||
'githubOrganization', | ||
'githubRepository', | ||
'githubWorkflow', | ||
'githubRunId', | ||
'githubRunAttempt', | ||
'gitBranch', | ||
'gitSha', | ||
'operatingSystem', | ||
'framework', | ||
'started', | ||
'totalDuration', | ||
'status', | ||
'countPassed', | ||
'countFailed', | ||
'countSkipped', | ||
'countFlaky' | ||
], | ||
additionalProperties: false | ||
}, | ||
details: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
name: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
location: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
started: { type: 'integer', minimum: 0 }, | ||
duration: { type: 'integer', minimum: 0 }, | ||
totalDuration: { type: 'integer', minimum: 0 }, | ||
status: { type: 'string', enum: ['passed', 'failed', 'skipped'] }, | ||
tool: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
experience: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
type: { type: 'string', pattern: '^[^\\s].+[^\\s]$' }, | ||
browser: { type: 'string', enum: ['chromium', 'firefox ', 'webkit'] }, | ||
retries: { type: 'integer', minimum: 0 } | ||
}, | ||
required: [ | ||
'name', | ||
'location', | ||
'started', | ||
'duration', | ||
'totalDuration', | ||
'status', | ||
'retries' | ||
], | ||
additionalProperties: false | ||
} | ||
} | ||
}, | ||
required: [ | ||
'reportId', | ||
'reportVersion', | ||
'summary', | ||
'details' | ||
], | ||
additionalProperties: false | ||
}; | ||
|
||
const validate = ajv.compile(schema); | ||
|
||
const getReport = async(logger, context, inputs) => { | ||
logger.startGroup('Gathering test report'); | ||
|
||
const { reportPath } = inputs; | ||
let report; | ||
|
||
try { | ||
const reportRaw = await fs.readFile(reportPath, 'utf8'); | ||
|
||
report = JSON.parse(reportRaw); | ||
} catch { | ||
throw new Error('Report is not valid'); | ||
} | ||
|
||
logger.info('Injecting GitHub context'); | ||
|
||
report.summary = { | ||
...context, | ||
...report.summary | ||
}; | ||
|
||
logger.info('Validating test report'); | ||
|
||
if (!validate(report)) { | ||
const message = ajv.errorsText(validate.errors, { dataVar: 'report' }); | ||
|
||
throw new Error(`Report does not conform to needed schema: ${message}`); | ||
} | ||
|
||
logger.endGroup(); | ||
|
||
return report; | ||
}; | ||
|
||
export { getReport }; |
Oops, something went wrong.