diff --git a/packages/blueprints/blueprint-builder/package.json b/packages/blueprints/blueprint-builder/package.json index 6c3b0a7f8..3e3df9784 100644 --- a/packages/blueprints/blueprint-builder/package.json +++ b/packages/blueprints/blueprint-builder/package.json @@ -69,7 +69,7 @@ "main": "lib/index.js", "license": "Apache-2.0", "homepage": "https://aws.amazon.com/", - "version": "0.3.25-preview.0", + "version": "0.3.25-preview.5", "types": "lib/index.d.ts", "publishingSpace": "blueprints", "mediaUrls": [ diff --git a/packages/blueprints/blueprint-builder/src/build-release-workflow.ts b/packages/blueprints/blueprint-builder/src/build-release-workflow.ts index 523e69e61..38a085245 100644 --- a/packages/blueprints/blueprint-builder/src/build-release-workflow.ts +++ b/packages/blueprints/blueprint-builder/src/build-release-workflow.ts @@ -1,11 +1,11 @@ import { TriggerType, WorkflowBuilder } from '@amazon-codecatalyst/blueprint-component.workflows'; export function buildReleaseWorkflow(workflow: WorkflowBuilder): WorkflowBuilder { - workflow.setName('blueprint-release'); const RELEASE_COMMIT_PREFIX = 'chore(release):'; + const BUILD_ARTIFACT_NAME = 'codebase'; - workflow.addBranchTrigger(['main']), + workflow.addBranchTrigger(['main']); workflow.addTrigger({ Type: TriggerType.MANUAL, }); @@ -15,9 +15,7 @@ export function buildReleaseWorkflow(workflow: WorkflowBuilder): WorkflowBuilder Sources: ['WorkflowSource'], }, output: { - Variables: [ - 'IS_RELEASE_COMMIT', - ], + Variables: ['IS_RELEASE_COMMIT'], }, steps: [ 'TRIGGER_COMMIT_ID=$CATALYST_EVENT_SHA', @@ -26,8 +24,7 @@ export function buildReleaseWorkflow(workflow: WorkflowBuilder): WorkflowBuilder 'IS_RELEASE_COMMIT=false', 'if grep -q "$RELEASE_PREFIX" <<< "$COMMIT_MESSAGE"; then echo \'this is a release commit\' && IS_RELEASE_COMMIT=true; fi', ], - }), - + }); workflow.addBuildAction({ actionName: 'build_blueprint', dependsOn: ['check_commit'], @@ -37,55 +34,64 @@ export function buildReleaseWorkflow(workflow: WorkflowBuilder): WorkflowBuilder IS_RELEASE_COMMIT: '${check_commit.IS_RELEASE_COMMIT}', }, }, - output: {}, + output: { + Artifacts: [ + { + Name: BUILD_ARTIFACT_NAME, + Files: ['**/*'], + }, + ], + }, steps: [ - 'if $IS_RELEASE_COMMIT; then echo \'This is a release commit, skipping\' && exit 1; fi', + "if $IS_RELEASE_COMMIT; then echo 'This is a release commit, skipping' && exit 1; fi", + 'yum install -y rsync', + 'npm install -g yarn', 'yarn', 'yarn build', 'yarn bump', 'yarn blueprint:package', ], - }), - - workflow.addBuildAction({ - actionName: 'commit_changes', + }); + // TODO: Build actions can't push back to source yet: + // workflow.addBuildAction({ + // actionName: 'commit_changes', + // dependsOn: ['build_blueprint'], + // input: { + // Sources: ['WorkflowSource'], + // Variables: { + // IS_RELEASE_COMMIT: '${check_commit.IS_RELEASE_COMMIT}', + // }, + // }, + // output: {}, + // steps: [ + // "if $IS_RELEASE_COMMIT; then echo 'This is a release commit, skipping' && exit 1; fi", + // `RELEASE_COMMIT_MESSAGE="${RELEASE_COMMIT_PREFIX} release on $(date +"%Y %m %d %H:%M:%S")"`, + // 'git add .', + // 'git commit -m $RELEASE_COMMIT_MESSAGE', + // 'git push --force', + // ], + // }); + workflow.addPublishBlueprintAction({ + actionName: 'publish_blueprint', dependsOn: ['build_blueprint'], - input: { + inputs: { Sources: ['WorkflowSource'], - Variables: { - IS_RELEASE_COMMIT: '${check_commit.IS_RELEASE_COMMIT}', - }, + Artifacts: [BUILD_ARTIFACT_NAME], + // TODO: The action doesn't handle this env var correctly: + // Variables: [ + // { + // Name: 'IS_RELEASE_COMMIT', + // Value: '${check_commit.IS_RELEASE_COMMIT}', + // }, + // ], }, - output: {}, - steps: [ - 'if $IS_RELEASE_COMMIT; then echo \'This is a release commit, skipping\' && exit 1; fi', - `RELEASE_COMMIT_MESSAGE="${RELEASE_COMMIT_PREFIX} release on $(date +"%Y %m %d %H:%M:%S")"`, - 'git add .', - 'git commit -m $RELEASE_COMMIT_MESSAGE', - 'git push --force', - ], - }), - - workflow.setDefinition({ - ...workflow.getDefinition(), - Actions: { - ...workflow.definition.Actions, - publish_blueprint: { - Identifier: 'aws/publish-blueprint-action', - dependsOn: ['commit_changes'], - Inputs: { - Sources: ['WorkflowSource'], - Variables: { - IS_RELEASE_COMMIT: '${check_commit.IS_RELEASE_COMMIT}', - }, - }, - Configuration: { - ArtifactPackagePath: 'dist/*.tgz', - PackageJSONPath: 'package.json', - TimeoutInSeconds: '120', - }, - }, + configuration: { + ArtifactPackagePath: 'dist/js/*.tgz', + PackageJSONPath: 'package.json', + InputArtifactName: BUILD_ARTIFACT_NAME, + TimeoutInSeconds: '120', }, }); + return workflow; -} \ No newline at end of file +} diff --git a/packages/components/workflows/src/actions/action-publish-blueprint.ts b/packages/components/workflows/src/actions/action-publish-blueprint.ts new file mode 100644 index 000000000..cf323e8a1 --- /dev/null +++ b/packages/components/workflows/src/actions/action-publish-blueprint.ts @@ -0,0 +1,41 @@ +import { Blueprint } from '@amazon-codecatalyst/blueprints.blueprint'; +import { ActionDefiniton, ActionIdentifierAlias, ComputeConfiguration, InputsDefinition, getDefaultActionIdentifier } from './action'; +import { WorkflowDefinition } from '../workflow/workflow'; + +export interface PublishBlueprintActionConfiguration { + ArtifactPackagePath: string; + PackageJSONPath: string; + InputArtifactName: string; + TimeoutInSeconds?: string; +} + +export interface PublishBlueprintActionParameters { + actionName: string; + inputs: InputsDefinition; + configuration: PublishBlueprintActionConfiguration; + dependsOn?: string[]; + computeName?: ComputeConfiguration; +} + +export function addGenericPublishBlueprintAction( + params: PublishBlueprintActionParameters & { + blueprint: Blueprint; + workflow: WorkflowDefinition; + }, +): string { + const { blueprint, inputs, dependsOn, computeName, configuration } = params; + const actionName = (params.actionName || 'PublishBlueprint').replace(new RegExp('-', 'g'), '_'); + + const publishBlueprintAction: ActionDefiniton = { + Identifier: getDefaultActionIdentifier(ActionIdentifierAlias.publishBlueprint, blueprint.context.environmentId), + Inputs: inputs, + DependsOn: dependsOn, + Compute: computeName, + Configuration: configuration, + }; + + params.workflow.Actions = params.workflow.Actions || {}; + params.workflow.Actions[actionName] = publishBlueprintAction; + + return actionName; +} diff --git a/packages/components/workflows/src/actions/action.ts b/packages/components/workflows/src/actions/action.ts index f3f3d7bcd..f6e607f86 100644 --- a/packages/components/workflows/src/actions/action.ts +++ b/packages/components/workflows/src/actions/action.ts @@ -7,6 +7,7 @@ import { BuildActionConfiguration } from './action-build'; import { CdkBootstrapActionConfiguration } from './action-cdk-bootstrap'; import { CdkDeployActionYamlOutput } from './action-cdk-deploy'; import { CfnDeployActionConfiguration } from './action-cfn-deploy'; +import { PublishBlueprintActionConfiguration } from './action-publish-blueprint'; import { TestActionConfiguration } from './action-test-reports'; import { WorkflowEnvironment } from '../environment/workflow-environment'; @@ -16,6 +17,7 @@ export enum ActionIdentifierAlias { test = 'test', cdkDeploy = 'cdkDeploy', cdkBootstrap = 'cdkBootstrap', + publishBlueprint = 'publishBlueprint', } const ACTION_IDENTIFIERS: { [key: string]: { default: string; prod: string } } = { @@ -39,6 +41,10 @@ const ACTION_IDENTIFIERS: { [key: string]: { default: string; prod: string } } = default: 'aws/cdk-bootstrap-gamma@v1', prod: 'aws/cdk-bootstrap@v1', }, + publishBlueprint: { + default: 'aws/publish-blueprint-action@v1', + prod: 'aws/publish-blueprint-action@v1', + }, }; export function getDefaultActionIdentifier(alias: ActionIdentifierAlias, environmentIdentifier: string = 'default'): string | undefined { @@ -51,7 +57,9 @@ type TypeSupportedActions = | CfnDeployActionConfiguration | TestActionConfiguration | CdkDeployActionYamlOutput - | CdkBootstrapActionConfiguration; + | CdkBootstrapActionConfiguration + | PublishBlueprintActionConfiguration; + export interface ActionDefiniton { Identifier?: string; Compute?: TypeSupportedCompute | string; diff --git a/packages/components/workflows/src/workflow/workflow-builder.ts b/packages/components/workflows/src/workflow/workflow-builder.ts index bbcfba813..073cdca47 100644 --- a/packages/components/workflows/src/workflow/workflow-builder.ts +++ b/packages/components/workflows/src/workflow/workflow-builder.ts @@ -7,6 +7,7 @@ import { addGenericCdkBootstrapAction, CdkBootstrapActionParameters } from '../a import { addGenericCdkDeployAction, CdkDeployActionParameters } from '../actions/action-cdk-deploy'; import { addGenericCloudFormationCleanupAction, CfnCleanupActionParameters } from '../actions/action-cfn-cleanup'; import { addGenericCloudFormationDeployAction, CfnDeployActionParameters } from '../actions/action-cfn-deploy'; +import { addGenericPublishBlueprintAction, PublishBlueprintActionParameters } from '../actions/action-publish-blueprint'; import { addGenericTestReports, TestReportActionParameters } from '../actions/action-test-reports'; export class WorkflowBuilder { @@ -99,4 +100,12 @@ export class WorkflowBuilder { workflow: this.definition, }); } + + addPublishBlueprintAction(configuration: PublishBlueprintActionParameters) { + addGenericPublishBlueprintAction({ + ...configuration, + blueprint: this.blueprint, + workflow: this.definition, + }); + } }