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

feat(codepipeline): GitPushFilter with branches and file paths for trigger #29127

Merged
merged 23 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
80 changes: 77 additions & 3 deletions packages/aws-cdk-lib/aws-codepipeline/lib/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,58 @@ export interface GitPushFilter {
* @default - no tags.
*/
readonly tagsIncludes?: string[];

/**
* The list of patterns of Git branches that, when a commit is pushed, are
* to be excluded from starting the pipeline.
*
* You can filter with glob patterns. The `branchesExcludes` takes priority
* over the `branchesIncludes`.
*
* Maximum length of this array is 8.
*
* @default - no branches.
*/
readonly branchesExcludes?: string[];

/**
* The list of patterns of Git branches that, when a commit is pushed, are
* to be included as criteria that starts the pipeline.
*
* You can filter with glob patterns. The `branchesExcludes` takes priority
* over the `branchesIncludes`.
*
* Maximum length of this array is 8.
*
* @default - no branches.
*/
readonly branchesIncludes?: string[];

/**
* The list of patterns of Git repository file paths that, when a commit is pushed,
* are to be excluded from starting the pipeline.
*
* You can filter with glob patterns. The `filePathsExcludes` takes priority
* over the `filePathsIncludes`.
*
* Maximum length of this array is 8.
*
* @default - no filePaths.
*/
readonly filePathsExcludes?: string[];

/**
* The list of patterns of Git repository file paths that, when a commit is pushed,
* are to be included as criteria that starts the pipeline.
*
* You can filter with glob patterns. The `filePathsExcludes` takes priority
* over the `filePathsIncludes`.
*
* Maximum length of this array is 8.
*
* @default - no filePaths.
*/
readonly filePathsIncludes?: string[];
}

/**
Expand Down Expand Up @@ -117,10 +169,22 @@ export class Trigger {

pushFilter?.forEach(filter => {
if (filter.tagsExcludes && filter.tagsExcludes.length > 8) {
throw new Error(`maximum length of tagsExcludes for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsExcludes.length}`);
throw new Error(`maximum length of tagsExcludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsExcludes.length}`);
}
if (filter.tagsIncludes && filter.tagsIncludes.length > 8) {
throw new Error(`maximum length of tagsIncludes for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsIncludes.length}`);
throw new Error(`maximum length of tagsIncludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.tagsIncludes.length}`);
}
if (filter.branchesExcludes && filter.branchesExcludes.length > 8) {
throw new Error(`maximum length of branchesExcludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.branchesExcludes.length}`);
}
if (filter.branchesIncludes && filter.branchesIncludes.length > 8) {
throw new Error(`maximum length of branchesIncludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.branchesIncludes.length}`);
}
if (filter.filePathsExcludes && filter.filePathsExcludes.length > 8) {
throw new Error(`maximum length of filePathsExcludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.filePathsExcludes.length}`);
}
if (filter.filePathsIncludes && filter.filePathsIncludes.length > 8) {
throw new Error(`maximum length of filePathsIncludes in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}' is 8, got ${filter.filePathsIncludes.length}`);
}
});
}
Expand All @@ -143,7 +207,17 @@ export class Trigger {
excludes: filter.tagsExcludes?.length ? filter.tagsExcludes : undefined,
includes: filter.tagsIncludes?.length ? filter.tagsIncludes : undefined,
};
return { tags };
const branches: CfnPipeline.GitBranchFilterCriteriaProperty | undefined = {
// set to undefined if empty array because CloudFormation does not accept empty array
excludes: filter.branchesExcludes?.length ? filter.branchesExcludes : undefined,
includes: filter.branchesIncludes?.length ? filter.branchesIncludes : undefined,
};
const filePaths: CfnPipeline.GitFilePathFilterCriteriaProperty | undefined = {
// set to undefined if empty array because CloudFormation does not accept empty array
excludes: filter.filePathsExcludes?.length ? filter.filePathsExcludes : undefined,
includes: filter.filePathsIncludes?.length ? filter.filePathsIncludes : undefined,
};
return { tags, branches, filePaths };
});

gitConfiguration = {
Expand Down
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-codepipeline/test/triggers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ describe('triggers', () => {
},
}],
});
}).toThrow(/maximum length of tagsExcludes for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
}).toThrow(/maximum length of tagsExcludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
});

test('throw if length of excludes is greater than 8', () => {
Expand All @@ -265,7 +265,7 @@ describe('triggers', () => {
},
}],
});
}).toThrow(/maximum length of tagsIncludes for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
}).toThrow(/maximum length of tagsIncludes in pushFilter for sourceAction with name 'CodeStarConnectionsSourceAction' is 8, got 9/);
});

test('empty pushFilter for trigger is set to undefined', () => {
Expand Down
Loading