Skip to content

Commit

Permalink
feat(blueprint-builder): Add publishing action toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
aggagen committed Nov 16, 2023
1 parent ab91cb2 commit 730c00b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 26 deletions.
20 changes: 15 additions & 5 deletions packages/blueprints/blueprint-builder/src/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export interface Options extends ParentOptions {
* If this is set, the blueprint will generate a release workflow. On push to main, a workflow will release this blueprint into your codecatalyst space.
*/
releaseWorkflow?: boolean;

/**
* Include a publishing step in the release workflow?
* If this is set, the generated release workflow will contain a publishing action.
* @hidden
*/
includePublishingAction?: boolean;
};
}

Expand Down Expand Up @@ -230,12 +237,15 @@ export class Blueprint extends ParentBlueprint {
},
});

/**
* todo: remove this once the release workflow is available in production
*/
if (this.context.environmentId == 'default' || options.advancedSettings.releaseWorkflow) {
if (options.advancedSettings.releaseWorkflow) {
const releaseWorkflow = new WorkflowBuilder(this);
new Workflow(this, repository, buildReleaseWorkflow(releaseWorkflow, repository).getDefinition());
new Workflow(
this,
repository,
buildReleaseWorkflow(releaseWorkflow, repository, {
includePublishStep: options.advancedSettings.includePublishingAction,
}).getDefinition(),
);
}
}

Expand Down
49 changes: 29 additions & 20 deletions packages/blueprints/blueprint-builder/src/build-release-workflow.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { SourceFile, SourceRepository, SubstitionAsset } from '@amazon-codecatalyst/blueprint-component.source-repositories';
import { TriggerType, WorkflowBuilder } from '@amazon-codecatalyst/blueprint-component.workflows';

export function buildReleaseWorkflow(workflow: WorkflowBuilder, repository: SourceRepository): WorkflowBuilder {
export function buildReleaseWorkflow(
workflow: WorkflowBuilder,
repository: SourceRepository,
options?: { includePublishStep?: boolean },
): WorkflowBuilder {
const publishingEnabled = options?.includePublishStep ?? true;

workflow.setName('blueprint-release');
const RELEASE_COMMIT_PREFIX = 'chore(release):';
const BUILD_ARTIFACT_NAME = 'codebase';
Expand Down Expand Up @@ -48,25 +54,28 @@ export function buildReleaseWorkflow(workflow: WorkflowBuilder, repository: Sour
},
steps: ["if $IS_RELEASE_COMMIT; then echo 'This is a release commit, skipping'; else chmod +x release.sh && ./release.sh; fi"],
});
workflow.addPublishBlueprintAction({
actionName: 'publish_blueprint',
dependsOn: ['build_and_commit'],
inputs: {
Artifacts: [BUILD_ARTIFACT_NAME],
Variables: [
{
Name: 'IS_RELEASE_COMMIT',
Value: '${check_commit.IS_RELEASE_COMMIT}',
},
],
},
configuration: {
ArtifactPackagePath: 'dist/js/*.tgz',
PackageJSONPath: 'package.json',
InputArtifactName: BUILD_ARTIFACT_NAME,
TimeoutInSeconds: '120',
},
});

if (publishingEnabled) {
workflow.addPublishBlueprintAction({
actionName: 'publish_blueprint',
dependsOn: ['build_and_commit'],
inputs: {
Artifacts: [BUILD_ARTIFACT_NAME],
Variables: [
{
Name: 'IS_RELEASE_COMMIT',
Value: '${check_commit.IS_RELEASE_COMMIT}',
},
],
},
configuration: {
ArtifactPackagePath: 'dist/js/*.tgz',
PackageJSONPath: 'package.json',
InputArtifactName: BUILD_ARTIFACT_NAME,
TimeoutInSeconds: '120',
},
});
}

return workflow;
}
3 changes: 2 additions & 1 deletion packages/blueprints/blueprint-builder/src/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"blueprintPackageName": "",
"license": "Apache-2.0",
"tags": ["first-label", "second-label"],
"releaseWorkflow": true
"releaseWorkflow": true,
"includePublishingAction": true
}
}

0 comments on commit 730c00b

Please sign in to comment.