-
Notifications
You must be signed in to change notification settings - Fork 61
44 lines (40 loc) · 1.83 KB
/
auto-merge-branches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# This workflow is intended to keep certain branches in sync and will automatically create PR's between
# these branches. For now these PR's must be manually reviewed and merged. Consider if we should just
# automatically do this if there are no conflicts.
#
# This step will fail if a PR already exists, so we ignore failures. This also
# mean that if some other error occur, the error will also be swallowed. This is acceptable.
name: Auto merge change between branches
on:
push:
branches:
# List of "from" branches. Targets are defined by the `find-target-branch`-step below.
- releases
- main
jobs:
main:
name: Create PR with changes that should be merged into another branch
runs-on: ubuntu-latest
steps:
- name: git checkout
uses: actions/checkout@v4
# Set the branch we want to merge changes into as step output. This step should list each branch name found in the `push`
# trigger in the top of this file.
- name: Set target branch
id: find-target-branch
shell: sh
run: |
if [ "${GITHUB_REF#refs/heads/}" = "releases" ]; then echo 'branch=${{ github.event.repository.default_branch }}' >> $GITHUB_OUTPUT; fi
# Unconditionally create a PR with the changes that needs to be manually reviewed.
# https://cli.github.com/manual/gh_pr_create
- name: Create Pull Request
id: open-pr
run: |
gh pr create \
--base '${{ steps.find-target-branch.outputs.branch }}' \
--head '${{ github.ref_name }}' \
--title "[Automated] Merge ${{ github.ref_name }} into ${{ steps.find-target-branch.outputs.branch }}" \
--body 'Automated Pull Request. Remember to choose "Create a merge commit" before merging.' \
|| true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}