Skip to content

feat(workflow): Add nightly dev-to-main rebase automation#244

Merged
DrunkOnJava merged 1 commit intomainfrom
feat/nightly-rebase-workflow
Jul 31, 2025
Merged

feat(workflow): Add nightly dev-to-main rebase automation#244
DrunkOnJava merged 1 commit intomainfrom
feat/nightly-rebase-workflow

Conversation

@DrunkOnJava
Copy link
Owner

🔄 Nightly Rebase Workflow

This PR adds an automated workflow to keep the dev branch in sync with main through nightly rebases.

What this adds:

  • Automated nightly rebases at 3 AM UTC to prevent branch divergence
  • Conflict detection with automatic PR creation for manual resolution
  • Success notifications via auto-closed issues for tracking
  • Old branch cleanup to remove rebase branches older than 7 days
  • Manual trigger option with dry-run capability for testing

Why this is needed:

In the hybrid workflow, dev can diverge from main over time. This automation ensures:

  • Regular synchronization without manual intervention
  • Early detection of conflicts before they compound
  • Clear process for conflict resolution when needed
  • Maintains the benefits of both protected main and active dev branches

Implementation details:

  • Uses --force-with-lease for safer force pushes
  • Creates detailed conflict resolution PRs with step-by-step guides
  • Includes branch statistics in logs for monitoring
  • Supports dry-run mode for testing without side effects

This is Part 1 of 5 of the hybrid workflow implementation, focusing on the core automation infrastructure.


Related to the hybrid workflow implementation based on developer feedback about balancing automation with human oversight.

Copilot AI review requested due to automatic review settings July 31, 2025 22:17
@github-actions
Copy link

🔍 PR Validation Results

Build Status: ❌ Failed
SwiftLint: ⚠️ Issues found
Project Structure: ❌ Issues found
Compilation: ❌ Failed


This comment was automatically generated by the PR validation workflow.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements an automated nightly workflow to rebase the dev branch onto main at 3 AM UTC daily, preventing branch divergence in a hybrid development workflow. The automation includes conflict detection, manual resolution workflows, and branch cleanup.

  • Automated nightly rebases with conflict detection and resolution
  • Success notifications via auto-closed issues and detailed conflict resolution PRs
  • Cleanup job to remove old rebase branches after 7 days

owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
head: `${context.repo.owner}:rebase-dev-${new Date().toISOString().split('T')[0]}`
Copy link

Copilot AI Jul 31, 2025

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.

Suggested change
head: `${context.repo.owner}:rebase-dev-${new Date().toISOString().split('T')[0]}`
head: `rebase-dev-${new Date().toISOString().split('T')[0]}`

Copilot uses AI. Check for mistakes.
repo: context.repo.repo,
labels: 'rebase-success',
state: 'open',
since: today
Copy link

Copilot AI Jul 31, 2025

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 uses AI. Check for mistakes.
echo "🧹 Cleaning up old rebase branches..."

# Get all rebase branches older than 7 days
CUTOFF_DATE=$(date -d '7 days ago' +%Y-%m-%d)
Copy link

Copilot AI Jul 31, 2025

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.

Suggested change
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])")

Copilot uses AI. Check for mistakes.
Comment on lines +51 to +56
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"
Copy link

Copilot AI Jul 31, 2025

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.

Suggested change
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"
AHEAD_COMMITS=$(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 $AHEAD_COMMITS commits ahead of main"

Copilot uses AI. Check for mistakes.
git rebase --abort

# Get conflict information
echo "conflict_files=$(git diff --name-only origin/main origin/dev | head -20 | tr '\n' ' ')" >> $GITHUB_OUTPUT
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The magic number '20' for limiting conflict files should be defined as a variable or constant at the top of the file for better maintainability.

Suggested change
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 uses AI. Check for mistakes.
DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
Update PR validation workflow to gracefully handle PRs that contain
no Swift files (like workflow-only or documentation PRs):
- Check for Swift files before running SwiftLint
- Skip Xcode build steps for non-Swift PRs
- Make Swift-specific checks conditional

This fixes CI failures for PRs #244-#248 which only contain
workflow files and scripts.

Co-authored-by: Claude <claude@anthropic.com>
DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
Update PR validation workflow to gracefully handle PRs that contain
no Swift files (like workflow-only or documentation PRs):
- Check for Swift files before running SwiftLint
- Skip Xcode build steps for non-Swift PRs
- Make Swift-specific checks conditional

This fixes CI failures for PRs #244-#248 which only contain
workflow files and scripts.

Co-authored-by: Claude <claude@anthropic.com>
@DrunkOnJava DrunkOnJava force-pushed the feat/nightly-rebase-workflow branch from 2da6bd0 to 5531dce Compare July 31, 2025 22:56
@github-actions
Copy link

🔍 PR Validation Results

Build Status: ❌ Failed
SwiftLint: ⚠️ Issues found
Project Structure: ❌ Issues found
Compilation: ❌ Failed


This comment was automatically generated by the PR validation workflow.

DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
- Check if PR contains Swift file changes before running SwiftLint
- Skip Swift-specific checks (TODO/FIXME, security) for non-Swift PRs
- Fixes CI failures on workflow-only PRs like #244-#248

This properly handles PRs that only modify workflows, scripts, or
documentation without triggering Swift-related validations.
DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
* fix(ci): Only run Swift checks on PRs with Swift changes

- Check if PR contains Swift file changes before running SwiftLint
- Skip Swift-specific checks (TODO/FIXME, security) for non-Swift PRs
- Fixes CI failures on workflow-only PRs like #244-#248

This properly handles PRs that only modify workflows, scripts, or
documentation without triggering Swift-related validations.

* fix(ci): Also check Swift changes for project generation step

The check_swift step needs to use the has_swift_changes output to
avoid trying to generate Xcode projects for non-Swift PRs.
Add automated workflow to keep dev branch in sync with main:
- Runs daily at 3 AM UTC
- Attempts to rebase dev onto main
- Creates conflict resolution PR if rebase fails
- Cleans up old rebase branches after 7 days
- Includes dry-run option for testing

This is part 1 of the hybrid workflow implementation, focusing on
automated branch synchronization to prevent divergence.

Co-authored-by: Claude <claude@anthropic.com>
@DrunkOnJava DrunkOnJava force-pushed the feat/nightly-rebase-workflow branch from 5531dce to c189a7e Compare July 31, 2025 23:10
@github-actions
Copy link

🔍 PR Validation Results

Build Status: ✅ Passed
SwiftLint: ⚠️ Issues found
Project Structure: ❌ Issues found
Compilation: ❌ Failed


This comment was automatically generated by the PR validation workflow.

@DrunkOnJava DrunkOnJava merged commit 071d02e into main Jul 31, 2025
2 of 4 checks passed
@DrunkOnJava DrunkOnJava deleted the feat/nightly-rebase-workflow branch July 31, 2025 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants