-
Notifications
You must be signed in to change notification settings - Fork 4.1k
90 lines (76 loc) · 3.49 KB
/
enum-auto-updater.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: CDK Enums Auto Updater
on:
workflow_dispatch:
jobs:
update-l2-enums:
if: github.repository == 'aws/aws-cdk'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Check Out
uses: actions/checkout@v4
- 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: cd tools/@aws-cdk/enum-updater && yarn install --frozen-lockfile && yarn build
- name: Identify Missing Values and Apply Code Changes
run: |
cd tools/@aws-cdk/enum-updater
./bin/update-missing-enums
- 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
# Authentication is required for gh cli
- name: Setup GitHub CLI
run: |
gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}"
- 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]'
# 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')
# If a PR exists, close it and continue
if [[ -n "$prExists" ]]; then
echo "PR already exists for module ${moduleName#aws-}, closing the existing PR."
gh pr close "$prExists" --confirm
fi
# Create a new branch for the module
branchName="enum-update/${moduleName#aws-}"
git checkout -b "$branchName"
# Stage, commit, and push changes for the 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"
# Create a new pull request
gh pr create --title "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}" \
--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"
done