Skip to content

Commit 9d179e6

Browse files
committedJun 6, 2023
feat(workflow): enabled creation of the workflow when the project doesnt have other workflows
1 parent 85c30f6 commit 9d179e6

File tree

7 files changed

+30
-14
lines changed

7 files changed

+30
-14
lines changed
 

‎package-lock.json

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

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"husky": "8.0.3",
6767
"jest-when": "3.5.2",
6868
"lockfile-lint": "4.10.5",
69-
"make-dir": "3.1.0",
7069
"mock-fs": "5.2.0",
7170
"npm-run-all": "4.1.5",
7271
"publint": "0.1.12",
@@ -79,6 +78,7 @@
7978
"vitest": "0.31.3"
8079
},
8180
"dependencies": {
82-
"js-yaml": "^4.1.0"
81+
"js-yaml": "^4.1.0",
82+
"make-dir": "^3.1.0"
8383
}
8484
}

‎src/workflow/scaffolder.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {promises as fs} from 'node:fs';
22
import {dump} from 'js-yaml';
3+
import mkdir from 'make-dir';
34

45
export default async function ({projectRoot}) {
56
await fs.writeFile(
6-
`${projectRoot}/.github/workflows/scorecard.yml`,
7+
`${await mkdir(`${projectRoot}/.github/workflows`)}/scorecard.yml`,
78
dump({
89
name: 'OpenSSF Scorecard',
910
on: {

‎src/workflow/scaffolder.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {promises as fs} from 'node:fs';
22
import jsYaml from 'js-yaml';
3+
import mkdir from 'make-dir';
34

45
import {afterEach, expect, describe, it, vi} from 'vitest';
56
import any from '@travi/any';
@@ -9,6 +10,7 @@ import scaffold from './scaffolder.js';
910

1011
vi.mock('node:fs');
1112
vi.mock('js-yaml');
13+
vi.mock('make-dir');
1214

1315
describe('workflow scaffolder', () => {
1416
const projectRoot = any.string();
@@ -19,7 +21,9 @@ describe('workflow scaffolder', () => {
1921

2022
it('should scaffold the scorecard workflow', async () => {
2123
const dumpedYaml = any.string();
24+
const pathToCreatedWorkflowsDirectory = any.string();
2225

26+
when(mkdir).calledWith(`${projectRoot}/.github/workflows`).mockResolvedValue(pathToCreatedWorkflowsDirectory);
2327
when(jsYaml.dump)
2428
.calledWith({
2529
name: 'OpenSSF Scorecard',
@@ -73,6 +77,6 @@ describe('workflow scaffolder', () => {
7377

7478
await scaffold({projectRoot});
7579

76-
expect(fs.writeFile).toHaveBeenCalledWith(`${projectRoot}/.github/workflows/scorecard.yml`, dumpedYaml);
80+
expect(fs.writeFile).toHaveBeenCalledWith(`${pathToCreatedWorkflowsDirectory}/scorecard.yml`, dumpedYaml);
7781
});
7882
});

‎test/integration/features/scaffolder.feature

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
Feature: Scaffolder
22

3-
Scenario: Scaffold a GitHub project
3+
Scenario: Scaffold a GitHub project where other workflows already exist
44
Given the project is hosted on "GitHub"
5+
And Actions workflows exist
6+
When the project is scaffolded
7+
Then the score badge is added to the status zone
8+
And the workflow is defined
9+
10+
Scenario: Scaffold a GitHub project where no other workflows exist
11+
Given the project is hosted on "GitHub"
12+
But no Actions workflows exist
513
When the project is scaffolded
614
Then the score badge is added to the status zone
715
And the workflow is defined
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import mkdir from 'make-dir';
2-
31
import {Given} from '@cucumber/cucumber';
42

53
Given('the project is hosted on {string}', async function (vcsHost) {
64
this.vcsHost = vcsHost.toLowerCase();
7-
8-
await mkdir(`${this.projectRoot}/.github/workflows`);
95
});

‎test/integration/features/step_definitions/workflow-steps.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import {fileExists} from '@form8ion/core';
2+
import mkdir from 'make-dir';
23

3-
import {Then} from '@cucumber/cucumber';
4+
import {Given, Then} from '@cucumber/cucumber';
45
import {assert} from 'chai';
56

7+
Given('Actions workflows exist', async function () {
8+
await mkdir(`${this.projectRoot}/.github/workflows`);
9+
});
10+
11+
Given('no Actions workflows exist', async function () {
12+
return undefined;
13+
});
14+
615
Then('the workflow is defined', async function () {
716
assert.isTrue(await fileExists(`${this.projectRoot}/.github/workflows/scorecard.yml`));
817
});

0 commit comments

Comments
 (0)
Please sign in to comment.