Skip to content

Update Para Dependencies Direct #98

Update Para Dependencies Direct

Update Para Dependencies Direct #98

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