Skip to content

Commit

Permalink
fix action name
Browse files Browse the repository at this point in the history
  • Loading branch information
cornelcroi committed Jun 17, 2024
1 parent ef04991 commit 94a50c9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Properly bundles package before publishing to npm
- Ensure connection stack name follows naming pattern
- Ensure connection stack name follows naming pattern

## [1.1.15] - 2024-06-07
### Added


### Changed


### Fixed

- Removal special characters Action name in CodePipeline
25 changes: 22 additions & 3 deletions bin/cli/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ import {
import { getPipelineStatus, getSSMParameter } from "./awsSDKUtil";

const MAX_STACK_NAME_LENGTH = 128;
const stackNameRegex = /^[A-Za-z][A-Za-z0-9-]*$/;
const MAX_PIPELINE_NAME_LENGTH = 100;
const MAX_BUILD_NAME_LENGTH = 150;
const MAX_ACTION_NAME_LENGTH = 100;

/**
* Retrieves the absolute path of the current working directory.
Expand Down Expand Up @@ -201,9 +203,10 @@ export function calculateConnectionStackName(

}

function cleanStackNameStr(stackName: string) {

function cleanNameStr(stackName: string, maxLength: number) {
var desiredString = stackName.replace(/[^a-zA-Z0-9]/g, "-");
desiredString = truncateString(desiredString, MAX_STACK_NAME_LENGTH);
desiredString = truncateString(desiredString, maxLength);
// Ensure it doesn't end with a hyphen after truncation
while (desiredString.endsWith("-")) {
desiredString = desiredString.substring(0, desiredString.length - 1);
Expand All @@ -217,6 +220,22 @@ function cleanStackNameStr(stackName: string) {
return desiredString;
}

function cleanStackNameStr(stackName: string) {
return cleanNameStr(stackName, MAX_STACK_NAME_LENGTH)
}

export function cleanPipelineNameStr(stackName: string) {
return cleanNameStr(stackName, MAX_PIPELINE_NAME_LENGTH)
}
export function cleanBuildNameStr(stackName: string) {
return cleanNameStr(stackName, MAX_BUILD_NAME_LENGTH)
}

export function cleanActionNameStr(stackName: string) {
return cleanNameStr(stackName, MAX_ACTION_NAME_LENGTH)
}


export function calculateCodeStarConnectionStackName(
repoUrl: string,
branchName: string
Expand Down
10 changes: 8 additions & 2 deletions lib/pipeline_infrastructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
CfnOutput,
} from "aws-cdk-lib";

import { calculateMainStackName, isRepoConfig, isS3Config, parseRepositoryUrl } from "../bin/cli/utils/helper";
import { calculateMainStackName, cleanActionNameStr, cleanBuildNameStr, cleanPipelineNameStr, isRepoConfig, isS3Config, parseRepositoryUrl } from "../bin/cli/utils/helper";

import { Construct } from "constructs";
import { IBucket } from "aws-cdk-lib/aws-s3";
Expand Down Expand Up @@ -127,10 +127,14 @@ export class PipelineInfrastructure extends Construct {
const { repoOwner, repoName } = parsedUrl;
//the pipeline is triggered from code repository
pipelineName = repoOwner + "@" + repoName;
pipelineName = cleanPipelineNameStr(pipelineName);
buildName = "Build-And-Copy-to-S3-" + repoName;
buildName = cleanBuildNameStr(buildName);
const sourceActionName = cleanActionNameStr("GitHub-Source-" + repoName);


sourceAction = new codepipeline_actions.CodeStarConnectionsSourceAction({
actionName: "GitHub-Source-" + repoName,
actionName: sourceActionName,
owner: repoOwner,
repo: repoName,
branch: params.hostingConfiguration.branchName,
Expand All @@ -148,6 +152,7 @@ export class PipelineInfrastructure extends Construct {
});

pipelineName = params.hostingConfiguration.s3bucket;
pipelineName = cleanPipelineNameStr(pipelineName);
buildName = "Unzip-And-Copy-to-S3";

const pipelineArn = `arn:aws:codepipeline:${Aws.REGION}:${Aws.ACCOUNT_ID}:${pipelineName}`;
Expand Down Expand Up @@ -427,6 +432,7 @@ export class PipelineInfrastructure extends Construct {

pipeline.addStage({
stageName: "Sources",

actions: [sourceAction! as IAction],
});

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aws/cloudfront-hosting-toolkit",
"version": "1.1.13",
"version": "1.1.15",
"description": "CloudFront Hosting Toolkit offers the convenience of a managed frontend hosting service while retaining full control over the hosting and deployment infrastructure to make it your own.",
"license": "Apache-2.0",
"bin": {
Expand Down

0 comments on commit 94a50c9

Please sign in to comment.