-
Notifications
You must be signed in to change notification settings - Fork 36
64 lines (57 loc) · 2.31 KB
/
aggregate-prs.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
name: Merge PR into Dynamic Branch on Label
on:
pull_request_target:
types: [labeled, synchronize]
branches:
- master
jobs:
merge-to-dynamic-branch:
if: github.event.label.name != 'do-not-merge' #Excludes those labeled with do-not-merge
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}
fetch-depth: 0
- name: Configure Git
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
- name: Check PR Labels and Merge for New Commit Events
if: github.event.action == 'synchronize'
run: |
LABELS_JSON=$(gh pr view ${{ github.event.pull_request.number }} --json labels)
LABELS=$(echo "$LABELS_JSON" | jq -r '.labels[].name')
for LABEL_BRANCH in $LABELS; do
# Check if the branch exists
if git show-ref --verify --quiet refs/heads/$LABEL_BRANCH; then
echo "Branch $LABEL_BRANCH already exists."
else
echo "Branch $LABEL_BRANCH does not exist, creating it."
git branch $LABEL_BRANCH origin/master
fi
git checkout $LABEL_BRANCH
# Merge PR changes into dynamic branch
git merge ${{ github.event.pull_request.head.sha }} --no-ff --no-commit
git commit -m "Merged PR #${{ github.event.pull_request.number }} due to new commits on labeled PR"
git push origin $LABEL_BRANCH
done
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Merge for Labeled Event
if: github.event.action == 'labeled'
run: |
LABEL_BRANCH=${{ github.event.label.name }}
# Check if the branch exists
if git show-ref --verify --quiet refs/heads/$LABEL_BRANCH; then
echo "Branch $LABEL_BRANCH already exists."
else
echo "Branch $LABEL_BRANCH does not exist, creating it."
git branch $LABEL_BRANCH origin/master
fi
git checkout $LABEL_BRANCH
# Merge PR changes into dynamic branch
git merge ${{ github.event.pull_request.head.sha }} --no-ff --no-commit
git commit -m "Merged PR #${{ github.event.pull_request.number }} due to label '$LABEL_BRANCH'"
git push origin $LABEL_BRANCH