-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
+3,521
−1,978
Merged
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
945d0c0
feat(codepipeline): GitPushFilter with branches and file paths for tr…
go-to-k 06d2fc9
doc
go-to-k 55fa3ec
add unit tests
go-to-k 8ebad4e
add validations
go-to-k 5d40f6c
README
go-to-k 3293f4d
change unit tests
go-to-k ad1487a
README
go-to-k 8cd7ef1
Merge branch 'main' into pipeline-trigger-branch
go-to-k 2ebda40
refactor
go-to-k 4ef0486
Revert "refactor"
go-to-k 74820d8
integ test
go-to-k 750dc08
change unit tests
go-to-k 61c7edc
Merge branch 'main' into pipeline-trigger-branch
go-to-k 3292050
Merge branch 'main' into pipeline-trigger-branch
go-to-k eb4a424
create renderPushFilter method
go-to-k c4337c5
refactor
go-to-k 29735fc
Merge branch 'main' into pipeline-trigger-branch
go-to-k c0d0199
Merge branch 'main' of https://github.com/go-to-k/aws-cdk into pipeli…
go-to-k 3700097
update an integ test
go-to-k c2bb84a
rm trailing spaces in triggers.test.ts
go-to-k bf846d6
Merge branch 'main' into pipeline-trigger-branch
go-to-k 669be8b
Merge branch 'main' into pipeline-trigger-branch
GavinZZ e22a8f2
Merge branch 'main' into pipeline-trigger-branch
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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[]; | ||
} | ||
|
||
/** | ||
|
@@ -51,8 +103,6 @@ export interface GitConfiguration { | |
* The field where the repository event that will start the pipeline, | ||
* such as pushing Git tags, is specified with details. | ||
* | ||
* Git tags is the only supported event type. | ||
* | ||
* The length must be less than or equal to 3. | ||
* | ||
* @default - no filter. | ||
|
@@ -116,11 +166,29 @@ export class Trigger { | |
} | ||
|
||
pushFilter?.forEach(filter => { | ||
if ((filter.tagsExcludes || filter.tagsIncludes) && (filter.branchesExcludes || filter.branchesIncludes)) { | ||
throw new Error(`cannot specify both tags and branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`); | ||
} | ||
Comment on lines
+273
to
+275
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is no this validation, the error occurred in CFn: In addition, we can only choose tags or branches (with file paths) in the AWS console. |
||
if (!filter.branchesExcludes && !filter.branchesIncludes && (filter.filePathsExcludes || filter.filePathsIncludes)) { | ||
throw new Error(`cannot specify filePaths without branches in pushFilter for sourceAction with name '${sourceAction.actionProperties.actionName}'`); | ||
} | ||
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}`); | ||
} | ||
}); | ||
} | ||
|
@@ -143,7 +211,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 = { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not separated here by the chapters "Tags" and "Branches" to add pull request filters in the PR.