mirror of
https://github.com/swc-project/swc.git
synced 2024-12-23 13:51:19 +03:00
chore(ci): Improve bot script (#4430)
- It will now rebase another PR if there's a merge conflict. - It does not update the base branch if it's already up-to-date.
This commit is contained in:
parent
6d4b32a51c
commit
c216a03673
5
.github/workflows/bot.yml
vendored
5
.github/workflows/bot.yml
vendored
@ -1,9 +1,11 @@
|
|||||||
name: SWC Bot
|
name: Bot
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
schedule:
|
||||||
|
- cron: "0 */1 * * *"
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GIT_COMMITTER_NAME: "SWC Bot"
|
GIT_COMMITTER_NAME: "SWC Bot"
|
||||||
@ -40,6 +42,7 @@ jobs:
|
|||||||
name: Create cargo bump commit
|
name: Create cargo bump commit
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
concurrency: swc-bot-cargo-bump
|
concurrency: swc-bot-cargo-bump
|
||||||
|
if: ${{ github.event_name == 'push' }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
|
@ -38,34 +38,51 @@ function sleep(ms: number) {
|
|||||||
return;
|
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({
|
console.log(`Updated PR ${pr.number} to merge upstream`);
|
||||||
owner,
|
|
||||||
repo,
|
|
||||||
pull_number: pr.number,
|
|
||||||
expected_head_sha: pr.head.sha
|
|
||||||
});
|
|
||||||
|
|
||||||
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',
|
|
||||||
});
|
|
||||||
})()
|
})()
|
||||||
|
Loading…
Reference in New Issue
Block a user