-
Notifications
You must be signed in to change notification settings - Fork 15
225 lines (185 loc) · 8.47 KB
/
Copy pathupdate-para-dependencies.yml
File metadata and controls
225 lines (185 loc) · 8.47 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Update Para Dependencies Direct
on:
workflow_dispatch:
inputs:
create_pr:
description: "Create pull request if updates found"
type: boolean
default: true
schedule:
- cron: "0 2 * * *"
env:
NODE_VERSION: "20.19.0"
jobs:
update-dependencies:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "yarn"
- name: Install dependencies
run: yarn install --immutable --network-timeout 60000
- name: Apply updates
id: apply_updates
run: |
echo "🔄 Applying dependency updates..."
# Run the update command
yarn deps:update 2>&1 | tee update_output.txt
# Check if any changes were made
if git diff --quiet; then
echo "changes_made=false" >> $GITHUB_OUTPUT
echo "No actual changes made"
else
echo "changes_made=true" >> $GITHUB_OUTPUT
# Extract summary from the update output
summary=$(grep -E "Updated \d+ files with \d+ dependency updates" update_output.txt || echo "Dependencies updated")
echo "update_summary=$summary" >> $GITHUB_OUTPUT
# Generate commit message directly in GITHUB_OUTPUT
echo "commit_message<<EOF" >> $GITHUB_OUTPUT
echo "update @getpara/* dependencies to latest alpha versions" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
grep -E "^\s+- @getpara/" update_output.txt >> $GITHUB_OUTPUT || true
echo "" >> $GITHUB_OUTPUT
echo "$summary" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
echo "✅ $summary"
fi
- name: Check for existing PR
if: steps.apply_updates.outputs.changes_made == 'true'
id: check_pr
run: |
# Check for existing open PRs with the automated dependency update title
existing_pr=$(gh pr list --base "2.0.0-alpha" --state open --json number,headRefName,title | \
jq -r '.[] | select(.title | contains("chore: update @getpara/* dependencies")) | .headRefName' | head -1)
if [ -n "$existing_pr" ]; then
echo "existing_branch=$existing_pr" >> $GITHUB_OUTPUT
echo "has_existing_pr=true" >> $GITHUB_OUTPUT
echo "📋 Found existing PR branch: $existing_pr"
else
echo "has_existing_pr=false" >> $GITHUB_OUTPUT
echo "📝 No existing PR found, will create new one"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create or update branch and commit changes
if: steps.apply_updates.outputs.changes_made == 'true'
id: commit_changes
run: |
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Use existing branch or create new one
if [ "${{ steps.check_pr.outputs.has_existing_pr }}" == "true" ]; then
BRANCH_NAME="${{ steps.check_pr.outputs.existing_branch }}"
echo "♻️ Updating existing branch: $BRANCH_NAME"
# Fetch and checkout the existing branch
git fetch origin $BRANCH_NAME:$BRANCH_NAME
git checkout $BRANCH_NAME
# Merge or rebase with base branch to get latest changes
git fetch origin 2.0.0-alpha
git rebase origin/2.0.0-alpha || {
echo "⚠️ Rebase failed, attempting merge..."
git rebase --abort
git merge origin/2.0.0-alpha -m "Merge latest changes from 2.0.0-alpha"
}
else
# Create a new branch with a fixed name (no timestamp)
BRANCH_NAME="automated-para-deps-update"
git checkout -b $BRANCH_NAME
echo "🆕 Created new branch: $BRANCH_NAME"
fi
echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT
# Stage and commit changes (excluding update_output.txt)
git add --all -- ':!update_output.txt'
if git diff --cached --quiet; then
echo "No changes to commit"
echo "committed=false" >> $GITHUB_OUTPUT
else
git commit -m "${{ steps.apply_updates.outputs.commit_message }}"
echo "committed=true" >> $GITHUB_OUTPUT
echo "✅ Changes committed successfully to branch $BRANCH_NAME"
fi
- name: Push changes
if: steps.commit_changes.outputs.committed == 'true'
run: |
if [ "${{ steps.check_pr.outputs.has_existing_pr }}" == "true" ]; then
# Force push to update the existing PR branch
git push --force-with-lease origin ${{ steps.commit_changes.outputs.branch_name }}
echo "♻️ Updated existing PR branch: ${{ steps.commit_changes.outputs.branch_name }}"
else
# Regular push for new branch
git push -u origin ${{ steps.commit_changes.outputs.branch_name }}
echo "✅ Changes pushed to new branch: ${{ steps.commit_changes.outputs.branch_name }}"
fi
- name: Create or Update Pull Request
if: steps.commit_changes.outputs.committed == 'true' && (inputs.create_pr || github.event_name == 'schedule')
run: |
if [ "${{ steps.check_pr.outputs.has_existing_pr }}" == "true" ]; then
# Find the PR number for the existing branch
pr_number=$(gh pr list --base "2.0.0-alpha" --head "${{ steps.commit_changes.outputs.branch_name }}" --json number -q '.[0].number')
if [ -n "$pr_number" ]; then
# Update the existing PR body with the latest changes
gh pr edit $pr_number \
--body "## 🔄 Automated Dependency Update
This PR updates @getpara/* packages to their latest alpha versions.
### Latest Changes
${{ steps.apply_updates.outputs.commit_message }}
### Verification
- [ ] All package.json files have been updated
- [ ] Yarn.lock files have been refreshed
- [ ] Dependencies are consistent across the monorepo
---
*Last updated: $(date '+%Y-%m-%d %H:%M:%S UTC')*
*This PR is automatically updated by the GitHub Action workflow.*
cc @jlm0"
echo "♻️ Updated existing PR #$pr_number"
else
echo "⚠️ Could not find PR number for existing branch, skipping PR update"
fi
else
# Create a new PR
gh pr create \
--title "chore: update @getpara/* dependencies to latest alpha versions" \
--body "## 🔄 Automated Dependency Update
This PR updates @getpara/* packages to their latest alpha versions.
### Changes Made
${{ steps.apply_updates.outputs.commit_message }}
### Verification
- [ ] All package.json files have been updated
- [ ] Yarn.lock files have been refreshed
- [ ] Dependencies are consistent across the monorepo
---
*This PR was created automatically by the GitHub Action workflow.*
cc @jlm0" \
--base "2.0.0-alpha" \
--head "${{ steps.commit_changes.outputs.branch_name }}" \
--reviewer "jlm0"
echo "🎉 Created new PR"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
if: always()
run: |
echo "## 📊 Dependency Update Summary" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.apply_updates.outputs.changes_made }}" == "true" ]; then
echo "✅ Updates were available and processed" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.commit_changes.outputs.committed }}" == "true" ]; then
echo "✅ Changes committed and pushed successfully" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "${{ steps.apply_updates.outputs.update_summary }}" >> $GITHUB_STEP_SUMMARY
fi
else
echo "🎉 All @getpara/* dependencies are already up to date!" >> $GITHUB_STEP_SUMMARY
fi