Skip to content
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

chore(enum-updater): add enum updater tool #33681

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
extract code writing logic to enum-updater tool + add workflow file
  • Loading branch information
paulhcsun committed Feb 28, 2025
commit 6d600c74a4ef10f8297512b2f91cb4fe6fe7c835
79 changes: 79 additions & 0 deletions .github/workflows/enum-auto-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: CDK Enums Auto Updater
on:
workflow_dispatch:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we trigger this workflow only manually? Should it require any cron schedule to run automatically?


jobs:
update-analytics-metadata:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It would be better to rename the job name related to enum specific for better readability.

if: github.repository == 'aws/aws-cdk'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- 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: yarn install --frozen-lockfile && cd tools/@aws-cdk/enum-updater && yarn build

- name: Update Enum Static Mapping
run: |
cd tools/@aws-cdk/enum-updater
./bin/update-enums
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it should be update-static-enum-mapping instead?


- name: Identify Missing Values and Apply Code Changes
run: |
cd tools/@aws-cdk/enum-updater
./bin/update-enums
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it should be update-missing-enums instead?


- name: Commit & Push changes
if: steps.git-check.outputs.changes == 'true'
run: |
git config --global user.name 'aws-cdk-automation'
git config --global user.email 'aws-cdk-automation@users.noreply.github.com'

# Iterate through each module directory that has changes
for module in $(git diff --name-only | grep -E '^packages/(@aws-cdk|aws-cdk-lib)/.*' | sed 's|/.*||' | sort -u); do
moduleName=$(basename $module)

# 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 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 a new branch for the module
branchName="enum-update/${moduleName#aws-}"
git checkout -b "$branchName"

# Stage, commit, and push changes for the module
git add "packages/$module" # Add only changes for this module
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"
done

# - name: Commit & Push changes
# if: steps.git-check.outputs.changes == 'true'
# run: |
# git config --global user.name 'aws-cdk-automation'
# git config --global user.email 'aws-cdk-automation@users.noreply.github.com'

# git checkout -B ${{ github.event.pull_request.head.ref }}
# git add .
# git commit -m "chore: update analytics metadata blueprints"
# git push origin ${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
40 changes: 14 additions & 26 deletions tools/@aws-cdk/construct-metadata-updater/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
// import { EnumLikeUpdater } from './metadata-updater';
import { EnumLikeUpdater } from './metadata-updater';
// TODO: Uncomment out the rest of the updaters and tweak the import before raising a PR.
// If you're reading this on GitHub, someone forgot to double-check!
import { ConstructsUpdater, EnumLikeUpdater, EnumsUpdater, MethodsUpdater, PropertyUpdater } from './metadata-updater';

export function main() {
const dir = '../../../../packages/'

// new ConstructsUpdater(dir).execute();
// console.log('Constructs updater finished.');
// new ConstructsUpdater(dir).execute();
// console.log('Constructs updater finished.');

// new PropertyUpdater(dir).execute();
// console.log('Property updater finished.')
// new PropertyUpdater(dir).execute();
// console.log('Property updater finished.')

// new EnumsUpdater(dir).execute();
// console.log('Enums updater finished.');
// new EnumsUpdater(dir).execute();
// console.log('Enums updater finished.');

// new MethodsUpdater(dir).execute();
// console.log('Methods updater finished.');
// new MethodsUpdater(dir).execute();
// console.log('Methods updater finished.');
new ConstructsUpdater(dir).execute();
console.log('Constructs updater finished.');

// new EnumLikeUpdater(dir).TEST();
// // console.log('Enum-like updater finished.');
new PropertyUpdater(dir).execute();
console.log('Property updater finished.')

new EnumLikeUpdater(dir).TEST();
new EnumsUpdater(dir).execute();
console.log('Enums updater finished.');

new EnumLikeUpdater(dir).execute();
console.log('Enums-like updater finished.');

new MethodsUpdater(dir).execute();
console.log('Methods updater finished.');
}
Loading
Oops, something went wrong.