diff --git a/.github/workflows/projen-drift-check.yml b/.github/workflows/projen-drift-check.yml index 49981e0f..612de3b4 100644 --- a/.github/workflows/projen-drift-check.yml +++ b/.github/workflows/projen-drift-check.yml @@ -5,12 +5,14 @@ on: pull_request: paths: - .projenrc.ts + - src/common/** types: - opened - synchronize push: paths: - .projenrc.ts + - src/common/** branches: - main jobs: diff --git a/.projenrc.ts b/.projenrc.ts index 761ad085..d7497558 100644 --- a/.projenrc.ts +++ b/.projenrc.ts @@ -94,7 +94,7 @@ testGithubWorkflow.addJobs({ build: {...job([npmRunJobStep('build')]), needs: ['lint', 'test', 'typecheck']}, }) -new ProjenDriftCheckWorkflow(project.github!, {}) +new ProjenDriftCheckWorkflow(project.github!, {additionalPaths: ['src/common/**']}) const createReleaseGithubWorkflow = project.github!.addWorkflow('create-release') diff --git a/src/common/github/__tests__/index.ts b/src/common/github/__tests__/index.ts index a1e0a943..d0a41528 100644 --- a/src/common/github/__tests__/index.ts +++ b/src/common/github/__tests__/index.ts @@ -236,6 +236,20 @@ describe('GitHub utils', () => { }) }) + test('allows setting additional paths to trigger the workflow', () => { + const additionalPaths = ['some/additional/path', 'another/additional/path'] + const project = new TestProject() + const paths = ['.projenrc.js', ...additionalPaths] + new ProjenDriftCheckWorkflow(project.github!, {additionalPaths}) + const snapshot = synthSnapshot(project) + const workflow = YAML.parse(snapshot[workflowPath]) + + expect(workflow.on).toEqual({ + pull_request: {paths, types: ['opened', 'synchronize']}, + push: {paths, branches: ['main']}, + }) + }) + test('allows to be run on pushes to specified branches', () => { const project = new TestProject() const branches = ['main', 'dev'] diff --git a/src/common/github/projen-drift-check-workflow.ts b/src/common/github/projen-drift-check-workflow.ts index f1bf4f0e..dcbf12da 100644 --- a/src/common/github/projen-drift-check-workflow.ts +++ b/src/common/github/projen-drift-check-workflow.ts @@ -25,6 +25,12 @@ export interface ProjenDriftCheckOptions * @default ['main'] */ readonly triggerOnPushToBranches?: Array + + /** + * By default the check runs only on projenrc file changes. + * This option allows adding paths that trigger the check. + */ + readonly additionalPaths?: string[] } /** @@ -41,7 +47,8 @@ export class ProjenDriftCheckWorkflow extends Component { const workflowName = 'projen-drift-check' const workingDirectory = options.outdir - const paths = [ProjenrcFile.of(project)!.filePath] + const additionalPaths = options.additionalPaths ?? [] + const paths = [ProjenrcFile.of(project)!.filePath, ...additionalPaths] const workflow = githubInstance.addWorkflow(workflowName) const branches = options.triggerOnPushToBranches ?? ['main'] const nodeVersion = options.workflowNodeVersion ?? project.package.minNodeVersion