Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add common source code to projen drift check triggers #477

Merged
merged 1 commit into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/projen-drift-check.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
14 changes: 14 additions & 0 deletions src/common/github/__tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
9 changes: 8 additions & 1 deletion src/common/github/projen-drift-check-workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export interface ProjenDriftCheckOptions
* @default ['main']
*/
readonly triggerOnPushToBranches?: Array<string>

/**
* By default the check runs only on projenrc file changes.
* This option allows adding paths that trigger the check.
*/
readonly additionalPaths?: string[]
}

/**
Expand All @@ -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
Expand Down
Loading