Skip to content

Commit a4fc5bd

Browse files
authored
refactor(pipelines): simplify CLI dependency version (#34803)
The Pipelines construct used to inspect `package.json` of the library to come up with the major version of the CDK CLI to use. This made sense when we were developing v1 and v2 of CDK at the same time, but now that v1 is deprecated and the version lines of library and CLI have been decoupled, this does not make sense anymore. Just depend on CLI v2 directly, in a clear way. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 13ce6e3 commit a4fc5bd

File tree

4 files changed

+27
-44
lines changed

4 files changed

+27
-44
lines changed

packages/aws-cdk-lib/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@
525525
"./region-info": "./region-info/index.js",
526526
"./triggers": "./triggers/index.js"
527527
},
528-
"preferredCdkCliVersion": "2",
529528
"publishConfig": {
530529
"tag": "latest"
531530
},

packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { GraphNodeCollection, isGraph, AGraphNode, PipelineGraph } from '../help
2121
import { PipelineBase } from '../main';
2222
import { AssetSingletonRole } from '../private/asset-singleton-role';
2323
import { CachedFnSub } from '../private/cached-fnsub';
24-
import { preferredCliVersion } from '../private/cli-version';
2524
import { appOf, assemblyBuilderOf, embeddedAsmPath, obtainScope } from '../private/construct-internals';
2625
import { CDKP_DEFAULT_CODEBUILD_IMAGE } from '../private/default-codebuild-image';
2726
import { toPosixPath } from '../private/fs';
@@ -425,7 +424,7 @@ export class CodePipeline extends PipelineBase {
425424
this.selfMutationEnabled = props.selfMutation ?? true;
426425
this.dockerCredentials = props.dockerCredentials ?? [];
427426
this.singlePublisherPerAssetType = !(props.publishAssetsInParallel ?? true);
428-
this.cliVersion = props.cliVersion ?? preferredCliVersion();
427+
this.cliVersion = props.cliVersion ?? '2';
429428
this.cdkAssetsCliVersion = props.cdkAssetsCliVersion ?? 'latest';
430429
this.useChangeSets = props.useChangeSets ?? true;
431430
this.stackOutputs = new StackOutputsMap(this);

packages/aws-cdk-lib/pipelines/lib/private/cli-version.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/aws-cdk-lib/pipelines/test/codepipeline/codepipeline.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,32 @@ test('CodeBuild asset role has the right Principal with the feature enabled', ()
277277
);
278278
});
279279

280+
test.each([
281+
[undefined, '2'],
282+
['9.9.9', '9.9.9'],
283+
])('When I request CLI version version %p I get %p', (requested, expected) => {
284+
const pipelineStack = new cdk.Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
285+
const pipe = new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk', {
286+
cliVersion: requested,
287+
});
288+
289+
pipe.addStage(new FileAssetApp(pipelineStack, 'App', {}));
290+
291+
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
292+
Source: {
293+
BuildSpec: Match.serializedJson(Match.objectLike({
294+
phases: {
295+
install: {
296+
commands: [
297+
`npm install -g aws-cdk@${expected}`,
298+
],
299+
},
300+
},
301+
})),
302+
},
303+
});
304+
});
305+
280306
test('CodeBuild asset role has the right Principal with the feature disabled', () => {
281307
const stack = new cdk.Stack();
282308
stack.node.setContext(cxapi.PIPELINE_REDUCE_ASSET_ROLE_TRUST_SCOPE, false);

0 commit comments

Comments
 (0)