Skip to content

Commit be231ed

Browse files
authored
chore: enable GitHub workflow for Metadata updater (#33262)
### Issue # (if applicable) N/A ### Reason for this change Added a weekly triggered workflow to update metadata and constructors. ### Description of changes Build a GitHub action file that will create a PR automatically ### Describe any new or updated permissions being added N/A ### Description of how you validated changes Workflow runs successfully. ### 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 37df0d2 commit be231ed

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: CDK Analytics Metadata Updater
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- yuanhaoz/metadata_workflow # TODO, remove this
7+
- v2-release
8+
9+
jobs:
10+
update-analytics-metadata:
11+
if: github.repository == 'aws/aws-cdk'
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
ref: ${{ github.event.pull_request.head.ref }}
20+
21+
- name: Set up Node
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: "*"
25+
env:
26+
NODE_OPTIONS: "--max-old-space-size=8196 --experimental-worker ${NODE_OPTIONS:-}"
27+
28+
- name: Install dependencies
29+
run: yarn install --frozen-lockfile && cd tools/@aws-cdk/construct-metadata-updater && yarn build+test
30+
31+
- name: Invoke Analytics Metadata Updater
32+
run: |
33+
cd tools/@aws-cdk/construct-metadata-updater
34+
./bin/update-construct-metadata
35+
36+
- name: Check for changes
37+
id: git-check
38+
run: |
39+
if [[ -n "$(git status --porcelain)" ]]; then
40+
echo "changes=true" >> $GITHUB_OUTPUT
41+
else
42+
echo "changes=false" >> $GITHUB_OUTPUT
43+
fi
44+
45+
- name: Commit & Push changes
46+
if: steps.git-check.outputs.changes == 'true'
47+
run: |
48+
git config --global user.name 'aws-cdk-automation'
49+
git config --global user.email '[email protected]'
50+
git add .
51+
git commit -m "chore: update analytics metadata blueprints"
52+
git push origin ${{ github.event.pull_request.head.ref }}
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

tools/@aws-cdk/construct-metadata-updater/lib/metadata-updater.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,22 @@ export class ConstructsUpdater extends MetadataUpdater {
160160
return;
161161
}
162162

163-
// Create the new import statement
164-
sourceFile.addImportDeclaration({
163+
// Find the correct insertion point (after the last import before the new one)
164+
const importDeclarations = sourceFile.getImportDeclarations();
165+
let insertIndex = importDeclarations.length;
166+
for (let i = 0; i < importDeclarations.length; i++) {
167+
const existingImport = importDeclarations[i].getModuleSpecifier().getText();
168+
if (existingImport.localeCompare(relativePath) > 0) {
169+
insertIndex = i;
170+
break;
171+
}
172+
}
173+
174+
// Insert the new import at the appropriate position
175+
sourceFile.insertImportDeclaration(insertIndex, {
165176
moduleSpecifier: relativePath,
166177
namedImports: [{ name: "addConstructMetadata" }],
167178
});
168-
169179
console.log(`Added import for MetadataType in file: ${filePath} with relative path: ${relativePath}`);
170180

171181
// Write the updated file back to disk

0 commit comments

Comments
 (0)