Skip to content

Commit c81e4b3

Browse files
committed
feat(legacy-release): removed the use of the cycjimmy action when switching to the release trigger
1 parent 37088f6 commit c81e4b3

File tree

5 files changed

+106
-6
lines changed

5 files changed

+106
-6
lines changed

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ suite('github-workflows lifter for semantic-release', () => {
1919
const vcsDetails = {name: vcsName, owner: vcsOwner};
2020
const verificationWorkflowContents = any.string();
2121
const parsedVerificationWorkflowContents = any.simpleObject();
22-
const jobs = any.simpleObject();
22+
const jobs = any.objectWithKeys(any.listOf(any.word), {factory: () => ({steps: any.listOf(any.simpleObject)})});
2323
const legacyReleaseJob = any.simpleObject();
2424
const updatedVerificationWorkflowContents = any.string();
2525
const branchTriggers = any.listOf(any.word);
@@ -105,6 +105,62 @@ suite('github-workflows lifter for semantic-release', () => {
105105
assert.calledWith(fs.writeFile, `${workflowsDirectory}/node-ci.yml`, updatedVerificationWorkflowContents);
106106
});
107107

108+
test('that the cycjimmy action is removed', async () => {
109+
const jobNameContainingCycjimmyAction = any.word();
110+
const otherStepsInJobContainingCycJimmyAction = any.listOf(any.simpleObject);
111+
const existingJobs = {
112+
...jobs,
113+
[jobNameContainingCycjimmyAction]: {
114+
steps: [
115+
...otherStepsInJobContainingCycJimmyAction,
116+
{uses: `cycjimmy/semantic-release-action@v${any.integer()}`}
117+
]
118+
}
119+
};
120+
core.fileExists.resolves(true);
121+
fs.readFile.withArgs(`${workflowsDirectory}/node-ci.yml`, 'utf-8').resolves(verificationWorkflowContents);
122+
releaseTriggerNeeds.default.withArgs(existingJobs).returns(neededJobsToTriggerRelease);
123+
jsYaml.load
124+
.withArgs(verificationWorkflowContents)
125+
.returns({
126+
...parsedVerificationWorkflowContents,
127+
on: {push: {branches: [...branchTriggers, 'alpha', 'beta', ...moreBranchTriggers]}},
128+
jobs: existingJobs
129+
});
130+
jsYaml.dump
131+
.withArgs({
132+
...parsedVerificationWorkflowContents,
133+
on: {push: {branches: [...branchTriggers, 'beta', ...moreBranchTriggers]}},
134+
jobs: {
135+
...jobs,
136+
[jobNameContainingCycjimmyAction]: {steps: otherStepsInJobContainingCycJimmyAction},
137+
'trigger-release': {
138+
'runs-on': 'ubuntu-latest',
139+
if: "github.event_name == 'push'",
140+
needs: neededJobsToTriggerRelease,
141+
steps: [{
142+
uses: 'octokit/[email protected]',
143+
with: {
144+
route: 'POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches',
145+
owner: vcsOwner,
146+
repo: vcsName,
147+
ref: '${{ github.ref }}', // eslint-disable-line no-template-curly-in-string
148+
workflow_id: 'release.yml'
149+
},
150+
env: {
151+
GITHUB_TOKEN: '${{ secrets.GH_PAT }}' // eslint-disable-line no-template-curly-in-string
152+
}
153+
}]
154+
}
155+
}
156+
})
157+
.returns(updatedVerificationWorkflowContents);
158+
159+
await lift({projectRoot, vcs: vcsDetails});
160+
161+
assert.calledWith(fs.writeFile, `${workflowsDirectory}/node-ci.yml`, updatedVerificationWorkflowContents);
162+
});
163+
108164
test('that the the release trigger is added when no release is configured yet', async () => {
109165
core.fileExists.resolves(true);
110166
fs.readFile.withArgs(`${workflowsDirectory}/node-ci.yml`, 'utf-8').resolves(verificationWorkflowContents);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import {fileExists, fileTypes, writeConfigFile} from '@form8ion/core';
55
import determineTriggerNeedsFrom from './release-trigger-needs';
66
import scaffoldReleaseWorkflow from './scaffolder';
77

8+
function removeCycjimmyActionFrom(otherJobs) {
9+
return Object.fromEntries(Object.entries(otherJobs).map(([jobName, job]) => [
10+
jobName,
11+
{...job, steps: job.steps.filter(step => !step.uses?.includes('cycjimmy/semantic-release-action'))}
12+
]));
13+
}
14+
815
export default async function ({projectRoot, vcs: {name: vcsProjectName, owner: vcsOwner}}) {
916
const workflowsDirectory = `${projectRoot}/.github/workflows`;
1017

@@ -22,7 +29,7 @@ export default async function ({projectRoot, vcs: {name: vcsProjectName, owner:
2229
const {release, ...otherJobs} = parsedVerificationWorkflowDetails.jobs;
2330

2431
parsedVerificationWorkflowDetails.jobs = {
25-
...otherJobs,
32+
...removeCycjimmyActionFrom(otherJobs),
2633
'trigger-release': {
2734
'runs-on': 'ubuntu-latest',
2835
if: "github.event_name == 'push'",

test/integration/features/lifter.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Feature: Lift
77
Then the release workflow is defined
88
And the verification workflow triggers the release workflow
99

10+
Scenario: cycjimmy action in a GitHub workflow
11+
Given semantic-release is configured
12+
And the cycjimmy action is configured in a GitHub workflow
13+
When the project is lifted
14+
Then the release workflow is defined
15+
And the verification workflow triggers the release workflow
16+
And the cycjimmy action was removed
17+
1018
Scenario: modern semantic-release in GitHub workflows
1119
Given semantic-release is configured
1220
And modern releases are configured in a GitHub workflow

test/integration/features/step_definitions/common-steps.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,24 @@ When('the project is lifted', async function () {
4545
}
4646
},
4747
jobs: {
48-
verify: {},
49-
...this.multipleNodeVersionsVerified && {'verify-matrix': {}},
50-
...this.nodeCiWithReleaseJob && {release: {}},
51-
...this.nodeCiWithTriggerReleaseJob && {'trigger-release': {}}
48+
verify: {steps: []},
49+
...this.multipleNodeVersionsVerified && {'verify-matrix': {steps: []}},
50+
...this.nodeCiWithReleaseJob && {release: {steps: []}},
51+
...this.nodeCiWithCycjimmyAction && {
52+
[any.word()]: {
53+
steps: [{
54+
name: 'semantic-release',
55+
uses: 'cycjimmy/semantic-release-action@v2',
56+
env: {
57+
// eslint-disable-next-line no-template-curly-in-string
58+
GITHUB_TOKEN: '${{ secrets.GH_TOKEN }}',
59+
// eslint-disable-next-line no-template-curly-in-string
60+
NPM_TOKEN: '${{ secrets.NPM_PUBLISH_TOKEN }}'
61+
}
62+
}]
63+
}
64+
},
65+
...this.nodeCiWithTriggerReleaseJob && {'trigger-release': {steps: []}}
5266
}
5367
})
5468
},

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Given('legacy releases are configured in a GitHub workflow', async function () {
1313
this.betaBranchTrigger = true;
1414
});
1515

16+
Given('the cycjimmy action is configured in a GitHub workflow', async function () {
17+
this.githubWorkflows = true;
18+
this.verificationWorkflow = true;
19+
this.nodeCiWithCycjimmyAction = true;
20+
});
21+
1622
Given('modern releases are configured in a GitHub workflow', async function () {
1723
this.githubWorkflows = true;
1824
this.verificationWorkflow = true;
@@ -92,3 +98,12 @@ Then('the release is not triggered until verification completes', async function
9298
assert.include(triggerReleaseJob.needs, 'verify');
9399
if (this.multipleNodeVersionsVerified) assert.include(triggerReleaseJob.needs, 'verify-matrix');
94100
});
101+
102+
Then('the cycjimmy action was removed', async function () {
103+
const ciWorkflow = await fs.readFile(
104+
`${process.cwd()}/.github/workflows/node-ci.yml`,
105+
'utf-8'
106+
);
107+
108+
assert.notInclude(ciWorkflow, 'cycjimmy');
109+
});

0 commit comments

Comments
 (0)