From 698e5ef3568880474adf73a38c21dad919b62b7e Mon Sep 17 00:00:00 2001 From: Meng Xin Zhu Date: Fri, 11 Sep 2020 08:55:21 +0800 Subject: [PATCH] feat(codebuild): add git submodule options of codebuild (#10283) closes #10271 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-codebuild/README.md | 12 ++++++++++++ packages/@aws-cdk/aws-codebuild/lib/source.ts | 12 ++++++++++++ .../@aws-cdk/aws-codebuild/test/test.codebuild.ts | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/packages/@aws-cdk/aws-codebuild/README.md b/packages/@aws-cdk/aws-codebuild/README.md index e6a312d4b048b..208912c6657e9 100644 --- a/packages/@aws-cdk/aws-codebuild/README.md +++ b/packages/@aws-cdk/aws-codebuild/README.md @@ -115,6 +115,18 @@ const bbSource = codebuild.Source.bitBucket({ }); ``` +### For all Git sources + +For all Git sources, you can fetch submodules while cloing git repo. + +```typescript +const gitHubSource = codebuild.Source.gitHub({ + owner: 'awslabs', + repo: 'aws-cdk', + fetchSubmodules: true, +}); +``` + ## Artifacts CodeBuild Projects can produce Artifacts and upload them to S3. For example: diff --git a/packages/@aws-cdk/aws-codebuild/lib/source.ts b/packages/@aws-cdk/aws-codebuild/lib/source.ts index 52161c3f90050..1d85e525b7d55 100644 --- a/packages/@aws-cdk/aws-codebuild/lib/source.ts +++ b/packages/@aws-cdk/aws-codebuild/lib/source.ts @@ -119,6 +119,13 @@ interface GitSourceProps extends SourceProps { * @default the default branch's HEAD commit ID is used */ readonly branchOrRef?: string; + + /** + * Whether to fetch submodules while cloning git repo. + * + * @default false + */ + readonly fetchSubmodules?: boolean; } /** @@ -127,12 +134,14 @@ interface GitSourceProps extends SourceProps { abstract class GitSource extends Source { private readonly cloneDepth?: number; private readonly branchOrRef?: string; + private readonly fetchSubmodules?: boolean; protected constructor(props: GitSourceProps) { super(props); this.cloneDepth = props.cloneDepth; this.branchOrRef = props.branchOrRef; + this.fetchSubmodules = props.fetchSubmodules; } public bind(_scope: Construct, _project: IProject): SourceConfig { @@ -142,6 +151,9 @@ abstract class GitSource extends Source { sourceProperty: { ...superConfig.sourceProperty, gitCloneDepth: this.cloneDepth, + gitSubmodulesConfig: this.fetchSubmodules ? { + fetchSubmodules: this.fetchSubmodules, + } : undefined, }, }; } diff --git a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts index bf52b1d7c86aa..a3450446606d2 100644 --- a/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts +++ b/packages/@aws-cdk/aws-codebuild/test/test.codebuild.ts @@ -546,6 +546,7 @@ export = { owner: 'testowner', repo: 'testrepo', cloneDepth: 3, + fetchSubmodules: true, webhook: true, reportBuildStatus: false, webhookFilters: [ @@ -561,6 +562,9 @@ export = { Location: 'https://github.com/testowner/testrepo.git', ReportBuildStatus: false, GitCloneDepth: 3, + GitSubmodulesConfig: { + FetchSubmodules: true, + }, }, }));