Skip to content

Commit ed0d0b4

Browse files
committed
feat(release): added the beta branch to the trigger list when the release isnt configured yet
1 parent c842ebb commit ed0d0b4

File tree

4 files changed

+66
-5
lines changed

4 files changed

+66
-5
lines changed

src/semantic-release/ci-providers/github-workflows/lifter-test.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,61 @@ suite('github-workflows lifter for semantic-release', () => {
6464
.withArgs(verificationWorkflowContents)
6565
.returns({
6666
...parsedVerificationWorkflowContents,
67-
on: {push: {branches: [...branchTriggers, 'alpha', ...moreBranchTriggers]}},
67+
on: {push: {branches: [...branchTriggers, 'alpha', 'beta', ...moreBranchTriggers]}},
6868
jobs: {...jobs, release: legacyReleaseJob}
6969
});
7070
jsYaml.dump
7171
.withArgs({
72+
...parsedVerificationWorkflowContents,
73+
on: {push: {branches: [...branchTriggers, 'beta', ...moreBranchTriggers]}},
74+
jobs: {
75+
...jobs,
76+
'trigger-release': {
77+
'runs-on': 'ubuntu-latest',
78+
if: "github.event_name == 'push'",
79+
steps: [{
80+
uses: 'octokit/[email protected]',
81+
with: {
82+
route: 'POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches',
83+
owner: vcsOwner,
84+
repo: vcsName,
85+
ref: '${{ github.ref }}', // eslint-disable-line no-template-curly-in-string
86+
workflow_id: 'release.yml'
87+
},
88+
env: {
89+
GITHUB_TOKEN: '${{ secrets.GH_PAT }}' // eslint-disable-line no-template-curly-in-string
90+
}
91+
}]
92+
}
93+
}
94+
})
95+
.returns(updatedVerificationWorkflowContents);
96+
97+
await lift({projectRoot, vcs: vcsDetails});
98+
99+
assert.calledWith(fs.writeFile, `${workflowsDirectory}/node-ci.yml`, updatedVerificationWorkflowContents);
100+
});
101+
102+
test('that the the release trigger is added when no release is configured yet', async () => {
103+
const verificationWorkflowContents = any.string();
104+
const parsedVerificationWorkflowContents = any.simpleObject();
105+
const jobs = any.simpleObject();
106+
const updatedVerificationWorkflowContents = any.string();
107+
const branchTriggers = any.listOf(any.word);
108+
const moreBranchTriggers = any.listOf(any.word);
109+
core.fileExists.resolves(true);
110+
fs.readFile.withArgs(`${workflowsDirectory}/node-ci.yml`, 'utf-8').resolves(verificationWorkflowContents);
111+
jsYaml.load
112+
.withArgs(verificationWorkflowContents)
113+
.returns({
72114
...parsedVerificationWorkflowContents,
73115
on: {push: {branches: [...branchTriggers, ...moreBranchTriggers]}},
116+
jobs
117+
});
118+
jsYaml.dump
119+
.withArgs({
120+
...parsedVerificationWorkflowContents,
121+
on: {push: {branches: [...branchTriggers, ...moreBranchTriggers, 'beta']}},
74122
jobs: {
75123
...jobs,
76124
'trigger-release': {

src/semantic-release/ci-providers/github-workflows/lifter.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export default async function ({projectRoot, vcs: {name: vcsProjectName, owner:
1313

1414
const parsedVerificationWorkflowDetails = load(await fs.readFile(pathToVerificationWorkflow, 'utf-8'));
1515

16-
parsedVerificationWorkflowDetails.on.push.branches = parsedVerificationWorkflowDetails.on.push.branches.filter(
17-
branch => 'alpha' !== branch
18-
);
16+
parsedVerificationWorkflowDetails.on.push.branches = [
17+
...parsedVerificationWorkflowDetails.on.push.branches.filter(branch => 'alpha' !== branch),
18+
...!parsedVerificationWorkflowDetails.on.push.branches.includes('beta') ? ['beta'] : []
19+
];
1920

2021
const {release, ...otherJobs} = parsedVerificationWorkflowDetails.jobs;
2122
parsedVerificationWorkflowDetails.jobs = {

test/integration/features/lifter.feature

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ Feature: Lift
1414
Then the release workflow is defined
1515

1616
Scenario: no existing release
17+
Given semantic-release is configured
18+
And no release is configured in a GitHub workflow
19+
When the project is lifted
20+
Then the release workflow is defined
21+
And the verification workflow triggers the release workflow
22+
23+
Scenario: no release needed
1724
Given semantic-release is not configured
1825
And no release is configured in a GitHub workflow
1926
When the project is lifted

test/integration/features/step_definitions/github-workflows-steps.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ Given('no release is configured in a GitHub workflow', async function () {
2525
this.verificationWorkflow = true;
2626
this.nodeCiWithReleaseJob = false;
2727
this.nodeCiWithTriggerReleaseJob = false;
28+
this.alphaBranchTrigger = false;
29+
this.betaBranchTrigger = false;
2830
});
2931

3032
Given('no GitHub workflows exist', async function () {
@@ -44,8 +46,11 @@ Then('the verification workflow triggers the release workflow', async function (
4446
`${process.cwd()}/.github/workflows/node-ci.yml`,
4547
'utf-8'
4648
));
49+
const branchTriggers = verificationWorkflowDefinition.on.push.branches;
4750

48-
assert.deepEqual(verificationWorkflowDefinition.on.push.branches, ['master', 'beta', 'dependency-updater/**']);
51+
assert.include(branchTriggers, 'master');
52+
assert.include(branchTriggers, 'beta');
53+
assert.include(branchTriggers, 'dependency-updater/**');
4954

5055
const verificationWorkflowJobs = verificationWorkflowDefinition.jobs;
5156
const triggerReleaseJob = verificationWorkflowJobs['trigger-release'];

0 commit comments

Comments
 (0)