Open merge-back-release PRs from a seprate branch

This commit is contained in:
Quentin Gliech
2025-01-31 13:23:31 +01:00
parent 42f04637fa
commit 3ef6247a0f
3 changed files with 90 additions and 36 deletions

72
.github/workflows/merge-back.yaml vendored Normal file
View File

@@ -0,0 +1,72 @@
name: Merge back a reference to main
on:
workflow_call:
inputs:
sha:
required: true
type: string
secrets:
BOT_GITHUB_TOKEN:
required: true
jobs:
merge-back:
name: Merge back the reference to main
runs-on: ubuntu-22.04
steps:
- name: Push branch and open a PR
uses: actions/github-script@v7.0.1
env:
SHA: ${{ inputs.sha }}
with:
github-token: ${{ secrets.BOT_GITHUB_TOKEN }}
script: |
const [owner, repo] = process.env.GITHUB_REPOSITORY.split('/');
const sha = process.env.SHA;
const branch = `ref-merge/${sha}`;
const ref = `heads/${branch}`;
await github.rest.git.createRef({
owner,
repo,
ref,
sha,
});
console.log(`Created branch ${branch} to ${sha}`);
// Create a PR to merge the branch back to main
const pr = await github.rest.pulls.create({
owner,
repo,
head: branch,
base: 'main',
title: `Automatic merge back to main`,
body: `This pull request was automatically created by the release workflow. It merges the release branch back to main.`,
maintainer_can_modify: true,
});
console.log(`Created pull request #${pr.data.number} to merge the release branch back to main`);
console.log(`PR URL: ${pr.data.html_url}`);
// Add the `T-Task` label to the PR
await github.rest.issues.addLabels({
owner,
repo,
issue_number: pr.data.number,
labels: ['T-Task'],
});
// Enable auto-merge on the PR
await github.graphql(
`
mutation AutoMerge($id: ID!) {
enablePullRequestAutoMerge(input: {
pullRequestId: $id,
mergeMethod: MERGE,
}) {
clientMutationId
}
}
`,
{ id: pr.data.node_id },
);

View File

@@ -73,6 +73,14 @@ jobs:
secrets:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
merge-back:
uses: ./.github/workflows/merge-back.yaml
needs: [tag]
with:
sha: ${{ needs.tag.outputs.sha }}
secrets:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
branch:
name: Create a new release branch
runs-on: ubuntu-22.04
@@ -103,20 +111,3 @@ jobs:
sha,
});
console.log(`Created branch ${branch} from ${sha}`);
- name: Checkout the code
uses: actions/checkout@v4.2.2
with:
ref: "release/v${{ needs.compute-version.outputs.short }}"
- name: Open a pull request to merge the branch into main
env:
VERSION: ${{ needs.compute-version.outputs.short }}
GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
run: |
gh pr create \
--title "Release branch $VERSION" \
--body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \
--base main \
--head "release/v$VERSION" \
--label "T-Task"

View File

@@ -42,7 +42,7 @@ jobs:
- name: Compute the new minor RC
id: next
env:
BUMP: ${{ github.event.inputs.rc && 'prerelease' || 'patch' }}
BUMP: ${{ inputs.rc && 'prerelease' || 'patch' }}
VERSION: ${{ steps.current.outputs.version }}
run: echo "version=$(npx --yes semver@7.5.4 -i "$BUMP" --preid rc "$VERSION")" >> "$GITHUB_OUTPUT"
@@ -54,6 +54,15 @@ jobs:
secrets:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
merge-back:
uses: ./.github/workflows/merge-back.yaml
needs: [tag]
if: inputs.merge-back
with:
sha: ${{ needs.tag.outputs.sha }}
secrets:
BOT_GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
update-branch:
name: Update the release branch
runs-on: ubuntu-22.04
@@ -83,21 +92,3 @@ jobs:
sha,
});
console.log(`Updated branch ${branch} to ${sha}`);
- name: Checkout the code
uses: actions/checkout@v4.2.2
with:
ref: "${{ github.ref_name }}"
- name: Open a pull request to merge the release branch back to main
if: github.event.inputs.merge-back
env:
VERSION: ${{ needs.compute-version.outputs.version }}
GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
run: |
gh pr create \
--title "Release branch $VERSION" \
--body "This pull request was automatically created by the release workflow. It merges the release branch back to main." \
--base main \
--head "$GITHUB_REF_NAME" \
--label "T-Task"