Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
Re-evaluate the parent when a child PR is opened or reopened
v0lumehi72c662e12134
diff --git a/.github/scripts/stack_rerun.py b/.github/scripts/stack_rerun.pyindex 38e68096..b3b97f6a 100644--- a/.github/scripts/stack_rerun.py+++ b/.github/scripts/stack_rerun.py@@ -8,6 +8,11 @@ the heavy jobs start, and the `stack` job asks GitHub again, live, whether the ponly if the parent has no other open child now (it is the tip), and a run of the workflow is finished and has a `Stack` jobnothing runs in progress are left alone, and nothing is re-run twice+A child that is `opened` or `reopened` is the other way round: its parent, the open PR whose head branch is the child's base, has a child now+and is no longer the tip. If the parent's heavy jobs started before the child existed, re-running the `Stack` job makes them skip. When a run of+the parent is still queued or in progress, the heavy jobs may be running: nothing is cancelled (a cancelled required check blocks the merge),+the script names the runs and leaves it to the maintainer. When all its latest runs are finished, each `Stack` job is re-run and decides live.+The event data arrives as environment variables and is only ever an argument of `gh`, never part of a shell command. No code of the pullrequest is checked out or run. Inputs: ACTION, BASE_REF, OLD_BASE_REF, PR_NUMBER, GH_REPO, GH_TOKEN. DRY_RUN=1 only prints."""@@ -22,7 +27,7 @@ WORKFLOWS = ('tests', 'Build the NX2Apple app (macOS)')def parent_branch(env):"""The head branch of the child's former parent, or ''."""- if env.get('ACTION') == 'closed':+ if env.get('ACTION') in ('closed', 'opened', 'reopened'):return env.get('BASE_REF', '')if env.get('ACTION') == 'edited':return env.get('OLD_BASE_REF', '') # empty unless the base changed@@ -59,21 +64,43 @@ def stack_job(repo, run_id):return None+def child_appeared(env, repo, parent, runs):+ """A child was opened on `parent`: re-run the Stack job of finished runs so the heavy jobs skip. Never cancel a run."""+ busy = [r for r in runs if r.get('status') != 'completed']+ if busy:+ ids = ', '.join(f'{r["workflowName"]} run {r["databaseId"]}' for r in busy)+ print(f'The heavy jobs of #{parent["number"]} were started before this child existed ({ids}). They are not cancelled. '+ f'Once the runs finished, re-run their Stack job by hand: gh run rerun <run id> --job <id of the Stack job>.')+ return 0+ for run in runs:+ job_id = stack_job(repo, run['databaseId'])+ if not job_id:+ print(f'{run["workflowName"]} (run {run["databaseId"]}) has no Stack job: left alone.')+ continue+ print(f'#{parent["number"]} has an open child now: re-running the Stack job of {run["workflowName"]} (run {run["databaseId"]}).')+ if env.get('DRY_RUN') != '1':+ gh('run', 'rerun', str(run['databaseId']), '--repo', repo, '--job', str(job_id))+ return 0++def main(env=os.environ):repo = env.get('GH_REPO', '')branch = parent_branch(env)if not repo or not branch:- print('Not a close or a base change of a child: nothing to do.')+ print('Not an open, close or base change of a child: nothing to do.')return 0try:parent = find_parent(repo, branch)if not parent:print(f'No open pull request has the head branch {branch}: nothing to do.')return 0+ runs = latest_runs(repo, parent['headRefOid'])+ if env.get('ACTION') in ('opened', 'reopened'):+ return child_appeared(env, repo, parent, runs)if open_children(repo, branch):print(f'#{parent["number"]} still has an open child: it is not the tip.')return 0- for run in latest_runs(repo, parent['headRefOid']):+ for run in runs:job_id = stack_job(repo, run['databaseId'])if not job_id:print(f'{run["workflowName"]} (run {run["databaseId"]}) is not finished or has no Stack job: left alone.')diff --git a/.github/scripts/tests/test_stack_rerun.py b/.github/scripts/tests/test_stack_rerun.pyindex 4cc0ec66..2397b352 100644--- a/.github/scripts/tests/test_stack_rerun.py+++ b/.github/scripts/tests/test_stack_rerun.py@@ -64,9 +64,55 @@ class Rerun(unittest.TestCase):self.assertEqual(fake.calls, [])def test_other_actions_do_nothing(self):- _, fake, _ = run({'ACTION': 'opened', 'BASE_REF': 'v0lumehi/b'})+ _, fake, _ = run({'ACTION': 'synchronize', 'BASE_REF': 'v0lumehi/b'})self.assertEqual(fake.calls, [])+ def test_opened_child_reruns_the_stack_job_of_a_finished_parent(self):+ code, fake, out = run({'ACTION': 'opened', 'BASE_REF': 'v0lumehi/b'})+ self.assertEqual(code, 0)+ self.assertEqual(fake.reruns(), [('run', 'rerun', '10', '--repo', 'LNPANDY/NX2Apple', '--job', '77'),+ ('run', 'rerun', '11', '--repo', 'LNPANDY/NX2Apple', '--job', '77')])+ self.assertIn('open child now', out)++ def test_opened_child_does_not_ask_for_other_children(self):+ _, fake, _ = run({'ACTION': 'opened', 'BASE_REF': 'v0lumehi/b'}, children=[{'number': 500, 'headRefName': 'x', 'isCrossRepository': False}])+ self.assertEqual(len(fake.reruns()), 2)++ def test_opened_child_with_a_running_parent_run_changes_nothing(self):+ runs = [{'databaseId': 10, 'workflowName': 'tests', 'status': 'in_progress'},+ {'databaseId': 11, 'workflowName': 'Build the NX2Apple app (macOS)', 'status': 'completed'}]+ code, fake, out = run({'ACTION': 'opened', 'BASE_REF': 'v0lumehi/b'}, runs=runs)+ self.assertEqual(code, 0)+ self.assertEqual(fake.reruns(), [])+ self.assertIn('started before this child existed', out)+ self.assertIn('run 10', out)+ self.assertNotIn('run 11', out)++ def test_opened_child_with_a_queued_parent_run_changes_nothing(self):+ runs = [{'databaseId': 10, 'workflowName': 'tests', 'status': 'queued'}]+ _, fake, out = run({'ACTION': 'opened', 'BASE_REF': 'v0lumehi/b'}, runs=runs)+ self.assertEqual(fake.reruns(), [])+ self.assertIn('run 10', out)+ self.assertFalse([c for c in fake.calls if c[0] == 'run' and c[1] == 'cancel'])++ def test_opened_child_on_main_has_no_parent(self):+ _, fake, out = run({'ACTION': 'opened', 'BASE_REF': 'main'}, parents=[])+ self.assertEqual(fake.reruns(), [])+ self.assertIn('nothing to do', out)++ def test_reopened_child_reruns_like_an_opened_one(self):+ _, fake, _ = run({'ACTION': 'reopened', 'BASE_REF': 'v0lumehi/b'})+ self.assertEqual(len(fake.reruns()), 2)++ def test_opened_child_with_a_fork_parent_is_ignored(self):+ _, fake, _ = run({'ACTION': 'opened', 'BASE_REF': 'v0lumehi/b'}, parents=[{**PARENT, 'isCrossRepository': True}])+ self.assertEqual(fake.reruns(), [])++ def test_opened_dry_run_does_not_rerun(self):+ _, fake, out = run({'ACTION': 'opened', 'BASE_REF': 'v0lumehi/b', 'DRY_RUN': '1'})+ self.assertEqual(fake.reruns(), [])+ self.assertIn('re-running', out)+def test_no_open_parent(self):_, fake, out = run({'ACTION': 'closed', 'BASE_REF': 'main'}, parents=[])self.assertEqual(fake.reruns(), [])diff --git a/.github/workflows/stack-parent-rerun.yml b/.github/workflows/stack-parent-rerun.ymlindex d0cf6ab9..4c564681 100644--- a/.github/workflows/stack-parent-rerun.yml+++ b/.github/workflows/stack-parent-rerun.yml@@ -1,4 +1,5 @@-# When the child of a stacked PR is closed, merged or retargeted, its parent may be the tip of the stack now. The parent's heavy jobs were skipped+# When the child of a stacked PR is closed, merged or retargeted, its parent may be the tip of the stack now. When a child is opened or reopened,+# its parent is no longer the tip, and its Stack job is re-run so that heavy jobs started earlier are skipped (only if the parent's runs finished). The parent's heavy jobs were skipped# while it had a child, and nothing re-triggers them. This workflow re-runs the `Stack` job of the parent's latest runs (tests, the app build),# which decides again, live, and starts the heavy jobs that depend on it. See .github/scripts/stack_rerun.py and CONTRIBUTING.md, "CI on stacks".#@@ -10,7 +11,7 @@ name: Stack parent re-runon:pull_request_target:- types: [closed, edited]+ types: [opened, reopened, closed, edited]permissions: {}@@ -20,9 +21,9 @@ concurrency:jobs:rerun:- name: Re-run the parent of a closed or retargeted PR+ name: Re-run the parent of an opened, closed or retargeted PR# A title or body edit has no `changes.base`.- if: ${{ github.event.action == 'closed' || github.event.changes.base != null }}+ if: ${{ github.event.action != 'edited' || github.event.changes.base != null }}runs-on: ubuntu-latesttimeout-minutes: 5permissions:diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 7029e6ec..1f2a3198 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -101,7 +101,7 @@ The maintainers work in stacks: one PR per step, each based on the head branch o- **What runs where.** Every PR runs the cheap checks (Patch queue, Qt front end, Triage script tests, Changed areas). The jobs that take a macOS runner (Mac launcher with `swift test`, Tool tests, the engine jobs) run on the tip. The app build (`Build the NX2Apple app (macOS)`) runs on the tip only when the PR changes a file that goes into the packaging (`.github/scripts/build_wanted.py` lists them) or has the label `full-build`. A push to `main`, a tag and a manual run always run everything. The changed files are counted against `main`, so the tip counts every PR below it.- **Why a lower PR shows "skipped".** Its `Stack` job found an open PR on top of it and skipped the heavy jobs. The job summary says `Not the tip of a stack: heavy checks run on #N`. A skipped job counts as passed for the required checks, so the PR can merge. The checks are skipped per job, never per workflow, because a workflow that does not start reports nothing and blocks the merge.-- **When a PR becomes the tip.** If its child is closed, merged or retargeted, `Stack parent re-run` re-runs the `Stack` job of the parent's latest runs, and the heavy jobs start. If a parent still shows skipped (its run was still going when the child closed), open the run and press "Re-run all jobs", or run `gh run rerun <run id> --job <id of the Stack job>`.+- **When a PR becomes the tip.** If its child is closed, merged or retargeted, `Stack parent re-run` re-runs the `Stack` job of the parent's latest runs, and the heavy jobs start. If a parent still shows skipped (its run was still going when the child closed), open the run and press "Re-run all jobs", or run `gh run rerun <run id> --job <id of the Stack job>`. A child that is opened or reopened later re-evaluates its parent the same way, so the parent's heavy jobs skip. Nothing is cancelled: if the parent's run is still going, its heavy jobs keep running. Re-run its `Stack` job by hand once the run finished, or open the child PRs top first.- **Force a run.** Add the label `full-build`, then re-run the `Build the NX2Apple app (macOS)` run (the label is read when the job runs, not when the run starts). Or start the workflow by hand: `gh workflow run build-mac-app.yml --ref <branch>`. A run by hand is always the tip.- **Merge a stack through its top PR.** Use the async API on the tip, it merges the PRs below it too: `gh api -X PUT repos/LNPANDY/NX2Apple/pulls/<n>/merge-async -f merge_method=merge -f merge_action=direct_merge`. The required checks of every PR in the stack must have reported, and a skipped heavy job has.- **If the lookup fails** (GitHub API down), the PR counts as the tip and CI runs. A broken lookup never skips a check.