Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pipelines): additionalInputs fails for deep directory #17074

Merged
merged 1 commit into from
Oct 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,11 @@ function generateInputArtifactLinkCommands(artifacts: ArtifactMap, inputs: FileS
return inputs.map(input => {
const fragments = [];

if (!['.', '..'].includes(path.dirname(input.directory))) {
fragments.push(`mkdir -p -- "${input.directory}"`);
fragments.push(`[[ ! -d "${input.directory}" ]] || { echo 'additionalInputs: "${input.directory}" must not exist yet. If you want to merge multiple artifacts, use a "cp" command.'; exit 1; }`);

const parentDirectory = path.dirname(input.directory);
if (!['.', '..'].includes(parentDirectory)) {
fragments.push(`mkdir -p -- "${parentDirectory}"`);
}

const artifact = artifacts.toCodePipeline(input.fileSet);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Template, Match } from '@aws-cdk/assertions';
import { Stack } from '@aws-cdk/core';
import * as cdkp from '../../lib';
import { PIPELINE_ENV, TestApp } from '../testhelpers';

let app: TestApp;
let pipelineStack: Stack;

beforeEach(() => {
app = new TestApp();
pipelineStack = new Stack(app, 'PipelineStack', { env: PIPELINE_ENV });
});

afterEach(() => {
app.cleanup();
});

test('additionalinputs creates the right commands', () => {
// WHEN
new cdkp.CodePipeline(pipelineStack, 'Pipeline', {
synth: new cdkp.CodeBuildStep('Synth', {
commands: ['/bin/true'],
input: cdkp.CodePipelineSource.gitHub('test/test', 'main'),
additionalInputs: {
'some/deep/directory': cdkp.CodePipelineSource.gitHub('test2/test2', 'main'),
},
}),
});

// THEN
Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodeBuild::Project', {
Source: {
BuildSpec: Match.serializedJson(Match.objectLike({
phases: {
install: {
commands: [
'[[ ! -d "some/deep/directory" ]] || { echo \'additionalInputs: "some/deep/directory" must not exist yet. If you want to merge multiple artifacts, use a "cp" command.\'; exit 1; } && mkdir -p -- "some/deep" && ln -s -- "$CODEBUILD_SRC_DIR_test2_test2_Source" "some/deep/directory"',
],
},
},
})),
},
});
});
4 changes: 2 additions & 2 deletions packages/@aws-cdk/pipelines/test/compliance/synths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -947,8 +947,8 @@ behavior('Multiple input sources in side-by-side directories', (suite) => {
phases: {
install: {
commands: [
'ln -s -- "$CODEBUILD_SRC_DIR_foo_bar_Source" "../sibling"',
'ln -s -- "$CODEBUILD_SRC_DIR_Prebuild_Output" "sub"',
'[[ ! -d "../sibling" ]] || { echo \'additionalInputs: "../sibling" must not exist yet. If you want to merge multiple artifacts, use a "cp" command.\'; exit 1; } && ln -s -- "$CODEBUILD_SRC_DIR_foo_bar_Source" "../sibling"',
'[[ ! -d "sub" ]] || { echo \'additionalInputs: "sub" must not exist yet. If you want to merge multiple artifacts, use a "cp" command.\'; exit 1; } && ln -s -- "$CODEBUILD_SRC_DIR_Prebuild_Output" "sub"',
],
},
build: {
Expand Down