Skip to content

Automatically update bootstrap template #897

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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
116 changes: 87 additions & 29 deletions .github/workflows/DetectCDKBootstrapVersionChanges.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,107 @@
name: Detect CDK Bootstrap Version Changes

on: [pull_request]
on:
schedule:
# Runs at 00:00 UTC every Monday
- cron: '0 0 * * 1'
workflow_dispatch:

permissions:
contents: write
pull-requests: write
id-token: write

jobs:
detect-cdk-bootstrap-changes:
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@ececac1a45f3b08a01d2dd070d28d111c5fe6722 #v4.1.0
with:
role-to-assume: ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_ROLE_ARN }}
aws-region: us-west-2

- name: Retrieve secret from AWS Secrets Manager
uses: aws-actions/aws-secretsmanager-get-secrets@fbd65ea98e018858715f591f03b251f02b2316cb #v2.0.8
with:
secret-ids: |
AWS_SECRET, ${{ secrets.RELEASE_WORKFLOW_ACCESS_TOKEN_NAME }}
parse-json-secrets: true

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
with:
fetch-depth: '0'
ref: dev
token: ${{ env.AWS_SECRET_TOKEN }}

- name: Setup .NET
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 #v4.3.1
with:
dotnet-version: '8.0.x'

- name: Install AWS CDK
run: |
npm install -g aws-cdk
cdk acknowledge 32775
- name: Get Staging Bucket Update/Replace Policy
id: stagingBucketUpdateReplacePolicy
run: |
echo "update-replace-policy=$(yq '.Resources.StagingBucket.UpdateReplacePolicy' 'src/AWS.Deploy.Orchestration/CDK/CDKBootstrapTemplate.yaml')" >> $GITHUB_OUTPUT
- name: Get Staging Bucket Deletion Policy
id: stagingBucketDeletionPolicy

- name: Create temporary directory
run: mkdir -p temp_cdk

- name: Save New CDK Bootstrap Template
working-directory: temp_cdk
run: |
echo "deletion-policy=$(yq '.Resources.StagingBucket.DeletionPolicy' 'src/AWS.Deploy.Orchestration/CDK/CDKBootstrapTemplate.yaml')" >> $GITHUB_OUTPUT
- name: Fail If Update/Replace Policy Not 'Delete'
if: steps.stagingBucketUpdateReplacePolicy.outputs.update-replace-policy != 'Delete'
cdk acknowledge 32775
cdk bootstrap --show-template > newTemplate.yml

- name: Update Template with Required Policies
working-directory: temp_cdk
run: |
echo "The 'UpdateReplacePolicy' of the 'StaginBucket' in the CDK bootstrap template should be 'Delete'."
exit 1
- name: Fail If Deletion Policy Not 'Delete'
if: steps.stagingBucketDeletionPolicy.outputs.deletion-policy != 'Delete'
yq eval '.Resources.StagingBucket.UpdateReplacePolicy = "Delete"' -i newTemplate.yml
yq eval '.Resources.StagingBucket.DeletionPolicy = "Delete"' -i newTemplate.yml

- name: Check for version changes
id: check_version
run: |
echo "The 'DeletionPolicy' of the 'StaginBucket' in the CDK bootstrap template should be 'Delete'."
exit 1
- name: Save New CDK Bootstrap Template
OLD_VERSION=$(yq eval '.Resources.CdkBootstrapVersion.Properties.Value' src/AWS.Deploy.Orchestration/CDK/CDKBootstrapTemplate.yaml)
NEW_VERSION=$(yq eval '.Resources.CdkBootstrapVersion.Properties.Value' temp_cdk/newTemplate.yml)

if [ "$OLD_VERSION" != "$NEW_VERSION" ]; then
echo "Version changed from $OLD_VERSION to $NEW_VERSION"
echo "version_changed=true" >> $GITHUB_OUTPUT
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
else
echo "No version change detected"
echo "version_changed=false" >> $GITHUB_OUTPUT
fi

- name: Update CDK Bootstrap Template
if: steps.check_version.outputs.version_changed == 'true'
run: |
cdk bootstrap --show-template > newTemplate.yml
- name: Get Latest CDK Bootstrap Version
id: latestBootstrapVersion
cp temp_cdk/newTemplate.yml src/AWS.Deploy.Orchestration/CDK/CDKBootstrapTemplate.yaml

- name: Generate change file
if: steps.check_version.outputs.version_changed == 'true'
env:
NEW_VERSION: ${{ steps.check_version.outputs.new_version }}
run: |
echo "latest-version=$(yq '.Resources.CdkBootstrapVersion.Properties.Value' 'newTemplate.yml')" >> $GITHUB_OUTPUT
- name: Get Current CDK Bootstrap Version
id: currentBootstrapVersion
dotnet tool install -g autover --version 0.0.25
autover change --project-name "AWS.Deploy.CLI" -m "Update CDK Bootstrap template to version $NEW_VERSION"

- name: Setup Git User
run: |
echo "current-version=$(yq '.Resources.CdkBootstrapVersion.Properties.Value' 'src/AWS.Deploy.Orchestration/CDK/CDKBootstrapTemplate.yaml')" >> $GITHUB_OUTPUT
- name: Fail If CDK Bootstrap Template Changes Detected
if: steps.currentBootstrapVersion.outputs.current-version != steps.latestBootstrapVersion.outputs.latest-version
git config --global user.email "[email protected]"
git config --global user.name "aws-sdk-dotnet-automation"

- name: Create Pull Request
if: steps.check_version.outputs.version_changed == 'true'
env:
GITHUB_TOKEN: ${{ env.AWS_SECRET_TOKEN }}
run: |
echo "A new version of the AWS CDK Bootstrap Template is available. The current template that is being used by the Deploy tool needs to be updated."
exit 1
git checkout -b update-cdk-bootstrap-template
git add src/AWS.Deploy.Orchestration/CDK/CDKBootstrapTemplate.yaml .autover/
git commit -m "chore: update CDK bootstrap template to version ${{ steps.check_version.outputs.new_version }}"
git push origin update-cdk-bootstrap-template
gh pr create \
--title "Update CDK Bootstrap Template to Version ${{ steps.check_version.outputs.new_version }}" \
--base dev \
--head update-cdk-bootstrap-template \
--delete-branch
3 changes: 1 addition & 2 deletions src/AWS.Deploy.Orchestration/CDK/CDKBootstrapTemplate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -658,5 +658,4 @@ Outputs:
Value:
Fn::GetAtt:
- CdkBootstrapVersion
- Value

- Value
Loading