11import { promises as fs } from 'fs' ;
2- import { fileExists } from '@form8ion/core' ;
2+ import { loadWorkflowFile , workflowFileExists } from '@form8ion/github-workflows- core' ;
33
44import { Given , Then } from '@cucumber/cucumber' ;
55import { assert } from 'chai' ;
6- import { load } from 'js-yaml' ;
76
8- async function loadReleaseWorkflowDefinition ( ) {
7+ const experimentalReleaseWorkflowName = 'experimental-release' ;
8+ const legacyReleaseWorkflowName = 'release' ;
9+ const ciWorkflowName = 'node-ci' ;
10+
11+ async function loadReleaseWorkflowDefinition ( { projectRoot} ) {
912 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'
1215 ) ;
1316
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 } ) ;
1718
1819 return { triggers, jobs} ;
1920}
@@ -85,21 +86,21 @@ Given('no conventional verification workflow is defined', async function () {
8586} ) ;
8687
8788Then ( '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 } ) ;
8990
9091 assert . isUndefined ( triggers . workflow_dispatch ) ;
9192 assert . deepEqual ( triggers . push . branches , [ 'alpha' ] ) ;
9293 assert . equal ( jobs . release . uses , 'form8ion/.github/.github/workflows/release-package.yml@master' ) ;
9394} ) ;
9495
9596Then ( '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 } ) ) ;
9798} ) ;
9899
99100Then (
100101 'the experimental release workflow calls the reusable workflow for semantic-release v19 for alpha branches' ,
101102 async function ( ) {
102- const { triggers, jobs} = await loadReleaseWorkflowDefinition ( ) ;
103+ const { triggers, jobs} = await loadReleaseWorkflowDefinition ( { projectRoot : this . projectRoot } ) ;
103104
104105 assert . isUndefined ( triggers . workflow_dispatch ) ;
105106 assert . deepEqual ( triggers . push . branches , [ 'alpha' ] ) ;
@@ -111,14 +112,11 @@ Then(
111112) ;
112113
113114Then ( '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 } ) ) ;
115116} ) ;
116117
117118Then ( '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 } ) ;
122120 const branchTriggers = verificationWorkflowDefinition . on . push . branches ;
123121
124122 assert . include ( branchTriggers , 'master' ) ;
@@ -148,10 +146,7 @@ Then('the verification workflow calls the reusable release workflow', async func
148146} ) ;
149147
150148Then ( '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 } ) ;
155150 const branchTriggers = verificationWorkflowDefinition . on . push . branches ;
156151
157152 assert . include ( branchTriggers , 'master' ) ;
@@ -172,19 +167,13 @@ Then('the verification workflow calls the reusable release workflow for semantic
172167} ) ;
173168
174169Then ( '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 } ) ;
179171
180172 assert . isUndefined ( verificationWorkflowDefinition . jobs [ 'trigger-release' ] ) ;
181173} ) ;
182174
183175Then ( '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 } ) ;
188177 const triggerReleaseJob = verificationWorkflowDefinition . jobs . release ;
189178
190179 assert . include ( triggerReleaseJob . needs , 'verify' ) ;
0 commit comments