|
2 | 2 | # Copyright (c) 2020 José Manuel Barroso Galindo <theypsilon@gmail.com> |
3 | 3 | # Adapted from https://github.com/MiSTer-DB9/Main_MiSTer |
4 | 4 | # |
5 | | -# Merge upstream MiSTer-devel/Main_MiSTer into master. |
6 | | -# Outputs changed=true/false to $GITHUB_OUTPUT. |
| 5 | +# Merge upstream MiSTer-devel/Main_MiSTer into both release-channel branches: |
| 6 | +# master -> integration/beta branch, feeds the unstable prerelease channel |
| 7 | +# stable -> promoted branch, feeds the distribution stable channel |
| 8 | +# |
| 9 | +# Both branches must keep absorbing upstream merges so that each channel's fork |
| 10 | +# diff (upstream/master..<branch>) stays fork-only. Emits <branch>_changed=true/false |
| 11 | +# to $GITHUB_OUTPUT so the workflow can push/build only what moved. |
7 | 12 |
|
8 | 13 | set -euo pipefail |
9 | 14 |
|
10 | 15 | UPSTREAM_REPO="https://github.com/MiSTer-devel/Main_MiSTer.git" |
11 | 16 | MAIN_BRANCH="master" |
| 17 | +# Channel branches to keep in sync with upstream/master. |
| 18 | +SYNC_BRANCHES="${SYNC_BRANCHES:-master stable}" |
12 | 19 |
|
13 | 20 | export GIT_MERGE_AUTOEDIT=no |
14 | 21 | git config --local user.name "zaparoo-ci-bot" |
@@ -55,23 +62,43 @@ elif [ -n "${ORIGINAL_HEAD:-}" ]; then |
55 | 62 | git checkout -q "${ORIGINAL_HEAD}" |
56 | 63 | fi |
57 | 64 |
|
58 | | -echo "" |
59 | | -echo "Merging upstream/${MAIN_BRANCH}..." |
60 | | -BEFORE=$(git rev-parse HEAD) |
61 | | - |
62 | | -if ! git merge -Xignore-all-space --no-edit "upstream/${MAIN_BRANCH}"; then |
| 65 | +# Merge upstream into each channel branch. rerere (trained above, shared cache) |
| 66 | +# auto-resolves recurring conflicts; stable's conflicts are a subset of master's. |
| 67 | +sync_branch() { |
| 68 | + local branch="$1" |
63 | 69 | echo "" |
64 | | - echo "ERROR: Merge conflict. Resolve locally, commit, and push." |
65 | | - echo "git rerere will remember the resolution for future runs." |
66 | | - exit 1 |
67 | | -fi |
| 70 | + echo "=== Syncing ${branch} <- upstream/${MAIN_BRANCH} ===" |
| 71 | + |
| 72 | + if ! git rev-parse --verify --quiet "origin/${branch}" >/dev/null; then |
| 73 | + echo "origin/${branch} does not exist yet; skipping." |
| 74 | + echo "${branch}_changed=false" >> "${GITHUB_OUTPUT:-/dev/null}" |
| 75 | + return 0 |
| 76 | + fi |
68 | 77 |
|
69 | | -AFTER=$(git rev-parse HEAD) |
| 78 | + git checkout -q -B "${branch}" "origin/${branch}" |
| 79 | + local before after |
| 80 | + before=$(git rev-parse HEAD) |
70 | 81 |
|
71 | | -if [ "${BEFORE}" = "${AFTER}" ]; then |
72 | | - echo "Already up-to-date with upstream." |
73 | | - echo "changed=false" >> "${GITHUB_OUTPUT:-/dev/null}" |
74 | | -else |
75 | | - echo "Merged upstream changes ($(git rev-parse --short HEAD))." |
76 | | - echo "changed=true" >> "${GITHUB_OUTPUT:-/dev/null}" |
77 | | -fi |
| 82 | + if ! git merge -Xignore-all-space --no-edit "upstream/${MAIN_BRANCH}"; then |
| 83 | + echo "" |
| 84 | + echo "ERROR: Merge conflict on ${branch}. Resolve locally, commit, and push." |
| 85 | + echo "git rerere will remember the resolution for future runs." |
| 86 | + exit 1 |
| 87 | + fi |
| 88 | + |
| 89 | + after=$(git rev-parse HEAD) |
| 90 | + if [ "${before}" = "${after}" ]; then |
| 91 | + echo "${branch} already up-to-date with upstream." |
| 92 | + echo "${branch}_changed=false" >> "${GITHUB_OUTPUT:-/dev/null}" |
| 93 | + else |
| 94 | + echo "Merged upstream into ${branch} ($(git rev-parse --short HEAD))." |
| 95 | + echo "${branch}_changed=true" >> "${GITHUB_OUTPUT:-/dev/null}" |
| 96 | + fi |
| 97 | +} |
| 98 | + |
| 99 | +for branch in ${SYNC_BRANCHES}; do |
| 100 | + sync_branch "${branch}" |
| 101 | +done |
| 102 | + |
| 103 | +# Leave the checkout on the main branch for subsequent steps. |
| 104 | +git checkout -q "${MAIN_BRANCH}" |
0 commit comments