Skip to content

Commit

Permalink
ci: rebase onto main before merging PR into prerelease branch
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Nov 9, 2024
1 parent 5cf5895 commit 95a14bc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/prerelease-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
Expand Down
58 changes: 38 additions & 20 deletions scripts/prerelease/src/prerelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand All @@ -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
Expand All @@ -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[]) {
Expand Down

0 comments on commit 95a14bc

Please sign in to comment.