Skip to content

Commit

Permalink
feat(workflow-file): expose a function to check for existence of a wo…
Browse files Browse the repository at this point in the history
…rkflow file
  • Loading branch information
travi committed Aug 26, 2024
1 parent d9aeb90 commit 87dcc42
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ import {
scaffoldDependencyInstallationStep,
scaffoldVerificationStep,
loadWorkflowFile,
writeWorkflowFile
writeWorkflowFile,
workflowFileExists
} from '@form8ion/github-workflows-core';
```

Expand All @@ -73,7 +74,10 @@ const projectRoot = process.cwd();

scaffoldVerificationStep();

await loadWorkflowFile({projectRoot, name: 'existing-workflow-name'});
if (await workflowFileExists({projectRoot, name: 'existing-workflow-name'})) {
await loadWorkflowFile({projectRoot, name: 'existing-workflow-name'});
}

await writeWorkflowFile({projectRoot, name: 'workflow-name', config: {}});
})();
```
Expand Down
8 changes: 6 additions & 2 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
scaffoldDependencyInstallationStep,
scaffoldVerificationStep,
loadWorkflowFile,
writeWorkflowFile
writeWorkflowFile,
workflowFileExists
} from './lib/index.js';

// remark-usage-ignore-next 4
Expand All @@ -29,6 +30,9 @@ const projectRoot = process.cwd();

scaffoldVerificationStep();

await loadWorkflowFile({projectRoot, name: 'existing-workflow-name'});
if (await workflowFileExists({projectRoot, name: 'existing-workflow-name'})) {
await loadWorkflowFile({projectRoot, name: 'existing-workflow-name'});
}

await writeWorkflowFile({projectRoot, name: 'workflow-name', config: {}});
})();
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ export {
setupNode as scaffoldNodeSetupStep,
checkout as scaffoldCheckoutStep
} from './steps/scaffolders.js';
export {load as loadWorkflowFile, write as writeWorkflowFile} from './workflow-file/index.js';
export {
fileExists as workflowFileExists,
load as loadWorkflowFile,
write as writeWorkflowFile
} from './workflow-file/index.js';
5 changes: 5 additions & 0 deletions src/workflow-file/existence-checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {fileExists} from '@form8ion/core';

export default function ({projectRoot, name}) {
return fileExists(`${projectRoot}/.github/workflows/${name}.yml`);
}
20 changes: 20 additions & 0 deletions src/workflow-file/existence-checker.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {fileExists} from '@form8ion/core';

import {when} from 'jest-when';
import any from '@travi/any';
import {describe, expect, it, vi} from 'vitest';

import workflowFileExists from './existence-checker.js';

vi.mock('@form8ion/core');

describe('workflow existence checker', () => {
it('should check for existence of the workflow file in the workflows directory', async () => {
const projectRoot = any.string();
const name = any.word();
const exists = any.boolean();
when(fileExists).calledWith(`${projectRoot}/.github/workflows/${name}.yml`).mockResolvedValue(exists);

expect(await workflowFileExists({projectRoot, name})).toBe(exists);
});
});
1 change: 1 addition & 0 deletions src/workflow-file/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export {default as fileExists} from './existence-checker.js';
export {default as load} from './loader.js';
export {default as write} from './writer.js';

0 comments on commit 87dcc42

Please sign in to comment.