1
1
import { promises as fs } from 'fs' ;
2
- import { fileExists } from '@form8ion/core' ;
2
+ import { loadWorkflowFile , workflowFileExists } from '@form8ion/github-workflows- core' ;
3
3
4
4
import { Given , Then } from '@cucumber/cucumber' ;
5
5
import { assert } from 'chai' ;
6
- import { load } from 'js-yaml' ;
7
6
8
- async function loadReleaseWorkflowDefinition ( ) {
7
+ const experimentalReleaseWorkflowName = 'experimental-release' ;
8
+ const legacyReleaseWorkflowName = 'release' ;
9
+ const ciWorkflowName = 'node-ci' ;
10
+
11
+ async function loadReleaseWorkflowDefinition ( { projectRoot} ) {
9
12
assert . isTrue (
10
- await fileExists ( ` ${ process . cwd ( ) } /.github/workflows/experimental-release.yml` ) ,
11
- 'Release workflow is missing'
13
+ await workflowFileExists ( { projectRoot , name : experimentalReleaseWorkflowName } ) ,
14
+ 'Experimental- Release workflow is missing'
12
15
) ;
13
16
14
- const { on : triggers , jobs} = load (
15
- await fs . readFile ( `${ process . cwd ( ) } /.github/workflows/experimental-release.yml` , 'utf-8' )
16
- ) ;
17
+ const { on : triggers , jobs} = await loadWorkflowFile ( { projectRoot, name : experimentalReleaseWorkflowName } ) ;
17
18
18
19
return { triggers, jobs} ;
19
20
}
@@ -85,21 +86,21 @@ Given('no conventional verification workflow is defined', async function () {
85
86
} ) ;
86
87
87
88
Then ( 'the experimental release workflow calls the reusable workflow for alpha branches' , async function ( ) {
88
- const { triggers, jobs} = await loadReleaseWorkflowDefinition ( ) ;
89
+ const { triggers, jobs} = await loadReleaseWorkflowDefinition ( { projectRoot : this . projectRoot } ) ;
89
90
90
91
assert . isUndefined ( triggers . workflow_dispatch ) ;
91
92
assert . deepEqual ( triggers . push . branches , [ 'alpha' ] ) ;
92
93
assert . equal ( jobs . release . uses , 'form8ion/.github/.github/workflows/release-package.yml@master' ) ;
93
94
} ) ;
94
95
95
96
Then ( 'the legacy experimental release workflow has been renamed' , async function ( ) {
96
- assert . isFalse ( await fileExists ( ` ${ process . cwd ( ) } /.github/workflows/release.yml` ) ) ;
97
+ assert . isFalse ( await workflowFileExists ( { projectRoot : this . projectRoot , name : legacyReleaseWorkflowName } ) ) ;
97
98
} ) ;
98
99
99
100
Then (
100
101
'the experimental release workflow calls the reusable workflow for semantic-release v19 for alpha branches' ,
101
102
async function ( ) {
102
- const { triggers, jobs} = await loadReleaseWorkflowDefinition ( ) ;
103
+ const { triggers, jobs} = await loadReleaseWorkflowDefinition ( { projectRoot : this . projectRoot } ) ;
103
104
104
105
assert . isUndefined ( triggers . workflow_dispatch ) ;
105
106
assert . deepEqual ( triggers . push . branches , [ 'alpha' ] ) ;
@@ -111,14 +112,11 @@ Then(
111
112
) ;
112
113
113
114
Then ( 'the release workflow is not defined' , async function ( ) {
114
- assert . isFalse ( await fileExists ( ` ${ process . cwd ( ) } /.github/workflows/release.yml` ) ) ;
115
+ assert . isFalse ( await workflowFileExists ( { projectRoot : this . projectRoot , name : experimentalReleaseWorkflowName } ) ) ;
115
116
} ) ;
116
117
117
118
Then ( 'the verification workflow calls the reusable release workflow' , async function ( ) {
118
- const verificationWorkflowDefinition = load ( await fs . readFile (
119
- `${ process . cwd ( ) } /.github/workflows/node-ci.yml` ,
120
- 'utf-8'
121
- ) ) ;
119
+ const verificationWorkflowDefinition = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
122
120
const branchTriggers = verificationWorkflowDefinition . on . push . branches ;
123
121
124
122
assert . include ( branchTriggers , 'master' ) ;
@@ -148,10 +146,7 @@ Then('the verification workflow calls the reusable release workflow', async func
148
146
} ) ;
149
147
150
148
Then ( 'the verification workflow calls the reusable release workflow for semantic-release v19' , async function ( ) {
151
- const verificationWorkflowDefinition = load ( await fs . readFile (
152
- `${ process . cwd ( ) } /.github/workflows/node-ci.yml` ,
153
- 'utf-8'
154
- ) ) ;
149
+ const verificationWorkflowDefinition = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
155
150
const branchTriggers = verificationWorkflowDefinition . on . push . branches ;
156
151
157
152
assert . include ( branchTriggers , 'master' ) ;
@@ -172,19 +167,13 @@ Then('the verification workflow calls the reusable release workflow for semantic
172
167
} ) ;
173
168
174
169
Then ( 'the verification workflow does not trigger the release workflow' , async function ( ) {
175
- const verificationWorkflowDefinition = load ( await fs . readFile (
176
- `${ process . cwd ( ) } /.github/workflows/node-ci.yml` ,
177
- 'utf-8'
178
- ) ) ;
170
+ const verificationWorkflowDefinition = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
179
171
180
172
assert . isUndefined ( verificationWorkflowDefinition . jobs [ 'trigger-release' ] ) ;
181
173
} ) ;
182
174
183
175
Then ( 'the release is not called until verification completes' , async function ( ) {
184
- const verificationWorkflowDefinition = load ( await fs . readFile (
185
- `${ process . cwd ( ) } /.github/workflows/node-ci.yml` ,
186
- 'utf-8'
187
- ) ) ;
176
+ const verificationWorkflowDefinition = await loadWorkflowFile ( { projectRoot : this . projectRoot , name : ciWorkflowName } ) ;
188
177
const triggerReleaseJob = verificationWorkflowDefinition . jobs . release ;
189
178
190
179
assert . include ( triggerReleaseJob . needs , 'verify' ) ;
0 commit comments