diff --git a/.github/workflows/bot.yml b/.github/workflows/bot.yml index 23890dfaf9a..842ae7fbce9 100644 --- a/.github/workflows/bot.yml +++ b/.github/workflows/bot.yml @@ -1,9 +1,11 @@ -name: SWC Bot +name: Bot on: push: branches: - main + schedule: + - cron: "0 */1 * * *" env: GIT_COMMITTER_NAME: "SWC Bot" @@ -40,6 +42,7 @@ jobs: name: Create cargo bump commit runs-on: ubuntu-latest concurrency: swc-bot-cargo-bump + if: ${{ github.event_name == 'push' }} steps: - uses: actions/checkout@v2 with: diff --git a/scripts/bot/src/auto-rebase.ts b/scripts/bot/src/auto-rebase.ts index 2a4b970ba77..dc0dff36337 100644 --- a/scripts/bot/src/auto-rebase.ts +++ b/scripts/bot/src/auto-rebase.ts @@ -38,34 +38,51 @@ function sleep(ms: number) { return; } - const pr = autoMergePrs[0]; + for (const pr of autoMergePrs) { + try { + const baseBranch = await octokit.rest.repos.getBranch({ + owner, + repo, + branch: pr.base.ref + }); + if (baseBranch.data.commit.sha === pr.base.sha) { + console.error(`PR #${pr.number} is already up-to-date`); + continue + } + await octokit.rest.pulls.updateBranch({ + owner, + repo, + pull_number: pr.number, + expected_head_sha: pr.head.sha + }); - await octokit.rest.pulls.updateBranch({ - owner, - repo, - pull_number: pr.number, - expected_head_sha: pr.head.sha - }); + console.log(`Updated PR ${pr.number} to merge upstream`); - console.log(`Updated PR ${pr.number} to merge upstream`); + await sleep(3000); - await sleep(3000); + const review = await octokit.pulls.createReview({ + owner, + repo, + pull_number: pr.number, + }); + console.log(`Created a review on PR ${pr.number}`); + + await octokit.pulls.submitReview({ + owner, + repo, + pull_number: pr.number, + review_id: review.data.id, + event: 'COMMENT', + body: 'Automated review comment generated by auto-rebase script', + }); + + break; + } catch (e) { + console.error(`Failed to auto-rebase:`, e) + } + } - const review = await octokit.pulls.createReview({ - owner, - repo, - pull_number: pr.number, - }); - console.log(`Created a review on PR ${pr.number}`); - await octokit.pulls.submitReview({ - owner, - repo, - pull_number: pr.number, - review_id: review.data.id, - event: 'COMMENT', - body: 'Automated review comment generated by auto-rebase script', - }); })()