Skip to content

Commit 3752b51

Browse files
committed
feat(lift): added the release workflow when not already defined
if the ci provider is github actions
1 parent 455bf2d commit 3752b51

File tree

15 files changed

+441
-98
lines changed

15 files changed

+441
-98
lines changed

package-lock.json

Lines changed: 215 additions & 93 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
"sinon": "12.0.1"
8484
},
8585
"dependencies": {
86+
"@form8ion/core": "^1.4.2",
8687
"@form8ion/javascript-core": "^4.0.0",
87-
"deepmerge": "^4.2.2"
88+
"deepmerge": "^4.2.2",
89+
"js-yaml": "^4.1.0"
8890
}
8991
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export {default as scaffold} from './scaffolder';
2+
export {default as test} from './tester';
3+
export {default as lift} from './lifter';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as core from '@form8ion/core';
2+
3+
import any from '@travi/any';
4+
import {assert} from 'chai';
5+
import sinon from 'sinon';
6+
7+
import * as scaffolder from './scaffolder';
8+
import lift from './lifter';
9+
10+
suite('github-workflows lifter for semantic-release', () => {
11+
let sandbox;
12+
const projectRoot = any.string();
13+
14+
setup(() => {
15+
sandbox = sinon.createSandbox();
16+
17+
sandbox.stub(core, 'fileExists');
18+
sandbox.stub(scaffolder, 'default');
19+
});
20+
21+
teardown(() => sandbox.restore());
22+
23+
test('that the release workflow is added if it doesnt already exist', async () => {
24+
core.fileExists.resolves(false);
25+
26+
await lift({projectRoot});
27+
28+
assert.calledWith(scaffolder.default, {projectRoot});
29+
});
30+
31+
test('that the release workflow is not added if it already exists', async () => {
32+
core.fileExists.withArgs(`${projectRoot}/.github/workflows/release.yml`).resolves(true);
33+
34+
await lift({projectRoot});
35+
36+
assert.notCalled(scaffolder.default);
37+
});
38+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import {fileExists} from '@form8ion/core';
2+
3+
import scaffoldReleaseWorkflow from './scaffolder';
4+
5+
export default async function ({projectRoot}) {
6+
if (!await fileExists(`${projectRoot}/.github/workflows/release.yml`)) {
7+
await scaffoldReleaseWorkflow({projectRoot});
8+
}
9+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import {promises as fs} from 'fs';
2+
import jsYaml from 'js-yaml';
3+
4+
import {assert} from 'chai';
5+
import sinon from 'sinon';
6+
import any from '@travi/any';
7+
8+
import scaffoldReleaseWorkflow from './scaffolder';
9+
10+
suite('github release workflow scaffolder', () => {
11+
let sandbox;
12+
13+
setup(() => {
14+
sandbox = sinon.createSandbox();
15+
16+
sandbox.stub(fs, 'writeFile');
17+
sandbox.stub(jsYaml, 'dump');
18+
});
19+
20+
teardown(() => sandbox.restore());
21+
22+
test('that release workflow is defined', async () => {
23+
const projectRoot = any.string();
24+
const workflowsDirectory = `${projectRoot}/.github/workflows`;
25+
const dumpedWorkflowYaml = any.simpleObject();
26+
jsYaml.dump
27+
.withArgs({
28+
on: {push: {branches: ['alpha']}, workflow_dispatch: {}},
29+
env: {FORCE_COLOR: 1, NPM_CONFIG_COLOR: 'always'},
30+
jobs: {
31+
release: {
32+
'runs-on': 'ubuntu-latest',
33+
steps: [
34+
{uses: 'actions/checkout@v2'},
35+
{
36+
name: 'Setup node',
37+
uses: 'actions/setup-node@v2',
38+
with: {'node-version-file': '.nvmrc', cache: 'npm'}
39+
},
40+
{run: 'npm clean-install'},
41+
{
42+
name: 'semantic-release',
43+
run: 'npx semantic-release',
44+
env: {
45+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}', // eslint-disable-line no-template-curly-in-string
46+
NPM_TOKEN: '${{ secrets.NPM_PUBLISH_TOKEN }}' // eslint-disable-line no-template-curly-in-string
47+
}
48+
}
49+
]
50+
}
51+
}
52+
})
53+
.returns(dumpedWorkflowYaml);
54+
55+
await scaffoldReleaseWorkflow({projectRoot});
56+
57+
assert.calledWith(fs.writeFile, `${workflowsDirectory}/release.yml`, dumpedWorkflowYaml);
58+
});
59+
});
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import {promises as fs} from 'fs';
2+
import {dump} from 'js-yaml';
3+
4+
export default async function ({projectRoot}) {
5+
await fs.writeFile(
6+
`${projectRoot}/.github/workflows/release.yml`,
7+
dump({
8+
on: {push: {branches: ['alpha']}, workflow_dispatch: {}},
9+
env: {FORCE_COLOR: 1, NPM_CONFIG_COLOR: 'always'},
10+
jobs: {
11+
release: {
12+
'runs-on': 'ubuntu-latest',
13+
steps: [
14+
{uses: 'actions/checkout@v2'},
15+
{
16+
name: 'Setup node',
17+
uses: 'actions/setup-node@v2',
18+
with: {'node-version-file': '.nvmrc', cache: 'npm'}
19+
},
20+
{run: 'npm clean-install'},
21+
{
22+
name: 'semantic-release',
23+
run: 'npx semantic-release',
24+
env: {
25+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}', // eslint-disable-line no-template-curly-in-string
26+
NPM_TOKEN: '${{ secrets.NPM_PUBLISH_TOKEN }}' // eslint-disable-line no-template-curly-in-string
27+
}
28+
}
29+
]
30+
}
31+
}
32+
})
33+
);
34+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as core from '@form8ion/core';
2+
3+
import any from '@travi/any';
4+
import sinon from 'sinon';
5+
import {assert} from 'chai';
6+
import projectUsesGithubWorkflows from './tester';
7+
8+
suite('GitHub workflows predicate', () => {
9+
const projectRoot = any.string();
10+
let sandbox;
11+
12+
setup(() => {
13+
sandbox = sinon.createSandbox();
14+
15+
sandbox.stub(core, 'directoryExists');
16+
});
17+
18+
teardown(() => sandbox.restore());
19+
20+
test('that `true` is returned when the project uses GitHub workflows', async () => {
21+
core.directoryExists.withArgs(`${projectRoot}/.github/workflows`).resolves(true);
22+
23+
assert.isTrue(await projectUsesGithubWorkflows({projectRoot}));
24+
});
25+
26+
test('that `false` is returned when the project uses GitHub workflows', async () => {
27+
core.directoryExists.resolves(false);
28+
29+
assert.isFalse(await projectUsesGithubWorkflows({projectRoot}));
30+
});
31+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import {directoryExists} from '@form8ion/core';
2+
3+
export default function ({projectRoot}) {
4+
return directoryExists(`${projectRoot}/.github/workflows`);
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {lift, test, scaffold} from './github-workflows';

0 commit comments

Comments
 (0)