-
Notifications
You must be signed in to change notification settings - Fork 4.5k
142 lines (117 loc) · 5.4 KB
/
enum-auto-updater.yml
File metadata and controls
142 lines (117 loc) · 5.4 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: CDK Enums Auto Updater
on:
workflow_dispatch:
schedule: # Runs every Monday at 1pm PT
- cron: '0 13 * * 1'
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@v6
- name: Set up Node
uses: actions/setup-node@v6
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
- name: Commit & Push changes
if: steps.git-check.outputs.changes == 'true'
run: |
# Enable command logging
set -x
echo "=== Starting PR creation process ==="
# Iterate through each module directory that has changes
echo "Storing original branch name..."
git config --global user.name 'aws-cdk-automation'
git config --global user.email '[email protected]'
# Store the original branch name
echo "Storing original branch name..."
original_branch=$(git rev-parse --abbrev-ref HEAD)
echo "Original branch: $original_branch"
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
echo "=== Processing module: $module ==="
moduleName=$(basename $module)
echo "Module name: $moduleName"
# Reset to clean state
echo "Resetting to clean state..."
git reset --hard HEAD
git clean -fd
# Determine the correct path for the module
echo "Determining module path..."
if [[ -d "packages/aws-cdk-lib/$module" ]]; then
modulePath="packages/aws-cdk-lib/$module"
echo "Found module in aws-cdk-lib: $modulePath"
elif [[ -d "packages/@aws-cdk/$module" ]]; then
modulePath="packages/@aws-cdk/$module"
echo "Found module in @aws-cdk: $modulePath"
else
echo "ERROR: Cannot find module directory for $module"
continue
fi
# Branch name for the module
branchName="enum-update/${moduleName#aws-}"
# Check for existing PR with the same name
prExists=$(gh pr list --state open --head ${branchName} --base main --json number,title -q '.[].number')
# If a PR exists, close it
if [[ -n "$prExists" ]]; then
echo "Found existing PR #$prExists for module ${moduleName#aws-}, closing it..."
gh pr close "$prExists" -c "Closing in favor of a new PR with updated enum values"
else
echo "No existing PR found for ${moduleName#aws-}"
fi
# Create/switch to branch for the module
echo "Creating/switching to branch: $branchName"
git checkout -B "$branchName" $original_branch # -B forces branch creation/reset
# Re-run the update script for this specific module
echo "Re-running update script..."
echo "Current directory: $(pwd)"
cd tools/@aws-cdk/enum-updater
echo "Running update-missing-enums script..."
./bin/update-missing-enums
cd ../../..
echo "Returned to: $(pwd)"
echo "Checking for changes after update..."
git status
# Stage, commit, and push changes for the module
echo "Staging changes for $modulePath"
git add "$modulePath"
echo "Committing changes..."
git commit -m "chore(${moduleName#aws-}): add new enum values for ${moduleName#aws-}"
# Force push to overwrite any existing branch
echo "Force pushing to remote..."
git push -f origin "$branchName"
# Create a new pull request
echo "Creating 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"
# Return to original branch
echo "Returning to original branch: $original_branch"
git checkout $original_branch
echo "=== Completed processing for module: $module ==="
done
# Disable command logging
set +x
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}