Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Sync: run the host unit tests and check patcher/tree consistency; a daily health check

LNPANDY7a1cbccffc30
diff --git a/.github/workflows/daily-health.yml b/.github/workflows/daily-health.yml
new file mode 100644
index 00000000..ac468fc1
--- /dev/null
+++ b/.github/workflows/daily-health.yml
@@ -0,0 +1,84 @@
+# Daily: check the fork's health without changing anything. Separate from sync-upstream.yml on
+# purpose — that workflow can fail silently (its own issue step needs a permission it may not have),
+# so this one reports on the state of the tree rather than on a sync attempt:
+# - the last sync is recent (catches a schedule that stopped firing, or a run that died early)
+# - the patchers still reproduce the tree (catches a source fix without its patcher entry)
+# - the host builds and the host unit tests pass (catches a fork change that broke a test rule)
+# - upstream has not moved without a sync (catches a failed sync that left no issue)
+# A problem opens an issue with the log; a clean run just succeeds. No push, ever.
+name: Daily health check
+
+on:
+ schedule:
+ - cron: '0 22 * * *' # 22:00 UTC = 6:00 Beijing, before the sync at 21:30 UTC has aged a day
+ workflow_dispatch:
+
+permissions:
+ contents: read
+ issues: write
+
+jobs:
+ check:
+ runs-on: macos-latest
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 0 # the patcher check compares against upstream/main
+
+ - name: Fetch upstream
+ run: |
+ git remote add upstream https://github.com/seedds/nxnative.git
+ git fetch upstream main --depth=1 || git fetch upstream main
+
+ - name: Health check
+ id: check
+ run: |
+ set -o pipefail
+ {
+ echo "=== last sync ==="
+ LAST=$(cat .upstream-ref 2>/dev/null || echo none)
+ echo ".upstream-ref: $LAST"
+ if [ "$LAST" != none ]; then
+ AGO=$(( ( $(date +%s) - $(git log -1 --format=%ct "$(git rev-list -1 --all --grep="Sync upstream" | head -1)" 2>/dev/null || date +%s) ) / 3600 ))
+ echo "last sync commit age: ${AGO}h"
+ [ "$AGO" -gt 48 ] && echo "PROBLEM: no sync for ${AGO}h (the schedule should run daily)"
+ fi
+
+ echo
+ echo "=== upstream drift ==="
+ NEW=$(git rev-parse upstream/main)
+ echo "upstream/main: $NEW"
+ if [ "$LAST" != none ] && [ "$LAST" != "$NEW" ]; then
+ BEHIND=$(git rev-list --count "$LAST..$NEW" 2>/dev/null || echo '?')
+ echo "commits upstream since the last sync: $BEHIND"
+ fi
+
+ echo
+ echo "=== patcher consistency ==="
+ python3 scripts/sync_upstream.py --old "$NEW" --new "$NEW" --skip-build 2>&1 | tail -40
+ } 2>&1 | tee check.log
+
+ - name: Host build and unit tests
+ run: |
+ set -o pipefail
+ GAME=$(ls dm/games | grep '^0100' | head -1)
+ echo "=== host build ($GAME) ===" | tee -a check.log
+ make -C dm/host GAME=$GAME dmhost -j4 2>&1 | tail -20 | tee -a check.log
+ echo "=== host unit tests ===" | tee -a check.log
+ make -C dm/host/tests GAME=$GAME run -j4 2>&1 | tail -30 | tee -a check.log
+
+ - name: Report a problem
+ if: failure()
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ gh issue create \
+ --title "Daily health check failed $(date -u +%Y-%m-%d)" \
+ --body "The daily check found a problem. Nothing was changed — the tree on main is as it was.
+
+ \`\`\`
+ $(tail -60 check.log 2>/dev/null || echo 'see the workflow log')
+ \`\`\`
+
+ Common causes: a fork source change without its patcher entry (patcher drift), a test rule that no longer links a new dependency, or a sync that has not run for over two days." \
+ || echo "issue creation failed; the log is in the workflow run"
diff --git a/scripts/sync_upstream.py b/scripts/sync_upstream.py
index 26313ec4..b0375342 100644
--- a/scripts/sync_upstream.py
+++ b/scripts/sync_upstream.py
@@ -606,6 +606,71 @@ def verify(skip_build):
tail = '\n'.join((r.stdout + r.stderr).splitlines()[-25:])
fail(f'host build failed:\n{tail}')
else: say(f' + host build OK ({game})')
+ # Host unit tests: the fs tests #include ../hle_fs.c and link romfs_arc.c, so a fork change that
+ # the test rules do not know about breaks them at link time and they stop running silently
+ # (PR #12 — they had been unbuildable). Cheap (seconds) and catches that class here.
+ say(f' … host unit tests for {game}')
+ r = subprocess.run(['make', '-C', 'dm/host/tests', f'GAME={game}', 'run', '-j4'], cwd=REPO, capture_output=True, text=True)
+ if r.returncode:
+ tail = '\n'.join((r.stdout + r.stderr).splitlines()[-25:])
+ fail(f'host unit tests failed:\n{tail}')
+ else: say(' + host unit tests OK')
+ check_patcher_consistency()
+
+
+def check_patcher_consistency():
+ """Every carrier's patched form must equal the file in the tree, code line by code line.
+
+ A fork change made to a carrier's source but not to its patcher entry is invisible today (the
+ marker is present, so the patcher skips) and reappears the next time upstream touches that file
+ — PR #11 was exactly that: GetEntryType had been fixed to arc_rel in the source while the patcher
+ still inserted ROMFSARC_SYNTH_REL. Comparing the patcher's output against the working tree makes
+ the drift show up on the sync that introduces it rather than months later.
+
+ Comments and blank lines are ignored: a comment reworded in the tree is not drift, and demanding
+ a matching comment edit in the patcher would train people to ignore this check.
+ """
+ say(' … patcher consistency (patched upstream file vs the tree, comments ignored)')
+ def code(text):
+ out = []
+ for ln in text.splitlines():
+ s = ln.strip()
+ if not s or s.startswith(('#', '//', '/*', '*', '<!--')):
+ continue
+ # strip a trailing comment too: `code; // why` is the same statement however the why
+ # is worded, and a reworded trailing comment must not read as drift
+ cut = ln.find(' //')
+ if cut < 0:
+ cut = ln.find(' #')
+ if cut > 0:
+ ln = ln[:cut]
+ out.append(ln.rstrip())
+ return out
+ drift = []
+ for path, patcher in PATCHERS.items():
+ src = REPO / path
+ if not src.exists():
+ continue
+ upstream = subprocess.run(['git', 'show', f'upstream/main:{path}'], cwd=REPO,
+ capture_output=True, text=True)
+ if upstream.returncode:
+ continue # a fork-only file has no upstream form to compare
+ try:
+ out = patcher(upstream.stdout)
+ except SyncProblem:
+ continue # an anchor miss is reported by apply_changes already
+ if out is None:
+ out = upstream.stdout
+ if code(out) != code(src.read_text(encoding='utf-8', errors='replace')):
+ drift.append(path)
+ if drift:
+ for d in drift:
+ say(f' ! {d}: the patcher and the tree disagree')
+ fail('patcher drift: ' + ', '.join(drift) +
+ ' — the source was changed without its patcher entry (or the other way round); '
+ 'a future sync would silently revert the change')
+ else:
+ say(f' + {len(PATCHERS)} patchers agree with the tree')
def apply_changes(a, changes):
"""Take every changed file from upstream, then re-apply the fork's patches to the carriers."""