Files
letro-authentication-service/.github/workflows/merge-back.yaml
2025-01-31 13:27:27 +01:00

73 lines
2.2 KiB
YAML

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 },
);