Skip to content

Commit 04a0e60

Browse files
committed
add unit test
1 parent 11cd9db commit 04a0e60

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

packages/@aws-cdk/pipelines/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ const cdkPipeline = new CdkPipeline(app, 'CdkPipeline', {
205205
});
206206
```
207207

208+
If you use assets for files or Docker images, every asset will get its own upload action during the asset stage.
209+
By setting the value `singlePublisherPerType` to `true`, only one action for files and one action for
210+
Docker images is created that handles all assets of the respective type.
211+
208212
## Initial pipeline deployment
209213

210214
You provision this pipeline by making sure the target environment has been

packages/@aws-cdk/pipelines/lib/pipeline.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export interface CdkPipelineProps {
128128
*/
129129
readonly singlePublisherPerType?: boolean;
130130

131+
/**
131132
* Whether the pipeline needs to build Docker images in the UpdatePipeline stage.
132133
*
133134
* If the UpdatePipeline stage tries to build a Docker image and this flag is not
@@ -341,7 +342,7 @@ export class CdkPipeline extends CoreConstruct {
341342
return flatMap(this._pipeline.stages, s => s.actions.filter(isDeployAction));
342343
}
343344

344-
private* validateDeployOrder(): IterableIterator<string> {
345+
private * validateDeployOrder(): IterableIterator<string> {
345346
const stackActions = this.stackActions;
346347
for (const stackAction of stackActions) {
347348
// For every dependency, it must be executed in an action before this one is prepared.
@@ -359,7 +360,7 @@ export class CdkPipeline extends CoreConstruct {
359360
}
360361
}
361362

362-
private* validateRequestedOutputs(): IterableIterator<string> {
363+
private * validateRequestedOutputs(): IterableIterator<string> {
363364
const artifactIds = this.stackActions.map(s => s.stackArtifactId);
364365

365366
for (const artifactId of Object.keys(this._outputArtifacts)) {

packages/@aws-cdk/pipelines/test/integ.pipeline-with-assets-single-upload.expected.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@
293293
"ProjectName": {
294294
"Ref": "PipelineBuildSynthCdkBuildProject6BEFA8E6"
295295
},
296-
"EnvironmentVariables": "[{\"name\":\"_PROJECT_CONFIG_HASH\",\"type\":\"PLAINTEXT\",\"value\":\"a0d828d64c88aa603631eb7a08bc4748769f45d4b84d1b550cc85f41e49dc87e\"}]"
296+
"EnvironmentVariables": "[{\"name\":\"_PROJECT_CONFIG_HASH\",\"type\":\"PLAINTEXT\",\"value\":\"da8c1ee6d645a5802d25355fec94a3f22a961102b74ac3846898d6b14e3a2c30\"}]"
297297
},
298298
"InputArtifacts": [
299299
{
@@ -739,6 +739,13 @@
739739
},
740740
"Environment": {
741741
"ComputeType": "BUILD_GENERAL1_SMALL",
742+
"EnvironmentVariables": [
743+
{
744+
"Name": "NPM_CONFIG_UNSAFE_PERM",
745+
"Type": "PLAINTEXT",
746+
"Value": "true"
747+
}
748+
],
742749
"Image": "aws/codebuild/standard:5.0",
743750
"ImagePullCredentialsType": "CODEBUILD",
744751
"PrivilegedMode": false,

packages/@aws-cdk/pipelines/test/pipeline-assets.test.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as cdkp from '../lib';
1111
import { BucketStack, PIPELINE_ENV, TestApp, TestGitHubAction, TestGitHubNpmPipeline } from './testutil';
1212

1313
const FILE_ASSET_SOURCE_HASH = '8289faf53c7da377bb2b90615999171adef5e1d8f6b88810e5fef75e6ca09ba5';
14+
const FILE_ASSET_SOURCE_HASH2 = 'ac76997971c3f6ddf37120660003f1ced72b4fc58c498dfd99c78fa77e721e0e';
1415

1516
let app: TestApp;
1617
let pipelineStack: Stack;
@@ -406,6 +407,53 @@ describe('pipeline with VPC', () => {
406407
});
407408
});
408409

410+
describe('pipeline with single asset publisher', () => {
411+
beforeEach(() => {
412+
app = new TestApp();
413+
pipelineStack = new Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
414+
pipeline = new TestGitHubNpmPipeline(pipelineStack, 'Cdk', {
415+
singlePublisherPerType: true,
416+
});
417+
});
418+
419+
afterEach(() => {
420+
app.cleanup();
421+
});
422+
423+
test('multiple assets are using the same job in singlePublisherMode', () => {
424+
// WHEN
425+
pipeline.addApplicationStage(new TwoFileAssetsApp(app, 'FileAssetApp'));
426+
427+
// THEN
428+
expect(pipelineStack).toHaveResourceLike('AWS::CodePipeline::Pipeline', {
429+
Stages: arrayWith({
430+
Name: 'Assets',
431+
Actions: [
432+
// Only one file asset action
433+
objectLike({ RunOrder: 1, Name: 'FileAsset' }),
434+
],
435+
}),
436+
});
437+
expect(pipelineStack).toHaveResourceLike('AWS::CodeBuild::Project', {
438+
Environment: {
439+
Image: 'aws/codebuild/standard:5.0',
440+
},
441+
Source: {
442+
BuildSpec: encodedJson(deepObjectLike({
443+
phases: {
444+
build: {
445+
// Both assets are uploaded in the same action
446+
commands: arrayWith(
447+
`cdk-assets --path "assembly-FileAssetApp/FileAssetAppStackEADD68C5.assets.json" --verbose publish "${FILE_ASSET_SOURCE_HASH}:current_account-current_region"`,
448+
`cdk-assets --path "assembly-FileAssetApp/FileAssetAppStackEADD68C5.assets.json" --verbose publish "${FILE_ASSET_SOURCE_HASH2}:current_account-current_region"`,
449+
),
450+
},
451+
},
452+
})),
453+
},
454+
});
455+
});
456+
});
409457
class PlainStackApp extends Stage {
410458
constructor(scope: Construct, id: string, props?: StageProps) {
411459
super(scope, id, props);

0 commit comments

Comments
 (0)