Skip to content

Commit ca45944

Browse files
committed
feat(workflow): defined the details of the generated workflow
1 parent 1f0b2ee commit ca45944

File tree

5 files changed

+146
-6
lines changed

5 files changed

+146
-6
lines changed

package-lock.json

+38-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"devDependencies": {
5353
"@cucumber/cucumber": "9.1.2",
5454
"@form8ion/commitlint-config": "1.0.51",
55+
"@form8ion/core": "2.0.0",
5556
"@form8ion/eslint-config": "5.0.32",
5657
"@form8ion/eslint-config-cucumber": "1.4.1",
5758
"@form8ion/remark-lint-preset": "5.0.9",

src/scaffolder.js

+55-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,61 @@ import {promises as fs} from 'node:fs';
22
import {dump} from 'js-yaml';
33

44
export default async function ({projectRoot, vcs: {owner, name, host}}) {
5-
await fs.writeFile(`${projectRoot}/.github/workflows/scorecard.yml`, dump({}));
5+
await fs.writeFile(
6+
`${projectRoot}/.github/workflows/scorecard.yml`,
7+
dump({
8+
name: 'OpenSSF Scorecard',
9+
on: {
10+
// To guarantee Maintained check is occasionally updated.
11+
// See https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
12+
schedule: [{cron: '31 2 * * 1'}],
13+
push: {branches: ['master']}
14+
},
15+
permissions: 'read-all',
16+
jobs: {
17+
analysis: {
18+
name: 'Scorecard analysis',
19+
'runs-on': 'ubuntu-latest',
20+
permissions: {
21+
// Needed to upload the results to code-scanning dashboard.
22+
'security-events': 'write',
23+
// Needed to publish results and get a badge (see publish_results below).
24+
'id-token': 'write'
25+
},
26+
steps: [
27+
{
28+
name: 'Checkout code',
29+
uses: 'actions/[email protected]',
30+
with: {'persist-credentials': false}
31+
},
32+
{
33+
name: 'Run analysis',
34+
uses: 'ossf/[email protected]',
35+
with: {
36+
results_file: 'results.sarif',
37+
results_format: 'sarif',
38+
publish_results: true
39+
}
40+
},
41+
{
42+
name: 'Upload artifact',
43+
uses: 'actions/[email protected]',
44+
with: {
45+
name: 'SARIF file',
46+
path: 'results.sarif',
47+
'retention-days': 5
48+
}
49+
},
50+
{
51+
name: 'Upload to code-scanning',
52+
uses: 'github/codeql-action/[email protected]',
53+
with: {sarif_file: 'results.sarif'}
54+
}
55+
]
56+
}
57+
}
58+
})
59+
);
660

761
return {
862
...'github' === host && {

src/scaffolder.test.js

+50-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,56 @@ describe('scaffolder', () => {
2121
});
2222

2323
it('should return scaffolding results', async () => {
24-
when(jsYaml.dump).calledWith({}).mockReturnValue(dumpedYaml);
24+
when(jsYaml.dump)
25+
.calledWith({
26+
name: 'OpenSSF Scorecard',
27+
on: {
28+
schedule: [{cron: '31 2 * * 1'}],
29+
push: {branches: ['master']}
30+
},
31+
permissions: 'read-all',
32+
jobs: {
33+
analysis: {
34+
name: 'Scorecard analysis',
35+
'runs-on': 'ubuntu-latest',
36+
permissions: {
37+
'security-events': 'write',
38+
'id-token': 'write'
39+
},
40+
steps: [
41+
{
42+
name: 'Checkout code',
43+
uses: 'actions/[email protected]',
44+
with: {'persist-credentials': false}
45+
},
46+
{
47+
name: 'Run analysis',
48+
uses: 'ossf/[email protected]',
49+
with: {
50+
results_file: 'results.sarif',
51+
results_format: 'sarif',
52+
publish_results: true
53+
}
54+
},
55+
{
56+
name: 'Upload artifact',
57+
uses: 'actions/[email protected]',
58+
with: {
59+
name: 'SARIF file',
60+
path: 'results.sarif',
61+
'retention-days': 5
62+
}
63+
},
64+
{
65+
name: 'Upload to code-scanning',
66+
uses: 'github/codeql-action/[email protected]',
67+
with: {sarif_file: 'results.sarif'}
68+
}
69+
]
70+
}
71+
}
72+
})
73+
.mockReturnValue(dumpedYaml);
2574

2675
expect(await scaffold({projectRoot, vcs: {owner, name, host: 'github'}}))
2776
.toEqual({
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import {promises as fs} from 'node:fs';
2-
import {load} from 'js-yaml';
1+
import {fileExists} from '@form8ion/core';
32

43
import {Then} from '@cucumber/cucumber';
54
import {assert} from 'chai';
65

76
Then('the workflow is defined', async function () {
8-
assert.deepEqual(load(await fs.readFile(`${this.projectRoot}/.github/workflows/scorecard.yml`, 'utf-8')), {});
7+
assert.isTrue(await fileExists(`${this.projectRoot}/.github/workflows/scorecard.yml`));
98
});

0 commit comments

Comments
 (0)