Skip to content

Commit

Permalink
chore: enable GitHub workflow for Metadata updater (aws#33262)
Browse files Browse the repository at this point in the history
### 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*
  • Loading branch information
GavinZZ authored Feb 3, 2025
1 parent 37df0d2 commit be231ed
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
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

0 comments on commit be231ed

Please sign in to comment.