Skip to content
Merged
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
18 changes: 13 additions & 5 deletions .github/workflows/enum-auto-updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
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
run: cd tools/@aws-cdk/enum-updater && yarn install --frozen-lockfile && yarn build

- name: Identify Missing Values and Apply Code Changes
run: |
Expand All @@ -46,6 +46,16 @@ jobs:
# Iterate through each module directory that has changes
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)

# 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')
Expand All @@ -61,7 +71,7 @@ jobs:
git checkout -b "$branchName"

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

Expand All @@ -70,9 +80,7 @@ jobs:
--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" \
--reviewer "aws-cdk-team" \
--label "contribution/core,pr-linter/exempt-integ-test,pr-linter/exempt-readme,pr-linter/exempt-test"
done

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14 changes: 14 additions & 0 deletions tools/@aws-cdk/enum-updater/lib/exclude-values.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"codebuild": {
"ComputeType": ["BUILD_LAMBDA_10GB"]
},
"eks": {
"AmiType": ["CUSTOM"]
},
"lambda": {
"UpdateRuntimeOn": ["Manual"]
},
"autoscaling": {
"VolumeType": ["io2"]
}
}
6 changes: 4 additions & 2 deletions tools/@aws-cdk/enum-updater/lib/missing-enum-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ export class MissingEnumsUpdater {
let textToInsert = hasDoubleLineBreaks ? '\n' : '';

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

textToInsert += ` /**\n * PLACEHOLDER_COMMENT_TO_BE_FILLED_OUT\n */\n`;
textToInsert += ` ${enumConstantName} = '${enumVal}'`;
textToInsert += ` ${enumConstantName} = '${enumValue}'`;

// Add a comma and appropriate newlines after each member
textToInsert += ',';
Expand Down
30 changes: 27 additions & 3 deletions tools/@aws-cdk/enum-updater/lib/static-enum-mapping-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,33 @@ export interface SdkEnums {
}


function extractEnums(schema: Record<string, any>, enums: { [enumName: string]: (string | number)[] }) {
function extractEnums(schema: Record<string, any>, enums: { [enumName: string]: (string | number)[] }, excludeDict: Record<string, any>) {
// Helper function to process a property and its potential enum values
function processProperty(propertyName: string, property: any) {
if (property.enum) {
if (propertyName in excludeDict) {
const excludeList = excludeDict[propertyName] as string[];
if (excludeList && excludeList.length > 0) {
// if property.enum include a value in excludeList, ignore the value
const filteredEnum = property.enum.filter((value: string) => !excludeList.includes(value));
enums[propertyName] = filteredEnum;
}
}
else {
enums[propertyName] = property.enum;
}
} else if (property.items?.enum) {
enums[propertyName] = property.items.enum;
if (propertyName in excludeDict) {
const excludeList = excludeDict[propertyName] as string[];
if (excludeList) {
// if property.enum include a value in excludeList, ignore the value
const filteredEnum = property.item.enum.filter((value: string) => !excludeList.includes(value));
enums[propertyName] = filteredEnum;
}
}
else {
enums[propertyName] = property.enum;
}
}

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

const excludeEnums = readJsonFile(path.join(__dirname, 'exclude-values.json'));

for (const file of jsonFiles) {
try {
if (file == 'module.json') {
Expand All @@ -224,8 +246,10 @@ export async function parseAwsSdkEnums(sdkModelsPath: string): Promise<void> {

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

const excludeList = excludeEnums[service] ?? [];

// Extract enums
extractEnums(jsonData, enumMap);
extractEnums(jsonData, enumMap, excludeList);

sdkEnums[service] = enumMap;
} catch (error) {
Expand Down