-
Notifications
You must be signed in to change notification settings - Fork 0
feat(workflow): Add nightly dev-to-main rebase automation #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,287 @@ | ||||||
| # Nightly Dev-to-Main Rebase | ||||||
| # Automatically rebases dev branch onto main to keep them in sync | ||||||
| name: Nightly Rebase | ||||||
|
|
||||||
| on: | ||||||
| schedule: | ||||||
| # Run at 3 AM UTC daily | ||||||
| - cron: '0 3 * * *' | ||||||
| workflow_dispatch: | ||||||
| inputs: | ||||||
| dry_run: | ||||||
| description: 'Dry run (no push)' | ||||||
| required: false | ||||||
| default: 'false' | ||||||
| type: choice | ||||||
| options: | ||||||
| - 'true' | ||||||
| - 'false' | ||||||
|
|
||||||
| jobs: | ||||||
| rebase-dev: | ||||||
| name: Rebase dev onto main | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| steps: | ||||||
| - name: Checkout Repository | ||||||
| uses: actions/checkout@v4 | ||||||
| with: | ||||||
| fetch-depth: 0 | ||||||
| token: ${{ secrets.GITHUB_TOKEN }} | ||||||
|
|
||||||
| - name: Configure Git | ||||||
| run: | | ||||||
| git config user.name 'github-actions[bot]' | ||||||
| git config user.email 'github-actions[bot]@users.noreply.github.com' | ||||||
|
|
||||||
| - name: Attempt Rebase | ||||||
| id: rebase | ||||||
| run: | | ||||||
| echo "🔄 Starting nightly rebase of dev onto main..." | ||||||
|
|
||||||
| # Fetch latest changes | ||||||
| git fetch origin main dev | ||||||
|
|
||||||
| # Checkout dev branch | ||||||
| git checkout dev | ||||||
|
|
||||||
| # Get commit counts for logging | ||||||
| MAIN_COMMITS=$(git rev-list --count origin/main) | ||||||
| DEV_COMMITS=$(git rev-list --count origin/dev) | ||||||
| DIVERGED=$(git rev-list --count origin/main..origin/dev) | ||||||
|
|
||||||
| echo "📊 Branch statistics:" | ||||||
| echo " - Main has $MAIN_COMMITS commits" | ||||||
| echo " - Dev has $DEV_COMMITS commits" | ||||||
| echo " - Dev is $DIVERGED commits ahead of main" | ||||||
|
|
||||||
| # Attempt rebase | ||||||
| if git rebase origin/main; then | ||||||
| echo "✅ Rebase successful!" | ||||||
| echo "rebase_success=true" >> $GITHUB_OUTPUT | ||||||
|
|
||||||
| # Check if this is a dry run | ||||||
| if [[ "${{ github.event.inputs.dry_run }}" != "true" ]]; then | ||||||
| # Push the rebased dev branch | ||||||
| git push origin dev --force-with-lease | ||||||
| echo "✅ Pushed rebased dev branch" | ||||||
| else | ||||||
| echo "🔍 Dry run - not pushing changes" | ||||||
| git log --oneline -10 | ||||||
| fi | ||||||
| else | ||||||
| echo "❌ Rebase failed due to conflicts" | ||||||
| echo "rebase_success=false" >> $GITHUB_OUTPUT | ||||||
|
|
||||||
| # Abort the rebase | ||||||
| git rebase --abort | ||||||
|
|
||||||
| # Get conflict information | ||||||
| echo "conflict_files=$(git diff --name-only origin/main origin/dev | head -20 | tr '\n' ' ')" >> $GITHUB_OUTPUT | ||||||
|
||||||
| echo "conflict_files=$(git diff --name-only origin/main origin/dev | head -20 | tr '\n' ' ')" >> $GITHUB_OUTPUT | |
| echo "conflict_files=$(git diff --name-only origin/main origin/dev | head -${{ env.MAX_CONFLICT_FILES }} | tr '\n' ' ')" >> $GITHUB_OUTPUT |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The head parameter format is incorrect for checking existing PRs. It should be just the branch name without the owner prefix when checking PRs in the same repository.
| head: `${context.repo.owner}:rebase-dev-${new Date().toISOString().split('T')[0]}` | |
| head: `rebase-dev-${new Date().toISOString().split('T')[0]}` |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 'since' parameter expects an ISO 8601 timestamp, but 'today' is in YYYY-MM-DD format. This should be since: today + 'T00:00:00Z' to properly filter issues created today.
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The date -d command is not portable and may fail on non-GNU systems like macOS. Since this runs on ubuntu-latest, it should work, but consider using a more portable date calculation or explicitly documenting the GNU date dependency.
| CUTOFF_DATE=$(date -d '7 days ago' +%Y-%m-%d) | |
| CUTOFF_DATE=$(node -e "console.log(new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split('T')[0])") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The variable name 'DIVERGED' is misleading as it represents commits ahead, not actual divergence. Consider renaming to 'AHEAD_COMMITS' or 'DEV_AHEAD' for clarity.