diff --git a/packages/aws-cdk-lib/package.json b/packages/aws-cdk-lib/package.json index 5bdf1bf6edf0d..cd472eacc2726 100644 --- a/packages/aws-cdk-lib/package.json +++ b/packages/aws-cdk-lib/package.json @@ -525,7 +525,6 @@ "./region-info": "./region-info/index.js", "./triggers": "./triggers/index.js" }, - "preferredCdkCliVersion": "2", "publishConfig": { "tag": "latest" }, diff --git a/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts b/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts index a14f52ffbfb15..b13ac284474f7 100644 --- a/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts +++ b/packages/aws-cdk-lib/pipelines/lib/codepipeline/codepipeline.ts @@ -21,7 +21,6 @@ import { GraphNodeCollection, isGraph, AGraphNode, PipelineGraph } from '../help import { PipelineBase } from '../main'; import { AssetSingletonRole } from '../private/asset-singleton-role'; import { CachedFnSub } from '../private/cached-fnsub'; -import { preferredCliVersion } from '../private/cli-version'; import { appOf, assemblyBuilderOf, embeddedAsmPath, obtainScope } from '../private/construct-internals'; import { CDKP_DEFAULT_CODEBUILD_IMAGE } from '../private/default-codebuild-image'; import { toPosixPath } from '../private/fs'; @@ -425,7 +424,7 @@ export class CodePipeline extends PipelineBase { this.selfMutationEnabled = props.selfMutation ?? true; this.dockerCredentials = props.dockerCredentials ?? []; this.singlePublisherPerAssetType = !(props.publishAssetsInParallel ?? true); - this.cliVersion = props.cliVersion ?? preferredCliVersion(); + this.cliVersion = props.cliVersion ?? '2'; this.cdkAssetsCliVersion = props.cdkAssetsCliVersion ?? 'latest'; this.useChangeSets = props.useChangeSets ?? true; this.stackOutputs = new StackOutputsMap(this); diff --git a/packages/aws-cdk-lib/pipelines/lib/private/cli-version.ts b/packages/aws-cdk-lib/pipelines/lib/private/cli-version.ts deleted file mode 100644 index 50624cab896b9..0000000000000 --- a/packages/aws-cdk-lib/pipelines/lib/private/cli-version.ts +++ /dev/null @@ -1,41 +0,0 @@ -import * as fs from 'fs'; -import * as path from 'path'; - -/** - * Return the preferred CLI version for the current CDK Library version - * - * This is necessary to prevent cxapi version incompatibility between the two - * CDK major versions. Since changes currently go into v1 before they go into - * v2, a cxapi change can be released in v1 while the v2 CLI doesn't support it - * yet. - * - * In those cases, simply installing the "latest" CLI (2) is not good enough - * because it won't be able to read the Cloud Assembly of the v1 app. - * - * Find this version by finding the containing `package.json` and reading - * `preferredCdkCliVersion` from it. - */ -export function preferredCliVersion(): string | undefined { - const pjLocation = findUp('package.json', __dirname); - if (!pjLocation) { - return undefined; - } - const pj = JSON.parse(fs.readFileSync(pjLocation, { encoding: 'utf-8' })); - return pj.preferredCdkCliVersion ? `${pj.preferredCdkCliVersion}` : undefined; -} - -export function findUp(name: string, directory: string): string | undefined { - const absoluteDirectory = path.resolve(directory); - - const file = path.join(directory, name); - if (fs.existsSync(file)) { - return file; - } - - const { root } = path.parse(absoluteDirectory); - if (absoluteDirectory == root) { - return undefined; - } - - return findUp(name, path.dirname(absoluteDirectory)); -} diff --git a/packages/aws-cdk-lib/pipelines/test/codepipeline/codepipeline.test.ts b/packages/aws-cdk-lib/pipelines/test/codepipeline/codepipeline.test.ts index 2f9586f06041e..33db46173e7e8 100644 --- a/packages/aws-cdk-lib/pipelines/test/codepipeline/codepipeline.test.ts +++ b/packages/aws-cdk-lib/pipelines/test/codepipeline/codepipeline.test.ts @@ -277,6 +277,32 @@ test('CodeBuild asset role has the right Principal with the feature enabled', () ); }); +test.each([ + [undefined, '2'], + ['9.9.9', '9.9.9'], +])('When I request CLI version version %p I get %p', (requested, expected) => { + const pipelineStack = new cdk.Stack(app, 'PipelineStack', { env: PIPELINE_ENV }); + const pipe = new ModernTestGitHubNpmPipeline(pipelineStack, 'Cdk', { + cliVersion: requested, + }); + + pipe.addStage(new FileAssetApp(pipelineStack, 'App', {})); + + Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', { + Source: { + BuildSpec: Match.serializedJson(Match.objectLike({ + phases: { + install: { + commands: [ + `npm install -g aws-cdk@${expected}`, + ], + }, + }, + })), + }, + }); +}); + test('CodeBuild asset role has the right Principal with the feature disabled', () => { const stack = new cdk.Stack(); stack.node.setContext(cxapi.PIPELINE_REDUCE_ASSET_ROLE_TRUST_SCOPE, false);