Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

feat: integrate auto-approval and auto-merge into sync workflow

LearningCircuitdaab7fb60a94
diff --git a/.github/workflows/auto-merge-sync.yml b/.github/workflows/auto-merge-sync.yml
deleted file mode 100644
index dc93aed06a..0000000000
--- a/.github/workflows/auto-merge-sync.yml
+++ /dev/null
@@ -1,65 +0,0 @@
-name: Auto-merge Clean Syncs
-
-on:
- pull_request:
- types: [opened, synchronize]
- branches:
- - dev
-
-jobs:
- auto-merge-sync:
- runs-on: ubuntu-latest
- # Only run on sync PRs without conflicts
- if: startsWith(github.event.pull_request.title, '✅ Sync main to dev') && contains(github.event.pull_request.labels.*.name, 'auto-merge')
-
- steps:
- - name: Checkout repository
- uses: actions/checkout@v5
-
- - name: Auto-approve PR (using PAT from code owner)
- if: ${{ secrets.PAT_TOKEN }}
- uses: hmarr/auto-approve-action@v3
- with:
- github-token: ${{ secrets.PAT_TOKEN }}
-
- - name: Comment approval status
- uses: actions/github-script@v7
- with:
- github-token: ${{ secrets.GITHUB_TOKEN }}
- script: |
- const prNumber = context.payload.pull_request.number;
- const hasPatToken = '${{ secrets.PAT_TOKEN }}' !== '';
-
- if (hasPatToken) {
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: prNumber,
- body: '✅ Auto-approved: Clean sync from main to dev with no conflicts.'
- });
-
- // Try to enable auto-merge after approval
- try {
- await github.rest.pulls.merge({
- owner: context.repo.owner,
- repo: context.repo.repo,
- pull_number: prNumber,
- commit_title: `Automated sync: ${context.payload.pull_request.title}`,
- commit_message: 'Automatically merged clean sync from main to dev',
- merge_method: 'merge'
- });
- console.log(`Auto-merged PR #${prNumber}`);
- } catch (error) {
- console.log(`Could not auto-merge PR #${prNumber}: ${error.message}`);
- // This might fail if checks haven't passed yet, which is expected
- }
- } else {
- await github.rest.issues.createComment({
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number: prNumber,
- body: '⚠️ **Manual approval required**: Auto-approval needs PAT_TOKEN secret to be configured.\n\nThis is a clean sync from main to dev, but requires manual approval from a code owner.'
- });
- }
-
- console.log(`PR #${prNumber} - Auto-approval attempted`);
diff --git a/.github/workflows/sync-main-to-dev.yml b/.github/workflows/sync-main-to-dev.yml
index 3e3977f02d..8c937f32cf 100644
--- a/.github/workflows/sync-main-to-dev.yml
+++ b/.github/workflows/sync-main-to-dev.yml
@@ -230,6 +230,193 @@ jobs:
labels: hasConflicts ? ['sync', 'conflicts'] : ['sync', 'auto-merge']
});
+ - name: Wait for PR to be ready
+ if: steps.check_sync.outputs.sync_needed == 'true' && steps.merge_attempt.outputs.merge_conflicts == 'false'
+ run: |
+ echo "Waiting for PR to be ready..."
+ sleep 5
+
+ - name: Verify PR contains only sync commits
+ if: steps.check_sync.outputs.sync_needed == 'true' && steps.merge_attempt.outputs.merge_conflicts == 'false'
+ id: verify_commits
+ uses: actions/github-script@v7
+ with:
+ github-token: ${{ secrets.GITHUB_TOKEN }}
+ script: |
+ const branchName = '${{ steps.create_branch.outputs.branch_name }}';
+
+ // Find the PR we just created/updated
+ const { data: prs } = await github.rest.pulls.list({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ state: 'open',
+ head: `${context.repo.owner}:${branchName}`,
+ base: 'dev'
+ });
+
+ if (prs.length === 0) {
+ console.log('PR not found, skipping auto-merge');
+ core.setOutput('pr_number', '');
+ core.setOutput('safe_to_merge', 'false');
+ return;
+ }
+
+ const pr = prs[0];
+ console.log(`Found PR #${pr.number}`);
+ core.setOutput('pr_number', pr.number);
+
+ // Get the list of commits in the PR
+ const { data: commits } = await github.rest.pulls.listCommits({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: pr.number
+ });
+
+ console.log(`PR has ${commits.length} commit(s)`);
+
+ // Check if all commits are either from main or are merge commits
+ let safeToMerge = true;
+ const suspiciousCommits = [];
+
+ for (const commit of commits) {
+ const message = commit.commit.message;
+ const author = commit.commit.author.email;
+
+ // Check if this is a merge commit or github-actions commit
+ const isMergeCommit = message.startsWith('Merge');
+ const isGitHubActions = author === 'github-actions[bot]@users.noreply.github.com' ||
+ author === '41898282+github-actions[bot]@users.noreply.github.com';
+
+ if (!isMergeCommit && !isGitHubActions) {
+ // Check if this commit exists in main
+ try {
+ await github.rest.repos.getCommit({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ ref: commit.sha
+ });
+ console.log(`Commit ${commit.sha.substring(0, 7)} exists in repo`);
+ } catch (e) {
+ suspiciousCommits.push({
+ sha: commit.sha.substring(0, 7),
+ message: message.split('\n')[0],
+ author: author
+ });
+ }
+ }
+ }
+
+ if (suspiciousCommits.length > 0) {
+ console.log('Found unexpected commits:');
+ suspiciousCommits.forEach(c => {
+ console.log(` - ${c.sha}: ${c.message} (by ${c.author})`);
+ });
+ safeToMerge = false;
+ } else {
+ console.log('All commits verified as sync-related');
+ }
+
+ core.setOutput('safe_to_merge', safeToMerge.toString());
+ core.setOutput('commit_count', commits.length.toString());
+
+ - name: Auto-approve PR
+ if: steps.verify_commits.outputs.safe_to_merge == 'true' && secrets.PAT_TOKEN != ''
+ id: auto_approve
+ uses: actions/github-script@v7
+ with:
+ github-token: ${{ secrets.PAT_TOKEN }}
+ script: |
+ const prNumber = ${{ steps.verify_commits.outputs.pr_number }};
+
+ if (!prNumber) {
+ console.log('No PR number found, skipping approval');
+ return;
+ }
+
+ try {
+ // Approve the PR
+ const { data: review } = await github.rest.pulls.createReview({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: prNumber,
+ event: 'APPROVE',
+ body: '✅ Auto-approved: Clean sync from main to dev with no conflicts.\n\nVerified:\n- No merge conflicts detected\n- Only contains sync-related commits\n- Ready for auto-merge'
+ });
+
+ console.log(`Successfully approved PR #${prNumber}`);
+ core.setOutput('approved', 'true');
+ } catch (error) {
+ console.log(`Failed to approve PR: ${error.message}`);
+ core.setOutput('approved', 'false');
+ }
+
+ - name: Enable auto-merge
+ if: steps.auto_approve.outputs.approved == 'true'
+ uses: actions/github-script@v7
+ with:
+ github-token: ${{ secrets.PAT_TOKEN }}
+ script: |
+ const prNumber = ${{ steps.verify_commits.outputs.pr_number }};
+
+ try {
+ // Enable auto-merge (will wait for status checks)
+ const mutation = `
+ mutation($pullRequestId: ID!) {
+ enablePullRequestAutoMerge(input: {
+ pullRequestId: $pullRequestId,
+ mergeMethod: MERGE
+ }) {
+ pullRequest {
+ autoMergeRequest {
+ enabledAt
+ enabledBy {
+ login
+ }
+ }
+ }
+ }
+ }
+ `;
+
+ // First get the PR node ID
+ const { data: prData } = await github.rest.pulls.get({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ pull_number: prNumber
+ });
+
+ const result = await github.graphql(mutation, {
+ pullRequestId: prData.node_id
+ });
+
+ console.log(`✅ Auto-merge enabled for PR #${prNumber}`);
+ console.log('The PR will be automatically merged once all status checks pass.');
+ } catch (error) {
+ console.log(`Could not enable auto-merge: ${error.message}`);
+ console.log('The PR has been approved but will need manual merging.');
+ }
+
+ - name: Log final status
+ if: steps.check_sync.outputs.sync_needed == 'true'
+ run: |
+ echo "========================================="
+ echo "Sync Workflow Summary:"
+ echo "========================================="
+ if [ "${{ steps.merge_attempt.outputs.merge_conflicts }}" == "true" ]; then
+ echo "⚠️ Status: PR created with CONFLICTS"
+ echo "Action required: Manual conflict resolution needed"
+ elif [ "${{ steps.verify_commits.outputs.safe_to_merge }}" != "true" ]; then
+ echo "⚠️ Status: PR created but contains unexpected commits"
+ echo "Action required: Manual review needed"
+ elif [ "${{ steps.auto_approve.outputs.approved }}" == "true" ]; then
+ echo "✅ Status: PR created, approved, and auto-merge enabled"
+ echo "The PR will merge automatically once checks pass"
+ else
+ echo "⚠️ Status: PR created but not auto-approved"
+ echo "Action required: Manual approval needed"
+ fi
+ echo "========================================="
+
- name: Notify if no sync needed
if: steps.check_sync.outputs.sync_needed == 'false'
run: |