Skip to content

Commit f686367

Browse files
Stewart Wallacesbkok
andauthored
Add ability to define CodeCommit artifact format (#389)
* Add ability to define CodeCommit artifact format * Updating Provider Documentation * Update src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py * Updating test to check OutputArtifactFormat not in configuration if not required Co-authored-by: Simon Kok <sbkok@users.noreply.github.com>
1 parent 5598044 commit f686367

4 files changed

Lines changed: 64 additions & 1 deletion

File tree

docs/providers-guide.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ Provider type: `codecommit`.
8787
>
8888
> By default, it will trigger on changes using the event triggered by
8989
> CodeCommit when an update to the repository took place.
90+
- *output_artifact_format* - *(String)* default: `CODE_ZIP`
91+
> The output artifact format. Values can be either CODEBUILD_CLONE_REF or CODE_ZIP. If unspecified, the default is CODE_ZIP.
92+
> If you are using CODEBUILD_CLONE_REF, you need to ensure that the IAM role passed in via the *role* property has the CodeCommit:GitPull permission.
93+
> NB: The CODEBUILD_CLONE_REF value can only be used by CodeBuild downstream actions.
9094
9195
### GitHub
9296

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_constructs/adf_codepipeline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,18 @@ def _generate_configuration(self): #pylint: disable=R0912, R0911, R0915
264264
'deployment_group_name')
265265
}
266266
if self.provider == "CodeCommit":
267-
return {
267+
props = {
268268
"BranchName": self.map_params['default_providers']['source'].get('properties', {}).get('branch', 'master'),
269269
"RepositoryName": self.map_params['default_providers']['source'].get('properties', {}).get('repository', {}) or self.map_params['name'],
270270
"PollForSourceChanges": (
271271
self.map_params['default_providers']['source'].get('properties', {}).get('trigger_on_changes', True)
272272
and self.map_params['default_providers']['source'].get('properties', {}).get('poll_for_changes', False)
273273
)
274274
}
275+
output_artifact_format = self.map_params['default_providers']['source'].get('properties', {}).get('output_artifact_format', None)
276+
if output_artifact_format:
277+
props["OutputArtifactFormat"] = output_artifact_format
278+
return props
275279
raise Exception("{0} is not a valid provider".format(self.provider))
276280

277281
def _generate_codepipeline_access_role(self): # pylint: disable=R0911

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/cdk/cdk_stacks/tests/test_pipeline_creation.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,62 @@ def test_pipeline_creation_outputs_as_expected_when_source_is_codecommit_and_bui
139139
assert build_stage_action['ActionTypeId']['Owner'] == "AWS"
140140
assert build_stage_action['ActionTypeId']['Provider'] == "CodeBuild"
141141

142+
assert "OutputArtifactFormat" not in source_stage_action['Configuration']
143+
144+
assert len(build_stage['Actions']) == 1
145+
146+
147+
def test_pipeline_creation_outputs_as_expected_when_source_is_codecommit_with_codebuild_clone_ref_and_build_is_codebuild():
148+
region_name = "eu-central-1"
149+
acount_id = "123456789012"
150+
151+
stack_input = {
152+
"input": {"params": {}, "default_providers": {}, "regions": {}},
153+
"ssm_params": {"fake-region": {}},
154+
}
155+
156+
stack_input["input"]["name"] = "test-stack"
157+
158+
stack_input["input"]["default_providers"]["source"] = {
159+
"provider": "codecommit",
160+
"properties": {"account_id": "123456789012", "output_artifact_format": "CODEBUILD_CLONE_REF"},
161+
}
162+
stack_input["input"]["default_providers"]["build"] = {
163+
"provider": "codebuild",
164+
"properties": {"account_id": "123456789012"},
165+
}
166+
167+
stack_input["ssm_params"][region_name] = {
168+
"modules": "fake-bucket-name",
169+
"kms": f"arn:aws:kms:{region_name}:{acount_id}:key/my-unique-kms-key-id",
170+
}
171+
app = core.App()
172+
PipelineStack(app, stack_input)
173+
174+
cloud_assembly = app.synth()
175+
resources = {k[0:-8]: v for k, v in cloud_assembly.stacks[0].template['Resources'].items()}
176+
code_pipeline = resources['codepipeline']
177+
assert code_pipeline['Type'] == "AWS::CodePipeline::Pipeline"
178+
assert len(code_pipeline["Properties"]["Stages"]) == 2
179+
180+
source_stage = code_pipeline['Properties']["Stages"][0]
181+
assert len(source_stage['Actions']) == 1
182+
183+
source_stage_action = source_stage['Actions'][0]
184+
assert source_stage_action['ActionTypeId']['Category'] == "Source"
185+
assert source_stage_action['ActionTypeId']['Owner'] == "AWS"
186+
assert source_stage_action['ActionTypeId']['Provider'] == "CodeCommit"
187+
assert source_stage_action['Configuration']['OutputArtifactFormat'] == "CODEBUILD_CLONE_REF"
188+
189+
build_stage = code_pipeline['Properties']["Stages"][1]
190+
build_stage_action = build_stage['Actions'][0]
191+
assert build_stage_action['ActionTypeId']['Category'] == "Build"
192+
assert build_stage_action['ActionTypeId']['Owner'] == "AWS"
193+
assert build_stage_action['ActionTypeId']['Provider'] == "CodeBuild"
194+
142195
assert len(build_stage['Actions']) == 1
143196

197+
144198
def test_pipeline_creation_outputs_as_expected_when_notification_endpoint_is_chatbot():
145199
region_name = "eu-central-1"
146200
acount_id = "123456789012"

src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/schema_validation.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
Optional("owner"): str,
5757
Optional("role"): str,
5858
Optional("trigger_on_changes"): bool,
59+
Optional("output_artifact_format", default=None): Or("CODEBUILD_CLONE_REF", "CODE_ZIP", None)
5960
}
6061
CODECOMMIT_SOURCE = {
6162
"provider": 'codecommit',

0 commit comments

Comments
 (0)