Skip to content

Commit 2ebac0a

Browse files
authored
chore(enum-updater): fix github workflow and add exclude list (#33957)
### Reason for this change The current enum updater workflow is broken. The PR is to fix that and add some other improvements. ### Description of changes - Fix enum updater workflow - add exclusion list so some enum values can be excluded from generation of the tool - bug fix ### Description of how you validated changes ### Checklist - [ ] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 21d0a5c commit 2ebac0a

File tree

4 files changed

+58
-10
lines changed

4 files changed

+58
-10
lines changed

.github/workflows/enum-auto-updater.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
NODE_OPTIONS: "--max-old-space-size=8196 --experimental-worker ${NODE_OPTIONS:-}"
2222

2323
- name: Install dependencies
24-
run: yarn install --frozen-lockfile && cd tools/@aws-cdk/enum-updater && yarn build
24+
run: cd tools/@aws-cdk/enum-updater && yarn install --frozen-lockfile && yarn build
2525

2626
- name: Identify Missing Values and Apply Code Changes
2727
run: |
@@ -46,6 +46,16 @@ jobs:
4646
# Iterate through each module directory that has changes
4747
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
4848
moduleName=$(basename $module)
49+
50+
# Determine the correct path for the module
51+
if [[ -d "packages/aws-cdk-lib/$module" ]]; then
52+
modulePath="packages/aws-cdk-lib/$module"
53+
elif [[ -d "packages/@aws-cdk/$module" ]]; then
54+
modulePath="packages/@aws-cdk/$module"
55+
else
56+
echo "Cannot find module directory for $module"
57+
continue
58+
fi
4959
5060
# Check for existing PR with the same name
5161
prExists=$(gh pr list --state open --search "feat(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" --json number,title -q '.[].number')
@@ -61,7 +71,7 @@ jobs:
6171
git checkout -b "$branchName"
6272
6373
# Stage, commit, and push changes for the module
64-
git add "packages/$module" # Add only changes for this module
74+
git add "$modulePath" # Using the correct path
6575
git commit -m "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}"
6676
git push origin "$branchName"
6777
@@ -70,9 +80,7 @@ jobs:
7080
--body "This PR updates the enum values for ${moduleName#aws-}." \
7181
--base main \
7282
--head "$branchName"
73-
--label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test" \
74-
--reviewer "aws-cdk-team" \
83+
--label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test"
7584
done
76-
7785
env:
7886
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"codebuild": {
3+
"ComputeType": ["BUILD_LAMBDA_10GB"]
4+
},
5+
"eks": {
6+
"AmiType": ["CUSTOM"]
7+
},
8+
"lambda": {
9+
"UpdateRuntimeOn": ["Manual"]
10+
},
11+
"autoscaling": {
12+
"VolumeType": ["io2"]
13+
}
14+
}

tools/@aws-cdk/enum-updater/lib/missing-enum-updater.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ export class MissingEnumsUpdater {
311311
let textToInsert = hasDoubleLineBreaks ? '\n' : '';
312312

313313
newEnumValues.forEach((enumVal: string, index: number) => {
314-
const enumConstantName = enumVal.toUpperCase().replace(/[^A-Z0-9]+/g, '_').replace(/_+$/, '');
314+
// Make sure enumValue is a string
315+
const enumValue = enumVal.toString();
316+
const enumConstantName = enumValue.toUpperCase().replace(/[^A-Z0-9]+/g, '_').replace(/_+$/, '');
315317

316318
textToInsert += ` /**\n * PLACEHOLDER_COMMENT_TO_BE_FILLED_OUT\n */\n`;
317-
textToInsert += ` ${enumConstantName} = '${enumVal}'`;
319+
textToInsert += ` ${enumConstantName} = '${enumValue}'`;
318320

319321
// Add a comma and appropriate newlines after each member
320322
textToInsert += ',';

tools/@aws-cdk/enum-updater/lib/static-enum-mapping-updater.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,33 @@ export interface SdkEnums {
3030
}
3131

3232

33-
function extractEnums(schema: Record<string, any>, enums: { [enumName: string]: (string | number)[] }) {
33+
function extractEnums(schema: Record<string, any>, enums: { [enumName: string]: (string | number)[] }, excludeDict: Record<string, any>) {
3434
// Helper function to process a property and its potential enum values
3535
function processProperty(propertyName: string, property: any) {
3636
if (property.enum) {
37+
if (propertyName in excludeDict) {
38+
const excludeList = excludeDict[propertyName] as string[];
39+
if (excludeList && excludeList.length > 0) {
40+
// if property.enum include a value in excludeList, ignore the value
41+
const filteredEnum = property.enum.filter((value: string) => !excludeList.includes(value));
42+
enums[propertyName] = filteredEnum;
43+
}
44+
}
45+
else {
3746
enums[propertyName] = property.enum;
47+
}
3848
} else if (property.items?.enum) {
39-
enums[propertyName] = property.items.enum;
49+
if (propertyName in excludeDict) {
50+
const excludeList = excludeDict[propertyName] as string[];
51+
if (excludeList) {
52+
// if property.enum include a value in excludeList, ignore the value
53+
const filteredEnum = property.item.enum.filter((value: string) => !excludeList.includes(value));
54+
enums[propertyName] = filteredEnum;
55+
}
56+
}
57+
else {
58+
enums[propertyName] = property.enum;
59+
}
4060
}
4161

4262
// Process nested properties
@@ -213,6 +233,8 @@ export async function parseAwsSdkEnums(sdkModelsPath: string): Promise<void> {
213233
try {
214234
const jsonFiles = getJsonFiles(sdkModelsPath);
215235

236+
const excludeEnums = readJsonFile(path.join(__dirname, 'exclude-values.json'));
237+
216238
for (const file of jsonFiles) {
217239
try {
218240
if (file == 'module.json') {
@@ -224,8 +246,10 @@ export async function parseAwsSdkEnums(sdkModelsPath: string): Promise<void> {
224246

225247
const enumMap = sdkEnums[service] ?? {};
226248

249+
const excludeList = excludeEnums[service] ?? [];
250+
227251
// Extract enums
228-
extractEnums(jsonData, enumMap);
252+
extractEnums(jsonData, enumMap, excludeList);
229253

230254
sdkEnums[service] = enumMap;
231255
} catch (error) {

0 commit comments

Comments
 (0)