-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: rebase onto main before merging PR into prerelease branch
- Loading branch information
1 parent
5cf5895
commit 95a14bc
Showing
2 changed files
with
38 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,10 @@ export async function prerelease({ | |
|
||
await exec('git', ['checkout', targetBranch]) | ||
} | ||
// Otherwise, fetch the main branch for rebasing the next branch. | ||
else { | ||
await exec('git', ['fetch', 'origin', 'main']) | ||
} | ||
|
||
// Check if this PR was already merged | ||
const existingCommit = await get('git', [ | ||
|
@@ -40,6 +44,39 @@ export async function prerelease({ | |
process.exit(0) | ||
} | ||
|
||
// Ensure all patches from main are applied to the target branch. If | ||
// a merge conflict occurs, a manual rebase is required. | ||
await exec('git', ['rebase', '-X', 'ours', 'origin/main']) | ||
|
||
await mergePullRequest({ | ||
prHeadRef, | ||
prRepoUrl, | ||
message: `${prTitle} (#${prNumber})`, | ||
}) | ||
|
||
await installDeployKey(deployKey) | ||
|
||
// The origin must use SSH for the deploy key to work. | ||
await execa('git', [ | ||
'remote', | ||
'set-url', | ||
'origin', | ||
'[email protected]:radashi-org/radashi.git', | ||
]) | ||
|
||
// Push the commit to the target branch | ||
await exec('git', ['push', 'origin', targetBranch, '--force']) | ||
} | ||
|
||
async function mergePullRequest({ | ||
prHeadRef, | ||
prRepoUrl, | ||
message, | ||
}: { | ||
prHeadRef: string | ||
prRepoUrl: string | ||
message: string | ||
}) { | ||
const baseCommit = await get('git', ['merge-base', 'HEAD', `pr/${prHeadRef}`]) | ||
|
||
// Get the first commit author from the PR branch | ||
|
@@ -62,26 +99,7 @@ export async function prerelease({ | |
await exec('git', ['add', '.']) | ||
|
||
// Create commit with PR title and number | ||
await exec('git', [ | ||
'commit', | ||
'-m', | ||
`${prTitle} (#${prNumber})`, | ||
'--author', | ||
prAuthor, | ||
]) | ||
|
||
await installDeployKey(deployKey) | ||
|
||
// The origin must use SSH for the deploy key to work. | ||
await execa('git', [ | ||
'remote', | ||
'set-url', | ||
'origin', | ||
'[email protected]:radashi-org/radashi.git', | ||
]) | ||
|
||
// Push the commit to the target branch | ||
await exec('git', ['push', 'origin', targetBranch]) | ||
await exec('git', ['commit', '-m', message, '--author', prAuthor]) | ||
} | ||
|
||
async function get(cmd: string, args: readonly string[]) { | ||
|