-
Notifications
You must be signed in to change notification settings - Fork 0
71 lines (59 loc) · 2.37 KB
/
Copy pathsync.yml
File metadata and controls
71 lines (59 loc) · 2.37 KB
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
name: Prepare EdgeProbe Upstream Sync
on:
schedule:
- cron: "0 0 * * 1"
workflow_dispatch:
permissions:
contents: write
concurrency:
group: upstream-sync
cancel-in-progress: false
env:
UPSTREAM_REPOSITORY: huilang-me/CF-Server-Monitor
UPSTREAM_BRANCH: main
TARGET_BRANCH: dev
SYNC_BRANCH: sync/upstream-main
jobs:
prepare:
name: Prepare sync branch
runs-on: ubuntu-latest
steps:
- name: Checkout integration branch
uses: actions/checkout@v4
with:
ref: ${{ env.TARGET_BRANCH }}
fetch-depth: 0
- name: Fetch upstream
run: |
git remote add upstream "https://github.com/${UPSTREAM_REPOSITORY}.git"
git fetch --no-tags upstream \
"+refs/heads/${UPSTREAM_BRANCH}:refs/remotes/upstream/${UPSTREAM_BRANCH}"
- name: Check for upstream changes
id: check
run: |
if git merge-base --is-ancestor "upstream/${UPSTREAM_BRANCH}" HEAD; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
echo "Upstream is already included in ${TARGET_BRANCH}." >> "$GITHUB_STEP_SUMMARY"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
- name: Merge upstream into sync branch
if: steps.check.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git fetch origin \
"+refs/heads/${SYNC_BRANCH}:refs/remotes/origin/${SYNC_BRANCH}" || true
git checkout -B "${SYNC_BRANCH}"
if ! git merge --no-ff --no-edit "upstream/${UPSTREAM_BRANCH}"; then
echo "### Upstream sync has conflicts" >> "$GITHUB_STEP_SUMMARY"
echo "Resolve the conflicts locally and merge the result into ${TARGET_BRANCH}." >> "$GITHUB_STEP_SUMMARY"
exit 1
fi
git push --force-with-lease origin "HEAD:refs/heads/${SYNC_BRANCH}"
- name: Publish pull request link
if: steps.check.outputs.has_changes == 'true'
run: |
compare_url="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/compare/${TARGET_BRANCH}...${SYNC_BRANCH}?expand=1"
echo "### Upstream sync branch is ready" >> "$GITHUB_STEP_SUMMARY"
echo "Review the changes and open a pull request: ${compare_url}" >> "$GITHUB_STEP_SUMMARY"