-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
…ints into experimental-sdk
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { TriggerType, WorkflowBuilder } from '@amazon-codecatalyst/blueprint-component.workflows'; | ||
|
||
export function buildReleaseWorkflow(workflow: WorkflowBuilder, options?: { includePublishStep?: boolean }): WorkflowBuilder { | ||
const publishingEnabled = options?.includePublishStep ?? true; | ||
|
||
workflow.setName('blueprint-release'); | ||
const RELEASE_COMMIT_PREFIX = 'chore(release):'; | ||
const BUILD_ARTIFACT_NAME = 'codebase'; | ||
|
||
workflow.addBranchTrigger(['main']); | ||
workflow.addTrigger({ | ||
Type: TriggerType.MANUAL, | ||
}); | ||
workflow.addBuildAction({ | ||
actionName: 'check_commit', | ||
input: { | ||
Sources: ['WorkflowSource'], | ||
}, | ||
output: { | ||
Variables: ['IS_RELEASE_COMMIT'], | ||
}, | ||
steps: [ | ||
'TRIGGER_COMMIT_ID=$CATALYST_EVENT_SHA', | ||
'COMMIT_MESSAGE="$(git log -n 1 $TRIGGER_COMMIT_ID --oneline)"', | ||
`RELEASE_PREFIX='${RELEASE_COMMIT_PREFIX}'`, | ||
'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_and_commit', | ||
dependsOn: ['check_commit'], | ||
input: { | ||
Sources: ['WorkflowSource'], | ||
Variables: { | ||
IS_RELEASE_COMMIT: '${check_commit.IS_RELEASE_COMMIT}', | ||
}, | ||
}, | ||
output: { | ||
Artifacts: [ | ||
{ | ||
Name: BUILD_ARTIFACT_NAME, | ||
Files: ['**/*'], | ||
}, | ||
], | ||
}, | ||
steps: ["if $IS_RELEASE_COMMIT; then echo 'This is a release commit, skipping'; else chmod +x release.sh && ./release.sh; fi"], | ||
}); | ||
|
||
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; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This script is used by the blueprint-release workflow to build | ||
# the blueprint, bump its package version, and commit the version | ||
# bump back into the repository. | ||
echo "Installing dependencies..." | ||
yum install -y rsync | ||
npm install -g yarn | ||
yarn | ||
|
||
echo "Building blueprint..." | ||
yarn build | ||
|
||
echo "Bumping package version..." | ||
yarn bump | ||
NEW_VERSION=`jq -r .version package.json` | ||
yarn blueprint:package | ||
|
||
echo "Getting credentials..." | ||
MI=`curl $AWS_CONTAINER_TOKEN_ENDPOINT` | ||
ACCESS_KEY_ID=$(echo "$MI" | jq -r '.AccessKeyId') | ||
SECRET_ACCESS_KEY=$(echo "$MI" | jq -r '.SecretAccessKey') | ||
ORIGINAL_REMOTE=`git config --get remote.origin.url` | ||
SOURCE_REPO_URL=`sed -e "s^//^//$ACCESS_KEY_ID:$SECRET_ACCESS_KEY@^" <<< $ORIGINAL_REMOTE` | ||
echo "Configuring git..." | ||
git remote set-url origin $SOURCE_REPO_URL | ||
git config --global user.email "noreply@amazon.com" | ||
git config --global user.name "Release Workflow" | ||
echo "Committing changes..." | ||
git add . | ||
RELEASE_COMMIT_MESSAGE="chore(release): release $NEW_VERSION" | ||
git commit -m "$RELEASE_COMMIT_MESSAGE" | ||
echo "Pushing to origin..." | ||
git push origin HEAD:main |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.