-
Notifications
You must be signed in to change notification settings - Fork 58
49 lines (43 loc) · 1.7 KB
/
sync-pr.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
name: Automatically Sync PR with Base Branch
on:
pull_request:
types:
- opened
- synchronize
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Configure Git Identity
run: |
git config --global user.email "ci-build@aemforms"
git config --global user.name "ci-build"
- name: Validate branch names
id: validate
run: |
echo "Validating branch names..."
if ! [[ "${{ github.event.pull_request.head.ref }}" =~ ^[a-zA-Z0-9._/-]+$ ]]; then
echo "Invalid characters in head ref"
exit 1
fi
if ! [[ "${{ github.event.pull_request.base.ref }}" =~ ^[a-zA-Z0-9._/-]+$ ]]; then
echo "Invalid characters in base ref"
exit 1
fi
echo "::set-output name=head_ref::${{ github.event.pull_request.head.ref }}"
echo "::set-output name=base_ref::${{ github.event.pull_request.base.ref }}"
- name: Sync with Base Branch
if: ${{ github.event.pull_request.base.ref != 'master' }}
run: |
git fetch origin ${{ steps.validate.outputs.head_ref }}
git fetch origin ${{ steps.validate.outputs.base_ref }}
git checkout ${{ steps.validate.outputs.base_ref }}
git pull origin ${{ steps.validate.outputs.base_ref }}
git checkout ${{ steps.validate.outputs.head_ref }}
git pull origin ${{ steps.validate.outputs.head_ref }}
git rebase ${{ steps.validate.outputs.base_ref }}
git push --force origin ${{ steps.validate.outputs.head_ref }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}