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
54 changes: 54 additions & 0 deletions .github/workflows/analytics-metadata-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CDK Analytics Metadata Updater
on:
workflow_dispatch:
pull_request:
branches:
- yuanhaoz/metadata_workflow # TODO, remove this
- v2-release

jobs:
update-analytics-metadata:
if: github.repository == 'aws/aws-cdk'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- 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/construct-metadata-updater && yarn build+test

- name: Invoke Analytics Metadata Updater
run: |
cd tools/@aws-cdk/construct-metadata-updater
./bin/update-construct-metadata

- name: Check for changes
id: git-check
run: |
if [[ -n "$(git status --porcelain)" ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
else
echo "changes=false" >> $GITHUB_OUTPUT
fi

- 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 '[email protected]'
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 }}
16 changes: 13 additions & 3 deletions tools/@aws-cdk/construct-metadata-updater/lib/metadata-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,22 @@ export class ConstructsUpdater extends MetadataUpdater {
return;
}

// Create the new import statement
sourceFile.addImportDeclaration({
// Find the correct insertion point (after the last import before the new one)
const importDeclarations = sourceFile.getImportDeclarations();
let insertIndex = importDeclarations.length;
for (let i = 0; i < importDeclarations.length; i++) {
const existingImport = importDeclarations[i].getModuleSpecifier().getText();
if (existingImport.localeCompare(relativePath) > 0) {
insertIndex = i;
break;
}
}

// Insert the new import at the appropriate position
sourceFile.insertImportDeclaration(insertIndex, {
moduleSpecifier: relativePath,
namedImports: [{ name: "addConstructMetadata" }],
});

console.log(`Added import for MetadataType in file: ${filePath} with relative path: ${relativePath}`);

// Write the updated file back to disk
Expand Down