Skip to content

Commit

Permalink
fix(pipeline): fix feature branch pipeline creation for bare PDKPipel…
Browse files Browse the repository at this point in the history
…inePyProject (#543)

This fixes the CodeBuild buildspec that creates feature branch pipelines by preventing the
inclusion of a `"cd "` command in before running `cdk synth`.

Changes:
 * Add an optional `cdkSrcDir` prop to `PDKPipeline` in case the assumption that `cdk.out`
and `cdk.json` are in the same directory is incorrect for the project.
 * Use `path.dirname()` to determine the default `cdkSrcDir` from the `primarySynthDir`
to handle the case that it is the project root.

fix #462

Co-authored-by: Adrian Dimech <[email protected]>
  • Loading branch information
jstrunk and agdimech authored Sep 8, 2023
1 parent 484fdf9 commit 2163f85
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/pipeline/src/feature-branches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface FeatureBranchesProps
readonly branchNamePrefixes: string[];

/**
* The directory to run cdk synth from.
* The directory with `cdk.json` to run cdk synth from.
*/
readonly cdkSrcDir: string;

Expand Down
15 changes: 11 additions & 4 deletions packages/pipeline/src/pdk-pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*! Copyright [Amazon.com](http://amazon.com/), Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 */
import * as path from "path";
import {
Aspects,
CfnOutput,
Expand Down Expand Up @@ -115,6 +116,15 @@ export interface PDKPipelineProps extends _CodePipelineProps {
*/
readonly branchNamePrefixes?: string[];

/**
* The directory with `cdk.json` to run cdk synth from. Set this if you enabled
* feature branches and `cdk.json` is not located in the parent directory of
* `primarySynthDirectory`.
*
* @default The parent directory of `primarySynthDirectory`
*/
readonly cdkSrcDir?: string;

/**
* CDK command. Override the command used to call cdk for synth and deploy.
*
Expand Down Expand Up @@ -342,10 +352,7 @@ export class PDKPipeline extends Construct {
) {
new FeatureBranches(this, "FeatureBranchPipelines", {
codeRepository: this.codeRepository,
cdkSrcDir: props.primarySynthDirectory
.split("/")
.slice(0, -1)
.join("/"),
cdkSrcDir: props.cdkSrcDir || path.dirname(props.primarySynthDirectory),
synthShellStepPartialProps: props.synthShellStepPartialProps,
cdkCommand: props.cdkCommand,
branchNamePrefixes: props.branchNamePrefixes,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2163f85

Please sign in to comment.