Skip to content

Commit 9c694bc

Browse files
authored
Add GitHub Actions workflow to sync master to dev/4.0
1 parent 7d0f85d commit 9c694bc

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Sync dev/4.0
2+
3+
on:
4+
push:
5+
branches:
6+
# Keep this in sync with SYNC_SOURCE_BRANCH below.
7+
# GitHub Actions does not allow env values in trigger branch filters.
8+
- master
9+
10+
env:
11+
SYNC_SOURCE_BRANCH: master
12+
SYNC_TARGET_BRANCH: dev/4.0
13+
14+
permissions:
15+
contents: write
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: false
20+
21+
jobs:
22+
sync-dev-branch:
23+
name: Merge ${{ env.SYNC_SOURCE_BRANCH }} into ${{ env.SYNC_TARGET_BRANCH }}
24+
# Keep this named after the GitHub repository.
25+
# GitHub Actions does not allow workflow env values in jobs.<job_id>.if.
26+
if: github.repository == 'phpbb-extensions/phpbb-ext-skeleton' && github.event.repository.fork == false
27+
runs-on: ubuntu-latest
28+
29+
steps:
30+
- name: Check out repository
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Configure Git author
36+
run: |
37+
git config user.name "github-actions[bot]"
38+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
39+
40+
- name: Merge source branch into target branch when clean
41+
run: |
42+
if ! git ls-remote --exit-code --heads origin "${SYNC_TARGET_BRANCH}" > /dev/null 2>&1; then
43+
echo "origin/${SYNC_TARGET_BRANCH} does not exist; skipping."
44+
exit 0
45+
fi
46+
47+
git fetch --no-tags --prune origin "${SYNC_TARGET_BRANCH}"
48+
git checkout -B "${SYNC_TARGET_BRANCH}" "origin/${SYNC_TARGET_BRANCH}"
49+
50+
if git merge --no-edit "$GITHUB_SHA"; then
51+
if [ "$(git rev-list --count "origin/${SYNC_TARGET_BRANCH}..HEAD")" -eq 0 ]; then
52+
echo "${SYNC_TARGET_BRANCH} is already up to date."
53+
exit 0
54+
fi
55+
56+
git push origin "HEAD:${SYNC_TARGET_BRANCH}"
57+
else
58+
echo "${SYNC_SOURCE_BRANCH} could not be merged cleanly into ${SYNC_TARGET_BRANCH}; skipping."
59+
if git rev-parse -q --verify MERGE_HEAD > /dev/null; then
60+
git merge --abort
61+
fi
62+
fi

0 commit comments

Comments
 (0)