-
Notifications
You must be signed in to change notification settings - Fork 6
84 lines (75 loc) · 2.62 KB
/
back-merge-handler.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Back Merge handler
on:
push:
branches:
- master
- stable
jobs:
pr_master_to_stable:
runs-on: ubuntu-latest
if: github.ref_name == 'master'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if PR exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json baseRefName,headRefName \
--jq '
map(select(.baseRefName == "stable" and .headRefName == "master"))
| length
')
if ((prs > 0)); then
echo "Pull Request already exists"
echo "SKIP=true" >> $GITHUB_ENV
fi
- name: Check if stable is ahead
run: |
commits=$(git rev-list origin/stable..origin/master --count)
if ((commits == 0)); then
echo "No diffs was found between branches"
echo "SKIP=true" >> $GITHUB_ENV
fi
- name: Create Pull Request
if: env.SKIP != 'true'
run: gh pr create -B stable -H master --title '[GitHub Actions] Merge master -> stable' --label back-merge --body 'Autogenerated Pull Request for `back-merge` triggered by Github Actions'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pr_stable_to_develop:
runs-on: ubuntu-latest
if: github.ref_name == 'stable'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check if PR exists
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
prs=$(gh pr list \
--repo "$GITHUB_REPOSITORY" \
--json baseRefName,headRefName \
--jq '
map(select(.baseRefName == "develop" and .headRefName == "stable"))
| length
')
if ((prs > 0)); then
echo "Pull Request already exists"
echo "SKIP=true" >> $GITHUB_ENV
fi
- name: Check if stable is ahead
run: |
commits=$(git rev-list origin/develop..origin/stable --count)
if ((commits == 0)); then
echo "No diffs was found between branches"
echo "SKIP=true" >> $GITHUB_ENV
fi
- name: Create Pull Request
if: env.SKIP != 'true'
run: gh pr create -B develop -H stable --title '[GitHub Actions] Merge stable -> develop' --label back-merge --body 'Autogenerated Pull Request for `back-merge` triggered by Github Actions'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}