From 5cc7dd006e54d315989d59d068a586e858f1ee59 Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 28 Apr 2025 15:51:38 -0700 Subject: [PATCH 1/4] chore(enum-updater): split out workflows and fix combined changes issue --- .github/workflows/enum-auto-updater.yml | 65 ++++++++----------- .../workflows/enum-static-mapping-updater.yml | 64 ++++++++++++++++++ 2 files changed, 91 insertions(+), 38 deletions(-) create mode 100644 .github/workflows/enum-static-mapping-updater.yml diff --git a/.github/workflows/enum-auto-updater.yml b/.github/workflows/enum-auto-updater.yml index 194d628987ef4..b4255aebf9270 100644 --- a/.github/workflows/enum-auto-updater.yml +++ b/.github/workflows/enum-auto-updater.yml @@ -1,8 +1,8 @@ name: CDK Enums Auto Updater on: workflow_dispatch: - schedule: - - cron: '0 0 * * 1' + schedule: # Runs every Monday at 1pm PT + - cron: '0 13 * * 1' jobs: update-l2-enums: @@ -25,11 +25,6 @@ jobs: - name: Install dependencies run: cd tools/@aws-cdk/enum-updater && yarn install --frozen-lockfile && yarn build - - name: Update enum static mapping - run: | - cd tools/@aws-cdk/enum-updater - ./bin/update-static-enum-mapping - - name: Check for changes id: static-mapping-check run: | @@ -39,29 +34,6 @@ jobs: else echo "changes=false" >> $GITHUB_OUTPUT fi - - - name: Create PR for static mapping changes - if: steps.static-mapping-check.outputs.changes == 'true' - run: | - cd tools/@aws-cdk/enum-updater - git config --global user.name 'aws-cdk-automation' - git config --global user.email 'aws-cdk-automation@users.noreply.github.com' - - # Create a new branch for the module - branchName="enum-update/static-mapping-update" - git checkout -b "$branchName" - - git add . # Add all files changed - git commit -m "chore: update enum static mapping" - git push origin "$branchName" - - gh pr create --title "chore: update enum static mapping" \ - --body "This PR updates the CDK enum mapping file." \ - --base main \ - --head "$branchName" \ - --label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Identify Missing Values and Apply Code Changes run: | @@ -83,8 +55,16 @@ jobs: # Iterate through each module directory that has changes git config --global user.name 'aws-cdk-automation' git config --global user.email 'aws-cdk-automation@users.noreply.github.com' + + # Store the original branch name + original_branch=$(git rev-parse --abbrev-ref HEAD) + for module in $(git diff --name-only | grep -E '^packages/(@aws-cdk|aws-cdk-lib)/.*' | sed -E 's|^packages/(@aws-cdk\|aws-cdk-lib)/([^/]+).*|\2|' | sort -u); do moduleName=$(basename $module) + + # Reset to clean state + git reset --hard HEAD + git clean -fd # Determine the correct path for the module if [[ -d "packages/aws-cdk-lib/$module" ]]; then @@ -105,21 +85,30 @@ jobs: gh pr close "$prExists" --confirm # Close the PR by its number fi - # Create a new branch for the module + # Create/switch to branch for the module branchName="enum-update/${moduleName#aws-}" - git checkout -b "$branchName" + git checkout -B "$branchName" $original_branch # -B forces branch creation/reset + + # Re-run the update script for this specific module + cd tools/@aws-cdk/enum-updater + ./bin/update-missing-enums + cd ../../.. # Stage, commit, and push changes for the module git add "$modulePath" # Using the correct path git commit -m "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" git push origin "$branchName" - # Create a new pull request - gh pr create --title "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" \ - --body "This PR updates the enum values for ${moduleName#aws-}." \ - --base main \ - --head "$branchName" \ - --label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test" + # Create a new pull request + gh pr create --title "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" \ + --body "This PR updates the enum values for ${moduleName#aws-}." \ + --base main \ + --head "$branchName" \ + --label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test" + + # Return to original branch + git checkout $original_branch + done env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/enum-static-mapping-updater.yml b/.github/workflows/enum-static-mapping-updater.yml new file mode 100644 index 0000000000000..a595caf82c3c3 --- /dev/null +++ b/.github/workflows/enum-static-mapping-updater.yml @@ -0,0 +1,64 @@ +name: CDK Enums Auto Updater +on: + workflow_dispatch: + schedule: # Runs every Monday at 12am PT + - cron: '0 0 * * 1' + +jobs: + update-l2-enums: + if: github.repository == 'aws/aws-cdk' + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Check Out + uses: actions/checkout@v4 + + - name: Set up Node + uses: actions/setup-node@v4 + with: + node-version: "*" + env: + NODE_OPTIONS: "--max-old-space-size=8196 --experimental-worker ${NODE_OPTIONS:-}" + + - name: Install dependencies + run: cd tools/@aws-cdk/enum-updater && yarn install --frozen-lockfile && yarn build + + - name: Update enum static mapping + run: | + cd tools/@aws-cdk/enum-updater + ./bin/update-static-enum-mapping + + - name: Check for changes + id: static-mapping-check + run: | + cd tools/@aws-cdk/enum-updater + if [[ -n "$(git status --porcelain ./lib/static-enum-mapping.json)" ]]; then + echo "changes=true" >> $GITHUB_OUTPUT + else + echo "changes=false" >> $GITHUB_OUTPUT + fi + + - name: Create PR for static mapping changes + if: steps.static-mapping-check.outputs.changes == 'true' + run: | + cd tools/@aws-cdk/enum-updater + git config --global user.name 'aws-cdk-automation' + git config --global user.email 'aws-cdk-automation@users.noreply.github.com' + + # Create a new branch for the module + branchName="enum-update/static-mapping-update" + git checkout -b "$branchName" + + git add . # Add all files changed + git commit -m "chore: update enum static mapping" + git push origin "$branchName" + + gh pr create --title "chore: update enum static mapping" \ + --body "This PR updates the CDK enum mapping file." \ + --base main \ + --head "$branchName" \ + --label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 373ff11cfcbb6380ce5b8d5cc3783700bdc81803 Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 28 Apr 2025 16:41:30 -0700 Subject: [PATCH 2/4] add logging + fix open PR check --- .github/workflows/enum-auto-updater.yml | 157 +++++++++++++++--------- 1 file changed, 97 insertions(+), 60 deletions(-) diff --git a/.github/workflows/enum-auto-updater.yml b/.github/workflows/enum-auto-updater.yml index b4255aebf9270..1a5ef90dae6c9 100644 --- a/.github/workflows/enum-auto-updater.yml +++ b/.github/workflows/enum-auto-updater.yml @@ -49,66 +49,103 @@ jobs: echo "changes=false" >> $GITHUB_OUTPUT fi - - name: Commit & Push changes - if: steps.git-check.outputs.changes == 'true' - run: | - # Iterate through each module directory that has changes - git config --global user.name 'aws-cdk-automation' - git config --global user.email 'aws-cdk-automation@users.noreply.github.com' - - # Store the original branch name - original_branch=$(git rev-parse --abbrev-ref HEAD) - - for module in $(git diff --name-only | grep -E '^packages/(@aws-cdk|aws-cdk-lib)/.*' | sed -E 's|^packages/(@aws-cdk\|aws-cdk-lib)/([^/]+).*|\2|' | sort -u); do - moduleName=$(basename $module) - - # Reset to clean state - git reset --hard HEAD - git clean -fd - - # Determine the correct path for the module - if [[ -d "packages/aws-cdk-lib/$module" ]]; then - modulePath="packages/aws-cdk-lib/$module" - elif [[ -d "packages/@aws-cdk/$module" ]]; then - modulePath="packages/@aws-cdk/$module" - else - echo "Cannot find module directory for $module" - continue - fi - - # Check for existing PR with the same name - prExists=$(gh pr list --state open --search "feat(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" --json number,title -q '.[].number') - - # If a PR exists, close it and continue - if [[ -n "$prExists" ]]; then - echo "PR already exists for module ${moduleName#aws-}, closing the existing PR." - gh pr close "$prExists" --confirm # Close the PR by its number - fi - - # Create/switch to branch for the module - branchName="enum-update/${moduleName#aws-}" - git checkout -B "$branchName" $original_branch # -B forces branch creation/reset - - # Re-run the update script for this specific module - cd tools/@aws-cdk/enum-updater - ./bin/update-missing-enums - cd ../../.. + - name: Commit & Push changes + if: steps.git-check.outputs.changes == 'true' + run: | + # Enable command logging + set -x + + echo "=== Starting PR creation process ===" + + # Iterate through each module directory that has changes + echo "Storing original branch name..." + git config --global user.name 'aws-cdk-automation' + git config --global user.email 'aws-cdk-automation@users.noreply.github.com' + + # Store the original branch name + echo "Storing original branch name..." + original_branch=$(git rev-parse --abbrev-ref HEAD) + echo "Original branch: $original_branch" + + for module in $(git diff --name-only | grep -E '^packages/(@aws-cdk|aws-cdk-lib)/.*' | sed -E 's|^packages/(@aws-cdk\|aws-cdk-lib)/([^/]+).*|\2|' | sort -u); do + echo "=== Processing module: $module ===" + moduleName=$(basename $module) + echo "Module name: $moduleName" + + # Reset to clean state + echo "Resetting to clean state..." + git reset --hard HEAD + git clean -fd + + # Determine the correct path for the module + echo "Determining module path..." + if [[ -d "packages/aws-cdk-lib/$module" ]]; then + modulePath="packages/aws-cdk-lib/$module" + echo "Found module in aws-cdk-lib: $modulePath" + elif [[ -d "packages/@aws-cdk/$module" ]]; then + modulePath="packages/@aws-cdk/$module" + echo "Found module in @aws-cdk: $modulePath" + else + echo "ERROR: Cannot find module directory for $module" + continue + fi - # Stage, commit, and push changes for the module - git add "$modulePath" # Using the correct path - git commit -m "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" - git push origin "$branchName" - - # Create a new pull request - gh pr create --title "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" \ - --body "This PR updates the enum values for ${moduleName#aws-}." \ - --base main \ - --head "$branchName" \ - --label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test" - - # Return to original branch - git checkout $original_branch - - done + # Check for existing PR with the same name + prExists=$(gh pr list --state open --search "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" --json number,title -q '.[].number') + + # If a PR exists, close it + if [[ -n "$prExists" ]]; then + echo "Found existing PR #$prExists for module ${moduleName#aws-}, closing it..." + gh pr close "$prExists" --confirm + else + echo "No existing PR found for ${moduleName#aws-}" + fi + + # Create/switch to branch for the module + branchName="enum-update/${moduleName#aws-}" + echo "Creating/switching to branch: $branchName" + git checkout -B "$branchName" $original_branch # -B forces branch creation/reset + + # Re-run the update script for this specific module + echo "Re-running update script..." + echo "Current directory: $(pwd)" + cd tools/@aws-cdk/enum-updater + echo "Running update-missing-enums script..." + ./bin/update-missing-enums + cd ../../.. + echo "Returned to: $(pwd)" + + echo "Checking for changes after update..." + git status + + # Stage, commit, and push changes for the module + echo "Staging changes for $modulePath" + git add "$modulePath" + + echo "Committing changes..." + git commit -m "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" + + # Force push to overwrite any existing branch + echo "Force pushing to remote..." + git push -f origin "$branchName" + + + # Create a new pull request + echo "Creating pull request..." + gh pr create --title "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" \ + --body "This PR updates the enum values for ${moduleName#aws-}." \ + --base main \ + --head "$branchName" \ + --label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test" + + # Return to original branch + echo "Returning to original branch: $original_branch" + git checkout $original_branch + + echo "=== Completed processing for module: $module ===" + done + + # Disable command logging + set +x env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 90b72cb7f46b94f207bc52bdd6c6abd489fc2721 Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Mon, 28 Apr 2025 16:57:48 -0700 Subject: [PATCH 3/4] add -f flag to static mapping update workflow --- .github/workflows/enum-static-mapping-updater.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/enum-static-mapping-updater.yml b/.github/workflows/enum-static-mapping-updater.yml index a595caf82c3c3..90a838d05796d 100644 --- a/.github/workflows/enum-static-mapping-updater.yml +++ b/.github/workflows/enum-static-mapping-updater.yml @@ -53,7 +53,7 @@ jobs: git add . # Add all files changed git commit -m "chore: update enum static mapping" - git push origin "$branchName" + git push -f origin "$branchName" gh pr create --title "chore: update enum static mapping" \ --body "This PR updates the CDK enum mapping file." \ From 9edb0a09a8a2fedb27a869589af283e8e8d2eadb Mon Sep 17 00:00:00 2001 From: Paul Sun Date: Tue, 29 Apr 2025 13:33:37 -0700 Subject: [PATCH 4/4] remove static mapping updates check --- .github/workflows/enum-auto-updater.yml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/enum-auto-updater.yml b/.github/workflows/enum-auto-updater.yml index 1a5ef90dae6c9..02b4b725b06b2 100644 --- a/.github/workflows/enum-auto-updater.yml +++ b/.github/workflows/enum-auto-updater.yml @@ -25,16 +25,6 @@ jobs: - name: Install dependencies run: cd tools/@aws-cdk/enum-updater && yarn install --frozen-lockfile && yarn build - - name: Check for changes - id: static-mapping-check - run: | - cd tools/@aws-cdk/enum-updater - if [[ -n "$(git status --porcelain ./lib/static-enum-mapping.json)" ]]; then - echo "changes=true" >> $GITHUB_OUTPUT - else - echo "changes=false" >> $GITHUB_OUTPUT - fi - - name: Identify Missing Values and Apply Code Changes run: | cd tools/@aws-cdk/enum-updater