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): cannot configure actionName for all sources #24027

Merged
merged 2 commits into from
Feb 6, 2023
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 @@ -236,6 +236,12 @@ export interface GitHubSourceOptions {
*/
readonly trigger?: GitHubTrigger;

/**
* The action name used for this source in the CodePipeline
*
* @default - The repository string
*/
readonly actionName?: string;
}

/**
Expand All @@ -262,7 +268,7 @@ class GitHubSource extends CodePipelineSource {
protected getAction(output: Artifact, actionName: string, runOrder: number, variablesNamespace?: string) {
return new cp_actions.GitHubSourceAction({
output,
actionName,
actionName: this.props.actionName ?? actionName,
runOrder,
oauthToken: this.authentication,
owner: this.owner,
Expand Down Expand Up @@ -379,7 +385,6 @@ export interface ConnectionSourceOptions {
*/
readonly connectionArn: string;


// long URL in @see
/**
* If this is set, the next CodeBuild job clones the repository (instead of CodePipeline downloading the files).
Expand All @@ -403,6 +408,13 @@ export interface ConnectionSourceOptions {
* @see https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CodestarConnectionSource.html
*/
readonly triggerOnPush?: boolean;

/**
* The action name used for this source in the CodePipeline
*
* @default - The repository string
*/
readonly actionName?: string;
}

class CodeStarConnectionSource extends CodePipelineSource {
Expand All @@ -424,7 +436,7 @@ class CodeStarConnectionSource extends CodePipelineSource {
protected getAction(output: Artifact, actionName: string, runOrder: number, variablesNamespace?: string) {
return new cp_actions.CodeStarConnectionsSourceAction({
output,
actionName,
actionName: this.props.actionName ?? actionName,
runOrder,
connectionArn: this.props.connectionArn,
owner: this.owner,
Expand Down Expand Up @@ -468,6 +480,13 @@ export interface CodeCommitSourceOptions {
* @see https://docs.aws.amazon.com/codepipeline/latest/userguide/action-reference-CodeCommit.html
*/
readonly codeBuildCloneOutput?: boolean;

/**
* The action name used for this source in the CodePipeline
*
* @default - The repository name
*/
readonly actionName?: string;
}

class CodeCommitSource extends CodePipelineSource {
Expand All @@ -483,7 +502,7 @@ class CodeCommitSource extends CodePipelineSource {
return new cp_actions.CodeCommitSourceAction({
output,
// Guaranteed to be okay as action name
actionName: this.repository.repositoryName,
actionName: this.props.actionName ?? this.repository.repositoryName,
runOrder,
branch: this.branch,
trigger: this.props.trigger,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,54 @@ test('pass role to s3 codepipeline source', () => {
}]),
});
});

type SourceFactory = (stack: Stack) => cdkp.CodePipelineSource;

test.each([
['CodeCommit', (stack) => {
const repo = new ccommit.Repository(stack, 'Repo', {
repositoryName: 'MyRepo',
});
return cdkp.CodePipelineSource.codeCommit(repo, 'main', {
actionName: 'ConfiguredName',
});
}],
['S3', (stack) => {
const bucket = new s3.Bucket(stack, 'Bucket');
return cdkp.CodePipelineSource.s3(bucket, 'thefile.zip', {
actionName: 'ConfiguredName',
});
}],
['ECR', (stack) => {
const repository = new ecr.Repository(stack, 'Repository', { repositoryName: 'namespace/repo' });
return cdkp.CodePipelineSource.ecr(repository, {
actionName: 'ConfiguredName',
});
}],
['GitHub', () => {
return cdkp.CodePipelineSource.gitHub('owner/repo', 'main', {
actionName: 'ConfiguredName',
});
}],
['CodeStar', () => {
return cdkp.CodePipelineSource.connection('owner/repo', 'main', {
connectionArn: 'arn:aws:codestar-connections:us-west-2:123456789012:connection/39e4c34d-e13a-4e94-a886',
actionName: 'ConfiguredName',
});
}],
] as Array<[string, SourceFactory]>)('can configure actionName for %s', (_name: string, fac: SourceFactory) => {
new ModernTestGitHubNpmPipeline(pipelineStack, 'Pipeline', {
input: fac(pipelineStack),
});

Template.fromStack(pipelineStack).hasResourceProperties('AWS::CodePipeline::Pipeline', {
Stages: Match.arrayWith([{
Name: 'Source',
Actions: [
Match.objectLike({
Name: 'ConfiguredName',
}),
],
}]),
});
});