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
Release candidates: rc tags publish a pre-release with the engine the release ships
v0lumehicf5ad3c91e69
diff --git a/.github/workflows/build-mac-app.yml b/.github/workflows/build-mac-app.ymlindex bedec58b..9ab37ed4 100644--- a/.github/workflows/build-mac-app.yml+++ b/.github/workflows/build-mac-app.yml@@ -19,21 +19,39 @@# so a player installs neither Homebrew nor Python (frontend/tools/bundle_tools.sh builds them from pinned, checksummed sources; check_bundle.sh# runs each from the assembled bundle with a clean PATH, checks the load paths and the signature).#-# - push a tag vX.Y.Z → builds and attaches the app to that release-# - workflow_dispatch → artifact only-# - a pull request that touches frontend/ or this file → artifact only, so a change to the bundle is tested before a release needs it+# - push a tag vX.Y.Z-rcN → a release candidate: a pre-release that is never "latest", with the app, the engine and a signed latest.json+# that names the engine the release X.Y.Z will carry (RELEASING.md)+# - push a tag vX.Y.Z → the release: it ships the files of the newest release candidate on the same commit, its engine checked against this build.+# A commit without a release candidate fails, unless a manual run on the tag sets release_without_rc+# - a push to main, or a pull request, that touches the paths below → artifact only (NX2Apple-macOS-arm64), which tools/try-pr opens.+# Nothing is published+# - workflow_dispatch → artifact only, or on a tag ref the same as a push of that tagname: Build nxnative (native macOS)on:push:+ branches: [main]tags: ['v*']+ # GitHub does not evaluate path filters for tag pushes: every v* tag builds. On main only a change to these paths builds.+ paths: ['frontend/**', 'tools/engine.py', 'tools/release_manifest.py', 'tools/requirements-release.txt', 'patches/**', '.upstream-ref', '.github/workflows/build-mac-app.yml']pull_request:paths: ['frontend/**', 'tools/engine.py', 'tools/release_manifest.py', 'tools/requirements-release.txt', 'patches/**', '.upstream-ref', '.github/workflows/build-mac-app.yml']workflow_dispatch:+ inputs:+ release_without_rc:+ description: 'Run on a final tag only (Use workflow from: the tag). Publish it although its commit has no release candidate. An emergency exit, see RELEASING.md.'+ type: boolean+ default: falsepermissions:contents: write+# A newer push to a pull request replaces its running build. Every commit on main and every tag keeps its own run: each main commit has its+# app artifact, and a release is never cancelled halfway.+concurrency:+ group: build-mac-app-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}+jobs:# The app icon is AppIcon.icon (Icon Composer). The actool of Xcode 26.6 (the default on macos-latest) throws an exception on it, the one of# Xcode 27.1 compiles it. So actool runs on the xcode-27 runner, as in tests.yml, and the build job takes the two files it writes. Assets.car is@@ -110,22 +128,85 @@ jobs:- name: Version from the tagid: vershell: bash+ env:+ REF_TYPE: ${{ github.ref_type }}+ TAG: ${{ github.ref_name }}run: |- # The app reads its version from ContentView.appVersion, and the bundle plist must agree- # or the updater compares the wrong number. Take the tag, and fail loudly on a mismatch- # rather than shipping a bundle that calls itself something else.- tag="${{ github.ref_name }}"- v="${tag#v}"- if [ "${{ github.ref_type }}" != "tag" ]; then- v=$(sed -n 's/.*static let appVersion = "\(.*\)".*/\1/p' frontend/Sources/NSPortBuilder/ContentView.swift)+ set -euo pipefail+ # The app reads its version from ContentView.appVersion, and the bundle plist must agree or the updater compares the wrong number.+ # Take the tag, and fail loudly on a mismatch rather than shipping a bundle that calls itself something else.+ # A release candidate vX.Y.Z-rcN is the build of the release X.Y.Z: its bundle says X.Y.Z, because the final tag ships these+ # exact files and the updater (AppUpdate.bundleProblem) accepts only a bundle whose version is the release's.+ src=$(sed -n 's/.*static let appVersion = "\(.*\)".*/\1/p' frontend/Sources/NSPortBuilder/ContentView.swift)+ kind=build rc=""+ if [ "$REF_TYPE" != "tag" ]; then+ v="$src"echo "not a tag: taking the version from the source ($v)"+ else+ v="${TAG#v}"+ if [[ "$v" =~ ^(.+)-rc([1-9][0-9]*)$ ]]; then+ kind=rc v="${BASH_REMATCH[1]}" rc="${BASH_REMATCH[2]}"+ elif [[ "$v" == *-rc* ]]; then+ echo "::error::$TAG is not a release candidate tag: write vX.Y.Z-rcN with N from 1 (RELEASING.md)"+ exit 1+ else+ kind=final+ fifi- src=$(sed -n 's/.*static let appVersion = "\(.*\)".*/\1/p' frontend/Sources/NSPortBuilder/ContentView.swift)if [ "$v" != "$src" ]; then- echo "::error::tag says $v but ContentView.appVersion says $src — bump the source first"+ echo "::error::tag says $v but ContentView.appVersion says $src: bump the source first"+ exit 1+ fi+ echo "$kind: version $v${rc:+, release candidate $rc}"+ { echo "version=$v"; echo "kind=$kind"; echo "rc=$rc"; } >> "$GITHUB_OUTPUT"++ - name: The release candidate of this commit (final tags)+ id: rc+ if: steps.ver.outputs.kind == 'final'+ shell: bash+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ ENGINE_SIGNING_KEY: ${{ secrets.ENGINE_SIGNING_KEY }}+ VERSION: ${{ steps.ver.outputs.version }}+ TAG: ${{ github.ref_name }}+ WITHOUT_RC: ${{ github.event_name == 'workflow_dispatch' && inputs.release_without_rc }}+ run: |+ set -euo pipefail+ # Players get the build that was tested: the newest vX.Y.Z-rcN on this commit. Its app zips go out as they are (a rebuild+ # is not byte for byte the same app). Its engine zip must hold the files this commit builds (the zip is reproducible, so+ # normally the same bytes) and be the one its signed latest.json names. Any difference stops the release.+ # Each rc tag with the commit it points at (the peeled ^{} line of an annotated tag).+ tags=$(git ls-remote --tags origin "refs/tags/v${VERSION}-rc*" | awk '{ r = $2; sub("^refs/tags/", "", r)+ if (r ~ /\^\{\}$/) { sub(/\^\{\}$/, "", r); peeled[r] = $1 } else direct[r] = $1 }+ END { for (r in direct) print (r in peeled ? peeled[r] : direct[r]), r }')+ rc=$(printf '%s\n' "$tags" | awk -v sha="$GITHUB_SHA" -v v="v${VERSION}-rc" '$1 == sha && index($2, v) == 1 {+ n = substr($2, length(v) + 1); if (n ~ /^[1-9][0-9]*$/) print n, $2 }' | sort -n | tail -n 1 | cut -d' ' -f2)+ if [ -z "$rc" ]; then+ others=$(printf '%s\n' "$tags" | awk 'NF == 2 { printf "%s%s (%s)", sep, $2, substr($1, 1, 12); sep = ", " }')+ if [ "$WITHOUT_RC" = "true" ]; then+ echo "::warning title=No release candidate::$TAG is published without a release candidate (release_without_rc). Nobody tested this build as a whole. Say so in the release notes."+ echo "promote=false" >> "$GITHUB_OUTPUT"+ exit 0+ fi+ echo "::error title=No release candidate::$TAG points at ${GITHUB_SHA:0:12}, which has no release candidate tag v${VERSION}-rcN.${others:+ Candidates on other commits: $others.} Tag this commit v${VERSION}-rcN, test it, then tag the final on the same commit (RELEASING.md). In an emergency: gh workflow run build-mac-app.yml --ref $TAG -f release_without_rc=true"exit 1fi- echo "version=$v" >> "$GITHUB_OUTPUT"+ echo "release candidate of this commit: $rc"+ dir="$RUNNER_TEMP/rc"+ rm -rf "$dir"; mkdir -p "$dir"+ names=$(gh release view "$rc" --json assets --jq '.assets[].name') || {+ echo "::error title=No release candidate build::$rc has no release yet. Wait for its build to finish, then re-run this job."; exit 1; }+ for a in NX2Apple-macOS-arm64.zip nxnative-macOS-arm64.zip NS-Port-Builder-macOS-arm64.zip NX2Apple-engine.zip latest.json; do+ grep -qx "$a" <<< "$names" || { echo "::error title=Incomplete release candidate::$rc has no $a. Wait for its build to finish, or cut the next release candidate."; exit 1; }+ gh release download "$rc" -p "$a" -D "$dir"+ done+ if grep -qx latest.json.sig <<< "$names"; then gh release download "$rc" -p latest.json.sig -D "$dir"; fi+ # The signature the launcher checks (required while ENGINE_SIGNING_KEY is set), then the same build, file by file.+ python tools/release_manifest.py verify --manifest "$dir/latest.json"+ python tools/release_manifest.py check-rc --manifest "$dir/latest.json" --version "$VERSION" --engine-zip "$dir/NX2Apple-engine.zip" \+ --app-zip "$dir/NX2Apple-macOS-arm64.zip" --built-engine-zip "$RUNNER_TEMP/engine-out/NX2Apple-engine.zip"+ rm -f "$dir/latest.json" "$dir/latest.json.sig" # the release gets its own manifest, with its own download URL+ { echo "promote=true"; echo "tag=$rc"; echo "dir=$dir"; } >> "$GITHUB_OUTPUT"- name: Buildworking-directory: frontend@@ -231,35 +312,104 @@ jobs:if-no-files-found: error- name: Attach to the release- if: startsWith(github.ref, 'refs/tags/')+ if: steps.ver.outputs.kind == 'rc' || steps.ver.outputs.kind == 'final'shell: bashenv:GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ KIND: ${{ steps.ver.outputs.kind }}+ VERSION: ${{ steps.ver.outputs.version }}+ RC: ${{ steps.ver.outputs.rc }}+ PROMOTE: ${{ steps.rc.outputs.promote }}+ RC_TAG: ${{ steps.rc.outputs.tag }}+ RC_DIR: ${{ steps.rc.outputs.dir }}run: |- gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1 || \- gh release create "$GITHUB_REF_NAME" --title "$GITHUB_REF_NAME" --notes "NX2Apple $GITHUB_REF_NAME"- # All three names, one build: NX2Apple is current; the older two keep self-update working+ set -euo pipefail+ src=frontend+ if [ "$KIND" = rc ]; then+ # A pre-release, never "latest": the app's update reads releases/latest, which skips it. Its files are what gets tested and+ # what the final tag ships, so a candidate is built once. A second build would replace the tested app with other bytes.+ if names=$(gh release view "$GITHUB_REF_NAME" --json assets --jq '.assets[].name' 2> /dev/null); then+ if grep -qx NX2Apple-macOS-arm64.zip <<< "$names"; then+ echo "::error::$GITHUB_REF_NAME already has its build. Cut the next release candidate instead of building this one again."+ exit 1+ fi+ gh release edit "$GITHUB_REF_NAME" --prerelease --latest=false --title "NX2Apple $VERSION release candidate $RC"+ else+ gh release create "$GITHUB_REF_NAME" --prerelease --latest=false --verify-tag --title "NX2Apple $VERSION release candidate $RC" \+ --notes "Release candidate $RC of NX2Apple $VERSION. The engine is published next, then these notes name it."+ fi+ else+ notes="NX2Apple $GITHUB_REF_NAME"+ if [ "$PROMOTE" = true ]; then+ src="$RC_DIR"+ notes="$notes"$'\n\n'"The files of the release candidate $RC_TAG, which was tested on the same commit (${GITHUB_SHA:0:12})."+ else+ notes="$notes"$'\n\n'"Published without a release candidate (release_without_rc)."+ fi+ gh release view "$GITHUB_REF_NAME" >/dev/null 2>&1 || \+ gh release create "$GITHUB_REF_NAME" --verify-tag --title "$GITHUB_REF_NAME" --notes "$notes"+ fi+ # All three names, one build: NX2Apple is current. The older two keep self-update working# for installs from before each rename (an app replaces the bundle at its own path).gh release upload "$GITHUB_REF_NAME" \- frontend/NX2Apple-macOS-arm64.zip \- frontend/nxnative-macOS-arm64.zip \- frontend/NS-Port-Builder-macOS-arm64.zip --clobber+ "$src/NX2Apple-macOS-arm64.zip" \+ "$src/nxnative-macOS-arm64.zip" \+ "$src/NS-Port-Builder-macOS-arm64.zip" --clobber- name: Publish the engine (NX2Apple-engine.zip, latest.json, latest.json.sig)- if: startsWith(github.ref, 'refs/tags/')+ if: steps.ver.outputs.kind == 'rc' || steps.ver.outputs.kind == 'final'shell: bashenv:GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}ENGINE_SIGNING_KEY: ${{ secrets.ENGINE_SIGNING_KEY }}+ VERSION: ${{ steps.ver.outputs.version }}+ PROMOTE: ${{ steps.rc.outputs.promote }}+ RC_DIR: ${{ steps.rc.outputs.dir }}run: |+ set -euo pipefail# latest.json: version, pin, engine_id, the engine and app assets with SHA-256 and size, sources (this release's download URL),# built, channel stable. latest.json.sig: the Ed25519 signature over its exact bytes, made when ENGINE_SIGNING_KEY is set (without it# the tool prints a warning and uploads no signature). The zip goes first, the signature last.+ # A release candidate publishes the stable manifest of the release it is a candidate for: the same version, pin and engine_id.+ # Only its download URL (its own tag) differs. The final tag publishes the candidate's zips under its own tag.+ engine="$RUNNER_TEMP/engine-out/NX2Apple-engine.zip" app=frontend/NX2Apple-macOS-arm64.zip+ if [ "$PROMOTE" = true ]; then engine="$RC_DIR/NX2Apple-engine.zip" app="$RC_DIR/NX2Apple-macOS-arm64.zip"; fipython tools/release_manifest.py publish \- --engine-zip "$RUNNER_TEMP/engine-out/NX2Apple-engine.zip" --app-zip frontend/NX2Apple-macOS-arm64.zip \- --version "${{ steps.ver.outputs.version }}" --channel stable --tag "$GITHUB_REF_NAME" \+ --engine-zip "$engine" --app-zip "$app" \+ --version "$VERSION" --channel stable --tag "$GITHUB_REF_NAME" \--out "$RUNNER_TEMP/publish" --upload+ - name: Release candidate notes (the engine build it tests)+ if: steps.ver.outputs.kind == 'rc'+ shell: bash+ env:+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}+ VERSION: ${{ steps.ver.outputs.version }}+ RC: ${{ steps.ver.outputs.rc }}+ run: |+ set -euo pipefail+ # Read from the latest.json just published, so the notes name what the manifest names.+ m="$RUNNER_TEMP/publish/latest.json"+ signed="not signed (ENGINE_SIGNING_KEY is not set)"+ [ -f "$RUNNER_TEMP/publish/latest.json.sig" ] && signed="signed (latest.json.sig)"+ cat > "$RUNNER_TEMP/rc-notes.md" <<NOTES+ Release candidate $RC of NX2Apple $VERSION, built from commit $GITHUB_SHA. A pre-release: the app's update never offers it.++ The engine this build carries is the engine the release $VERSION will carry:++ - version: $(jq -r .version "$m"), channel $(jq -r .channel "$m")+ - pin: seedds/nxnative $(jq -r .pin "$m")+ - engine_id: \`$(jq -r .engine_id "$m")\`+ - NX2Apple-engine.zip SHA-256: \`$(jq -r .engine.sha256 "$m")\`+ - NX2Apple-macOS-arm64.zip SHA-256: \`$(jq -r .app.sha256 "$m")\`+ - latest.json: $signed++ Test the app against this engine_id: \`tools/try-pr $GITHUB_REF_NAME\` in a checkout, or the steps in RELEASING.md.+ When the test passes, the final tag v$VERSION goes on the same commit, and its release ships these files.+ NOTES+ gh release edit "$GITHUB_REF_NAME" --notes-file "$RUNNER_TEMP/rc-notes.md"+ cat "$RUNNER_TEMP/rc-notes.md"+- name: Engine publishing dry run (a throwaway key, nothing uploaded)if: ${{ !startsWith(github.ref, 'refs/tags/') }}shell: bashdiff --git a/AGENTS.md b/AGENTS.mdindex d370f8c9..8f3c195f 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -2,11 +2,11 @@This is the fork's guide. The engine has its own, upstream's: [engine/AGENTS.md](engine/AGENTS.md) (after `python3 tools/engine.py sync`, or [seedds/nxnative's AGENTS.md](https://github.com/seedds/nxnative/blob/main/AGENTS.md)). Read this file first, the engine's for any work in `engine/`.-- **Layout.** NX2Apple is the launcher and the glue around [seedds/nxnative](https://github.com/seedds/nxnative), which runs Nintendo Switch games natively on Apple platforms. This repository commits: `frontend/` (the Mac launcher, SwiftUI), `frontend-qt/` (the Qt front end), `frontend-ios/` (the iPhone shell), `tools/` (`engine.py`, `patches.py`, `release_manifest.py` and their tests), `patches/` (the series), `.upstream-ref` (the nxnative commit we build on), `.github/` (CI, forms, triage), the player and developer pages (`README*.md`, `GAMES*.md`, `BUILDING*.md`, `CONTRIBUTING*.md`, `CHANGELOG*.md`). The engine (`dm/`, `scripts/`, `docs/`, `ref/`) is **not** here: it is nxnative at the pin plus `patches/`, built into `engine/` by `python3 tools/engine.py sync`. `engine/` is a real git repository that this one ignores. A root `.ignore` keeps it visible to ripgrep.+- **Layout.** NX2Apple is the launcher and the glue around [seedds/nxnative](https://github.com/seedds/nxnative), which runs Nintendo Switch games natively on Apple platforms. This repository commits: `frontend/` (the Mac launcher, SwiftUI), `frontend-qt/` (the Qt front end), `frontend-ios/` (the iPhone shell), `tools/` (`engine.py`, `patches.py`, `release_manifest.py` and their tests, `try-pr`), `patches/` (the series), `.upstream-ref` (the nxnative commit we build on), `.github/` (CI, forms, triage), the player and developer pages (`README*.md`, `GAMES*.md`, `BUILDING*.md`, `CONTRIBUTING*.md`, `CHANGELOG*.md`, `RELEASING.md`). The engine (`dm/`, `scripts/`, `docs/`, `ref/`) is **not** here: it is nxnative at the pin plus `patches/`, built into `engine/` by `python3 tools/engine.py sync`. `engine/` is a real git repository that this one ignores. A root `.ignore` keeps it visible to ripgrep.- **Commit with your own git identity, never upstream's.** Use the identity configured for your clone, or your own name and email. `engine/AGENTS.md` ends with a `git -c user.name=seedds -c user.email=…` line because it is written for seedds/nxnative, where seedds is the maintainer. Do not copy it here: it makes fork commits, and the `From:` line of patches made with `tools/engine.py export`, show upstream's author. Commit only when asked.- **Here first, upstream in parallel.** A fix to the engine, to a game profile or to upstream's docs may land here first, as a patch. The same change goes to seedds/nxnative as a pull request in parallel, from a branch off their main (`git -C engine fetch seedds`, `engine/` has the remote). If you cannot open that pull request, a maintainer sends it. A patch here is a bridge until upstream has it, and the next bump drops it once the change is in. [patches/README.md](patches/README.md#here-first-upstream-in-parallel) has the rule and the `Upstream-Status` values.- **How a commit in `engine/` becomes a patch.** Work in `engine/` (it holds upstream's tree with our patches as commits on top): change, test, commit with a message that says what and why. `python3 tools/engine.py export` turns the commits made since the last sync into `patches/NNNN-*.patch` with the header `Upstream-Status`, `Reason` and `Issue` (fill them in, `--status`, `--reason` and `--issue` set them) and adds them to `patches/series`. `python3 tools/engine.py check` must pass (headers, no patch on the shader chain, the series applies to the pin). The same commit goes to seedds/nxnative as a pull request in parallel. The patch says `pending` until that pull request is open, then `forwarded seedds/nxnative#<n>`. Commit `patches/` in a PR here. `sync` never throws away work in `engine/`: it stops and names `export`.- **Never add engine files to this repository.** Files under `dm/`, `scripts/`, `docs/` and `ref/` at the root are ignored by `.gitignore`, and the `pr-scope` check fails a PR that adds them. A direct edit of engine files is lost on the next sync.-- **Issues and pull requests.** Follow [CONTRIBUTING.md](CONTRIBUTING.md), section "For AI agents and other tools", and the forms and the PR template in `.github/`. Fix or feature: every fix goes through a PR and merges when CI is green, unless a maintainer's "changes requested" review is unanswered (a plain review comment does not block, and Andy decides only when the maintainers disagree), a maintainer's own feature after 48 hours (a feature from outside never merges by waiting, a maintainer has to agree, try the app and review the code), a patch is renumbered by whoever merges it, releases and version bumps are the owner's. Never attach or commit keys, game files or data extracted from a game.+- **Issues and pull requests.** Follow [CONTRIBUTING.md](CONTRIBUTING.md), section "For AI agents and other tools", and the forms and the PR template in `.github/`. Fix or feature: every fix goes through a PR and merges when CI is green, unless a maintainer's "changes requested" review is unanswered (a plain review comment does not block, and @LNPANDY decides only when the maintainers disagree), a maintainer's own feature after 48 hours (a feature from outside never merges by waiting, a maintainer has to agree, try the app and review the code), a patch is renumbered by whoever merges it, releases and version bumps are the owner's ([RELEASING.md](RELEASING.md): a release candidate tag first, the final tag on its commit). `tools/try-pr <PR number|main|tag>` opens the app CI built. Never attach or commit keys, game files or data extracted from a game.- **Checks.** `cd frontend && swift build && swift test` for the Mac launcher (its tests read `engine/`, so sync first), `python3 -m unittest discover -s frontend-qt/tests` for the Qt front end (and `python3 frontend-qt/gen_localization.py` leaves `frontend-qt/nspb_qt/localization.py` unchanged), `python3 -m unittest discover tools/tests` for the tools. The engine's own tests run in `engine/` as `tests.yml` does.- **Language and text.** Everything is in English except the Chinese pages (`*.zh-CN.md`) and the launcher's strings. No semicolons in UI strings, READMEs and docs.diff --git a/RELEASING.md b/RELEASING.mdnew file mode 100644index 00000000..ed42eca6--- /dev/null+++ b/RELEASING.md@@ -0,0 +1,63 @@+# Releasing NX2Apple++A release starts as a release candidate. Players get the exact files of the candidate that was tested: the same app and the same engine.++## Release candidates++### Cutting a candidate++1. The version bump goes to `main` first: `static let appVersion` in `frontend/Sources/NSPortBuilder/ContentView.swift`, and the changelog.+2. Tag a commit on `main` as `vX.Y.Z-rcN`, with N from 1: `git tag v0.7.6-rc1 <commit> && git push origin v0.7.6-rc1`.++`build-mac-app.yml` checks that the tag without `-rcN` is `appVersion`. The app inside says `0.7.6`, not `0.7.6-rc1`. The final release ships this bundle, and the app's own update installs only a bundle whose version is the release's.++### What CI publishes++The tag gets a GitHub pre-release titled "NX2Apple 0.7.6 release candidate 1". It is never "latest", and the app's update reads only the latest release, so no player is offered it. It carries:++- `NX2Apple-macOS-arm64.zip` and the same app under its older names (`nxnative-`, `NS-Port-Builder-macOS-arm64.zip`)+- `NX2Apple-engine.zip`, the engine tree that is also inside the app (`Contents/Resources/engine`)+- `latest.json` and `latest.json.sig`, the signed manifest of the stable channel for version 0.7.6. Its version, pin and `engine_id` are the ones the final `latest.json` of 0.7.6 has. Only its download URL differs.++The release notes name the engine build: version, pin, `engine_id`, and the SHA-256 of the engine zip and of the app zip.++The candidate never touches the pre-release `engine-experimental`, which serves `main`.++A candidate is built once. A second run of the same tag fails once the app is uploaded, because a rebuild would not be the same bytes. A broken build or a fix is the next candidate, `rc2`.++### Testing a candidate++The test runs against the engine the release will serve, not against whatever an engine channel serves that day.++- In a checkout, `tools/try-pr v0.7.6-rc1` downloads the app, checks its SHA-256 and its bundled `engine_id` against the candidate's `latest.json`, and prints the `engine_id`. It opens the app with launch arguments that make it build with its bundled engine: the stable channel, that `engine_id`, and no automatic engine or app update. The arguments last for that run.+- By hand: download `NX2Apple-macOS-arm64.zip` from the pre-release and unzip it. `NX2Apple.app/Contents/Resources/engine/.engine-id` is the `engine_id` of the notes. Then run `open -n NX2Apple.app --args -engineChannel stable -engineID <engine_id> -autoUpdateRepo '<false/>' -autoUpdateApp '<false/>'`.+- Settings shows the engine's version and the first 8 characters of its `engine_id`. The diagnostics report shows `Engine: stable 0.7.6 (<engine_id>)`. Both must match the notes.+- Without the arguments the app follows the channel and engine saved in its settings. The experimental channel serves the engine of `main`.+- Test the whole app on a Mac, and build and install games for iPhone or iPad with it.++The test app has the bundle id of an installed NX2Apple (`org.nxnative.NSPortBuilder`). It shares its settings and `~/Library/Application Support` (`NS Port Builder`, `NX2Apple` with the engine store, `nxnative`). A setting changed in the test app stays changed. The test app saves its engine choice. An installed release app goes back to its own engine at its next start. If it followed the experimental channel, pick that again in Settings.++If something is broken, a fix or a revert goes to `main`, and the next candidate is tagged on the new commit.++## The final release++When a candidate passes, the final tag `vX.Y.Z` goes on the same commit: `git tag v0.7.6 <commit of v0.7.6-rc2>`.++The build of the final tag looks for the newest `v0.7.6-rcN` on its commit. It downloads that candidate's files and checks the signature of its `latest.json`. It then checks that the manifest names exactly those zips, and that the engine zip this commit builds holds the same files as the candidate's (the zip is reproducible, so normally it is the same bytes). The release then gets the candidate's app zips and engine zip unchanged, with a `latest.json` of its own (same `engine_id`, its own download URL). Any difference stops the release before anything is uploaded.++A final tag on a commit without a candidate fails. In an emergency, a manual run on the tag publishes it anyway: `gh workflow run build-mac-app.yml --ref v0.7.6 -f release_without_rc=true`. Nobody tested that build as a whole, and the release notes say so.++## Who tags++- Release candidates: LNPANDY or v0lumehi.+- Final releases: LNPANDY. If LNPANDY cannot be reached for 48 hours, v0lumehi tags the final from the tested candidate and leaves a note in the release notes or in an issue.+- A final tag always points at the commit of a tested candidate.++### The tag ruleset++Two tag rulesets in Settings → Rules → Rulesets:++- Target `v*`, rules "Restrict updates" and "Restrict deletions", bypass for the repository admin. A tested tag never moves.+- Target `v*`, excluding `v*-rc*`, rule "Restrict creations", bypass for the repository admin and the write role.++In a repository owned by a personal account, bypass goes by role, not by person. LNPANDY is the admin, v0lumehi has the write role. The second ruleset does not block v0lumehi, so the 48-hour fallback works. It stops workflows and apps from making a final tag. Who tags a final release is the agreement above.diff --git a/frontend/README.md b/frontend/README.mdindex 69de7149..04c651a2 100644--- a/frontend/README.md+++ b/frontend/README.md@@ -261,6 +261,10 @@ or double-click `nxnative.app` in this folder (ad-hoc signed, and rebuild it witand copy the binary into `Contents/MacOS/`). The app's settings and library stay under the folder name ithad before the rename, `~/Library/Application Support/NS Port Builder/`.+To try the app CI built for a pull request, for `main` or for a release candidate, without building it: `tools/try-pr 271`,+`tools/try-pr main` or `tools/try-pr v0.7.6-rc1` from the repository root. It opens the downloaded copy on the engine tree inside it.+That copy shares settings and Application Support with an installed NX2Apple. The top of `tools/try-pr` says what that means.+SwiftUI, macOS 13+.### Why the dependency check does not use `which`diff --git a/patches/README.md b/patches/README.mdindex 4476e9d9..c9d5e243 100644--- a/patches/README.md+++ b/patches/README.md@@ -106,7 +106,8 @@ the pin alone does not name a tree). The zip is deterministic (sorted, fixed tim`python3 tools/release_manifest.py publish ...` writes `latest.json` (version, pin, `engine_id`, channel, built, the engine and app assets withSHA-256 and size, sources) and, when a key is set, `latest.json.sig` (a detached Ed25519 signature over its exact bytes, base64). With `--upload` it puts`NX2Apple-engine.zip`, `latest.json` and `latest.json.sig` on a GitHub release. Without `--upload` it is a dry run.-`build-mac-app.yml` does this for a release tag (stable channel, the tree also goes into `Contents/Resources/engine`).+`build-mac-app.yml` does this for a release candidate tag `vX.Y.Z-rcN` and a release tag `vX.Y.Z` (stable channel, the tree also goes into `Contents/Resources/engine`).+A release tag ships the files of the release candidate on its commit, and `release_manifest.py check-rc` checks they are that build ([RELEASING.md](../RELEASING.md)).`sync-upstream.yml` does it for the pre-release tag `engine-experimental`.### Signing is optional for nowdiff --git a/tools/release_manifest.py b/tools/release_manifest.pyindex 60a46064..de371725 100755--- a/tools/release_manifest.py+++ b/tools/release_manifest.py@@ -31,6 +31,11 @@ Subcommands (Python 3.9+, `pip install -r tools/requirements-release.txt`):verify --manifest F [--sig F] [--pub FILE] [--require-signature]check a signature the way the launcher does. A missing signature file is accepted with a warning whileENGINE_SIGNING_KEY is not set, and is an error when the key is set or --require-signature is given+ check-rc --manifest F --version V --engine-zip Z --app-zip A --built-engine-zip B+ before a final tag ships the files of its release candidate (RELEASING.md): exit 0 only when the+ candidate's latest.json is the stable manifest of version V, names exactly the engine zip Z and the app zip A+ (SHA-256, size, pin, engine_id), and the engine zip B that the final tag's commit builds holds the same+ files as Z (the same bytes, or the same files compressed differently, which it notes)"""import argparseimport base64@@ -261,6 +266,57 @@ def cmd_verify(a):return 0 if ok else 1+def check_rc(manifest, version, engine_zip, app_zip, built_engine_zip):+ """The reasons the release candidate's files are not the release `version` (empty when they are)."""+ try: m = json.loads(Path(manifest).read_bytes())+ except (OSError, ValueError) as e: return [f'{manifest} is not readable JSON: {e}']+ bad = []+ if m.get('channel') != 'stable': bad.append(f'the candidate\'s manifest has channel {m.get("channel")!r}, not stable')+ if m.get('version') != version: bad.append(f'the candidate\'s manifest is for version {m.get("version")!r}, not {version!r}')+ for key, path in (('engine', engine_zip), ('app', app_zip)):+ want = m.get(key) or {}+ got = asset(path)+ for field in ('asset', 'sha256', 'size'):+ if want.get(field) != got[field]:+ bad.append(f'{key} {field}: the manifest says {want.get(field)!r}, the candidate\'s {Path(path).name} has {got[field]!r}')+ pin, eid = engine_identity(engine_zip)+ if (m.get('pin'), m.get('engine_id')) != (pin, eid):+ bad.append(f'the manifest names pin {m.get("pin")} engine_id {m.get("engine_id")}, the candidate\'s engine zip is {eid}')+ _, beid = engine_identity(built_engine_zip)+ if beid != eid:+ bad.append(f'this commit builds engine {beid}, the candidate carries {eid}')+ elif sha256_file(built_engine_zip) != sha256_file(engine_zip):+ # The zip is reproducible, so the bytes normally match. Another zlib on the runner could compress the same files differently:+ # that is still the tested engine (the release ships the candidate's zip in any case). Different files are not.+ diff = sorted(set(zip_files(built_engine_zip)) ^ set(zip_files(engine_zip)))+ if diff:+ names = sorted({n for n, _, _ in diff})+ bad.append(f'this commit builds an engine zip with other files than the candidate\'s: {", ".join(names[:5])}'+ + (f' and {len(names) - 5} more' if len(names) > 5 else ''))+ else:+ say(f'note: the engine zip this commit builds has the same files as the candidate\'s, compressed differently '+ f'(SHA-256 {sha256_file(built_engine_zip)}). The release ships the candidate\'s zip')+ return bad+++def zip_files(path):+ """Each file of a zip as (name, CRC-32, size): what it holds, whatever the compression."""+ with zipfile.ZipFile(path) as z:+ return [(i.filename, i.CRC, i.file_size) for i in z.infolist()]+++def cmd_check_rc(a):+ bad = check_rc(a.manifest, a.version, a.engine_zip, a.app_zip, a.built_engine_zip)+ for b in bad: say(f'::error title=Not the tested build::{b}' if os.environ.get('GITHUB_ACTIONS') == 'true' else f'error: {b}')+ if bad:+ say('the final release would not ship the build of its release candidate: nothing is published')+ return 1+ m = json.loads(Path(a.manifest).read_bytes())+ say(f'same build as the release candidate: {m["version"]} engine_id {m["engine_id"]}, engine SHA-256 {m["engine"]["sha256"]}, '+ f'app SHA-256 {m["app"]["sha256"]}')+ return 0++def cmd_keygen(a):ed, _ = ed25519()from cryptography.hazmat.primitives import serialization@@ -278,6 +334,9 @@ def main(argv=None):s = sub.add_parser('check-key'); s.add_argument('--pub', default=str(PUB_FILE)); s.set_defaults(f=cmd_check_key)s = sub.add_parser('verify'); s.add_argument('--manifest', required=True); s.add_argument('--sig', help='default: latest.json.sig next to the manifest'); s.add_argument('--pub', default=str(PUB_FILE))s.add_argument('--require-signature', action='store_true'); s.set_defaults(f=cmd_verify)+ s = sub.add_parser('check-rc')+ for o in ('--manifest', '--version', '--engine-zip', '--app-zip', '--built-engine-zip'): s.add_argument(o, required=True)+ s.set_defaults(f=cmd_check_rc)s = sub.add_parser('publish')s.add_argument('--engine-zip', required=True); s.add_argument('--app-zip'); s.add_argument('--version', required=True)s.add_argument('--channel', required=True, choices=('stable', 'experimental')); s.add_argument('--tag', required=True)diff --git a/tools/tests/test_release_manifest.py b/tools/tests/test_release_manifest.pyindex 3a26fd5e..05e31455 100644--- a/tools/tests/test_release_manifest.py+++ b/tools/tests/test_release_manifest.py@@ -308,5 +308,113 @@ class Unsigned(unittest.TestCase):self.assertEqual(R.main([*args, '--require-signature']), 1)+class ReleaseCandidate(unittest.TestCase):+ """A release candidate vX.Y.Z-rcN publishes the stable manifest of X.Y.Z on its pre-release, and the final tag ships its files only+ when `check-rc` finds them to be exactly what its latest.json names and what the final commit builds (RELEASING.md)."""+ def setUp(self):+ self.tmp = Path(tempfile.mkdtemp(prefix='test-manifest-rc-'))+ self.addCleanup(__import__('shutil').rmtree, self.tmp, True)+ self.pubfile = self.tmp / 'engine-signing.pub'+ self.pubfile.write_text('# no key yet\n')+ self.engine = self.zip('NX2Apple-engine.zip', EID)+ self.app = self.tmp / 'NX2Apple-macOS-arm64.zip'; self.app.write_bytes(b'app bytes')+ self.old_env = dict(os.environ)+ os.environ.pop(R.KEY_ENV, None); os.environ.pop('GITHUB_ACTIONS', None)+ self.addCleanup(self.restore)++ def restore(self):+ os.environ.clear(); os.environ.update(self.old_env)++ def zip(self, name, eid, extra='x', compression=zipfile.ZIP_STORED):+ p = self.tmp / name+ with zipfile.ZipFile(p, 'w') as z: # fixed timestamps, like `tools/engine.py tree`: the same input gives the same bytes+ for n, s in (('.engine-id', eid + '\n'), ('.upstream-ref', eid[:40] + '\n'), ('dm/a.c', extra * 200)):+ i = zipfile.ZipInfo(n, (1980, 1, 1, 0, 0, 0)); i.compress_type = compression+ z.writestr(i, s)+ return p++ def run_main(self, args):+ import contextlib, io+ buf = io.StringIO()+ with contextlib.redirect_stdout(buf): code = R.main(args)+ return code, buf.getvalue()++ def publish_rc(self, *extra, channel='stable', version='0.8.0', tag='v0.8.0-rc1'):+ out = self.tmp / 'rc'+ args = ['publish', '--engine-zip', str(self.engine), '--app-zip', str(self.app), '--version', version, '--channel', channel,+ '--tag', tag, '--out', str(out), '--pub', str(self.pubfile), '--built', '2026-10-31T02:00:00Z', *extra]+ self.assertEqual(self.run_main(args)[0], 0)+ return out / 'latest.json'++ def check(self, manifest, built=None, app=None, version='0.8.0'):+ return self.run_main(['check-rc', '--manifest', str(manifest), '--version', version, '--engine-zip', str(self.engine),+ '--app-zip', str(app or self.app), '--built-engine-zip', str(built or self.engine)])++ def test_the_candidate_manifest_is_the_stable_manifest_of_the_release_under_its_own_tag(self):+ m = json.loads(self.publish_rc().read_text())+ self.assertEqual((m['version'], m['channel'], m['pin'], m['engine_id']), ('0.8.0', 'stable', PIN, EID))+ self.assertEqual(m['sources'], ['https://github.com/LNPANDY/NX2Apple/releases/download/v0.8.0-rc1/'])+ final = self.tmp / 'final'+ self.run_main(['publish', '--engine-zip', str(self.engine), '--app-zip', str(self.app), '--version', '0.8.0', '--channel', 'stable',+ '--tag', 'v0.8.0', '--out', str(final), '--pub', str(self.pubfile), '--built', '2026-10-31T02:00:00Z'])+ f = json.loads((final / 'latest.json').read_text())+ self.assertEqual({k: v for k, v in f.items() if k != 'sources'}, {k: v for k, v in m.items() if k != 'sources'})++ def test_the_candidate_uploads_onto_its_prerelease_without_changing_it(self):+ d = self.tmp / 'bin'; d.mkdir()+ log = self.tmp / 'gh.log'+ (d / 'gh').write_text(f'#!/bin/sh\necho "$@" >> "{log}"\nexit 0\n'); (d / 'gh').chmod(0o755)+ os.environ['PATH'] = f'{d}:{os.environ["PATH"]}'+ self.publish_rc('--upload')+ calls = [l.split() for l in log.read_text().splitlines()]+ self.assertFalse([c for c in calls if c[:2] in (['release', 'create'], ['release', 'edit'])]) # stays a pre-release, never latest+ self.assertEqual({c[2] for c in calls if c[:2] == ['release', 'upload']}, {'v0.8.0-rc1'})+ self.assertNotIn(R.EXPERIMENTAL_TAG, log.read_text())++ def test_the_same_build_passes(self):+ built = self.zip('built-engine.zip', EID) # the engine zip is reproducible: the final commit builds the same bytes+ self.assertEqual(self.engine.read_bytes(), built.read_bytes())+ code, text = self.check(self.publish_rc(), built=built)+ self.assertEqual(code, 0, text); self.assertIn(f'engine_id {EID}', text)++ def test_another_engine_on_the_final_commit_fails(self):+ other = self.zip('built-engine.zip', PIN + '-000000000000')+ code, text = self.check(self.publish_rc(), built=other)+ self.assertEqual(code, 1); self.assertIn('this commit builds engine', text)++ def test_the_same_engine_id_with_other_files_fails(self):+ other = self.zip('built-engine.zip', EID, extra='y')+ code, text = self.check(self.publish_rc(), built=other)+ self.assertEqual(code, 1); self.assertIn('other files than the candidate\'s: dm/a.c', text)++ def test_the_same_files_compressed_differently_pass_with_a_note(self):+ other = self.zip('built-engine.zip', EID, compression=zipfile.ZIP_DEFLATED)+ self.assertNotEqual(other.read_bytes(), self.engine.read_bytes())+ code, text = self.check(self.publish_rc(), built=other)+ self.assertEqual(code, 0, text); self.assertIn('compressed differently', text)++ def test_an_app_that_is_not_the_one_in_the_manifest_fails(self):+ m = self.publish_rc()+ other = self.tmp / 'other' / 'NX2Apple-macOS-arm64.zip'; other.parent.mkdir(); other.write_bytes(b'rebuilt app')+ code, text = self.check(m, app=other)+ self.assertEqual(code, 1); self.assertIn('app sha256', text)++ def test_an_engine_zip_that_is_not_the_one_in_the_manifest_fails(self):+ m = self.publish_rc()+ self.engine = self.zip('NX2Apple-engine.zip', EID, extra='swapped')+ code, text = self.check(m, built=self.engine)+ self.assertEqual(code, 1); self.assertIn('engine sha256', text)++ def test_a_manifest_for_another_version_or_channel_fails(self):+ self.assertEqual(self.check(self.publish_rc(), version='0.8.1')[0], 1)+ code, text = self.check(self.publish_rc(channel='experimental'))+ self.assertEqual(code, 1); self.assertIn('not stable', text)++ def test_in_ci_a_difference_is_an_error_annotation(self):+ os.environ['GITHUB_ACTIONS'] = 'true'+ code, text = self.check(self.publish_rc(), built=self.zip('built-engine.zip', PIN + '-000000000000'))+ self.assertEqual(code, 1); self.assertIn('::error title=Not the tested build::', text)++if __name__ == '__main__':unittest.main()diff --git a/tools/try-pr b/tools/try-prnew file mode 100755index 00000000..e277d065--- /dev/null+++ b/tools/try-pr@@ -0,0 +1,198 @@+#!/usr/bin/env bash+# Open the Mac app that CI built, without building it yourself (RELEASING.md).+#+# tools/try-pr 271 the app of pull request #271 (the newest successful build of its head commit, fork pull requests too)+# tools/try-pr main the app of main (the newest successful build of a push to main)+# tools/try-pr v0.7.6-rc1 the app of a release candidate or release, checked against the latest.json of that release+#+# Options:+# --dir DIR put the download into DIR (empty or new). Default: a new folder under $TMPDIR+# --no-open download and unpack only+# --own-repo let the app choose its engine as it always does, instead of the engine tree bundled in this build+#+# Needs gh (signed in) on an Apple silicon Mac. The app comes from the artifact NX2Apple-macOS-arm64 of the workflow+# build-mac-app.yml, or from the release assets for a tag. The download is unpacked into its own folder, the quarantine flag is+# removed from that copy only, and the installed NX2Apple is not touched.+#+# The app opens with launch arguments that last for this run only. They make it build with the engine tree it carries+# (Contents/Resources/engine), whatever the channels serve that day:+# -engineChannel stable -engineID <its engine_id> the stable channel and the bundled engine, which the app copies into its+# engine store (~/Library/Application Support/NX2Apple/engine) if needed+# -enginePreviousID <your engine_id> the engine your installed app uses stays in the store+# -autoUpdateRepo '<false/>' no engine download and no git pull at launch+# -autoUpdateApp '<false/>' no self-update of the test copy+# A build from before the engine store (v0.7.5 and older) gets -repoPath <DIR>/engine instead of the engine arguments: a copy+# of its bundled tree, which it builds from instead of your checkout.+#+# The test app has the bundle id of the installed app (org.nxnative.NSPortBuilder). It shares its settings, and+# ~/Library/Application Support/NS Port Builder (Python environment, game library), .../NX2Apple (engine store) and .../nxnative+# (saves). The app has no switch to keep these apart. A setting you change in the test app stays changed for the installed app.+# The test app also saves its engine choice (stable, its engine) and its engine folder as the repository path. The installed+# release app goes back to its own engine at its next start. If it followed the experimental channel, pick that again in+# Settings. A launcher built from a checkout may need its checkout picked again.+set -euo pipefail++REPO=${NX2APPLE_REPO:-LNPANDY/NX2Apple}+WORKFLOW=build-mac-app.yml+ARTIFACT=NX2Apple-macOS-arm64++usage() { sed -n '2,12p' "$0" | sed 's/^# \{0,1\}//'; exit "${1:-0}"; }+die() { echo "try-pr: $*" >&2; exit 1; }+note() { echo "try-pr: $*"; }++# The network is not always there: three tries, then the error of the last one.+retry() {+ local n=1+ until "$@"; do+ [ "$n" -ge 3 ] && return 1+ sleep $((n * 3)); n=$((n + 1))+ done+}++target="" dir="" open_app=1 own_repo=0+while [ $# -gt 0 ]; do+ case "$1" in+ -h|--help) usage 0 ;;+ --dir) [ $# -ge 2 ] || usage 1; dir=$2; shift ;;+ --no-open) open_app=0 ;;+ --own-repo) own_repo=1 ;;+ -*) usage 1 ;;+ *) [ -z "$target" ] || usage 1; target=$1 ;;+ esac+ shift+done+[ -n "$target" ] || usage 1+command -v gh > /dev/null || die "needs the GitHub CLI: brew install gh, then gh auth login"+case "$target" in '#'*) target=${target#\#} ;; esac+case "$target" in+ main|v[0-9]*) ;;+ *[!0-9]*|'') die "expected a pull request number, main, or a tag like v0.7.6-rc1, not '$target'" ;;+esac++if [ -z "$dir" ]; then+ dir=$(mktemp -d "${TMPDIR:-/tmp}/nx2apple-try.XXXXXX")+else+ mkdir -p "$dir"+ [ -z "$(ls -A "$dir")" ] || die "$dir is not empty"+fi+dir=$(cd "$dir" && pwd)+# Nothing to try: leave no half download behind.+trap 'status=$?; [ "$status" = 0 ] || rm -rf "$dir"' EXIT+mkdir -p "$dir/download"++# The run whose artifact to take: "<id> <head sha>", or a message why there is none.+pick_run() { # $1: the head commit, $2: what it is (for messages)+ local runs ok first+ runs=$(retry gh api "repos/$REPO/actions/workflows/$WORKFLOW/runs?head_sha=$1&per_page=30" \+ --jq '.workflow_runs[] | [.id, .status, (.conclusion // "-"), .html_url] | @tsv') || die "could not list the builds of $1"+ ok=$(printf '%s\n' "$runs" | awk -F'\t' '$2 == "completed" && $3 == "success" { print $1; exit }')+ if [ -n "$ok" ]; then echo "$ok"; return; fi+ first=$(printf '%s\n' "$runs" | head -n 1)+ [ -n "$first" ] || die "$2 (${1:0:12}) has no app build. CI builds the app only when a change touches frontend/, patches/, tools/engine.py,+tools/release_manifest.py, tools/requirements-release.txt, .upstream-ref or build-mac-app.yml. tools/try-pr main has the app of main."+ IFS=$'\t' read -r _ status conclusion url <<< "$first"+ case "$status/$conclusion" in+ completed/action_required) die "the build of $2 waits for a maintainer to approve the workflow run (a fork pull request): $url" ;;+ completed/*) die "the newest build of $2 ended with '$conclusion', there is no app to try: $url" ;;+ *) die "the build of $2 is still running ($status). Try again when it is done: $url" ;;+ esac+}++fetch_artifact() { # $1: run id+ local state+ state=$(retry gh api "repos/$REPO/actions/runs/$1/artifacts" \+ --jq ".artifacts[] | select(.name == \"$ARTIFACT\") | if .expired then \"expired\" else \"ok\" end") || die "could not list the artifacts of run $1"+ case "$state" in+ ok) ;;+ expired) die "the app of run $1 has expired (GitHub keeps artifacts for a limited time). Re-run the build, or try a newer commit" ;;+ *) die "run $1 has no artifact $ARTIFACT" ;;+ esac+ note "downloading $ARTIFACT of https://github.com/$REPO/actions/runs/$1"+ retry gh run download "$1" -R "$REPO" -n "$ARTIFACT" -D "$dir/download" || die "the download failed"+}++manifest=""+case "$target" in+ main)+ head=$(retry gh api "repos/$REPO/commits/main" --jq .sha) || die "could not read main of $REPO"+ line=$(retry gh api "repos/$REPO/actions/workflows/$WORKFLOW/runs?branch=main&event=push&status=success&per_page=1" \+ --jq '.workflow_runs[0] | "\(.id) \(.head_sha)"') || die "could not list the builds of main"+ [ -n "$line" ] && [ "$line" != "null null" ] || die "main has no successful app build yet"+ run=${line% *} sha=${line#* }+ if [ "$sha" != "$head" ]; then+ note "the newest app of main is from ${sha:0:12}. main is at ${head:0:12}: the commits after it do not touch the app, or their build has not finished"+ fi+ fetch_artifact "$run"+ what="main at ${sha:0:12}"+ ;;+ v[0-9]*)+ info=$(retry gh release view "$target" -R "$REPO" --json isPrerelease,assets --jq '"\(.isPrerelease) \([.assets[].name] | join(","))"') \+ || die "$REPO has no release $target"+ case ",${info#* }," in *",$ARTIFACT.zip,"*) ;; *) die "$target has no $ARTIFACT.zip yet: its build is still running or failed (gh run list -R $REPO -w $WORKFLOW)" ;; esac+ note "downloading $ARTIFACT.zip of $target"+ retry gh release download "$target" -R "$REPO" -p "$ARTIFACT.zip" -D "$dir/download" || die "the download failed"+ case ",${info#* }," in+ *",latest.json,"*)+ retry gh release download "$target" -R "$REPO" -p latest.json -D "$dir/download" || die "the download of latest.json failed"+ manifest="$dir/download/latest.json" ;;+ *) note "$target has no latest.json: the engine of this build cannot be checked against it" ;;+ esac+ what="$target"; [ "${info%% *}" = true ] && what="$target (pre-release)"+ ;;+ *)+ head=$(retry gh pr view "$target" -R "$REPO" --json headRefOid --jq .headRefOid) || die "$REPO has no pull request #$target"+ run=$(pick_run "$head" "pull request #$target")+ fetch_artifact "$run"+ what="pull request #$target at ${head:0:12}"+ ;;+esac++zip="$dir/download/$ARTIFACT.zip"+[ -f "$zip" ] || die "the download has no $ARTIFACT.zip"+if [ -n "$manifest" ]; then+ want=$(plutil -extract app.sha256 raw -o - "$manifest" 2> /dev/null || true)+ got=$(shasum -a 256 "$zip" | cut -d' ' -f1)+ [ -z "$want" ] || [ "$want" = "$got" ] || die "$ARTIFACT.zip has SHA-256 $got, latest.json names $want"+fi+ditto -x -k "$zip" "$dir"+app="$dir/NX2Apple.app"+[ -d "$app" ] || die "the zip has no NX2Apple.app"+xattr -dr com.apple.quarantine "$app" 2> /dev/null || true++version=$(plutil -extract CFBundleShortVersionString raw -o - "$app/Contents/Info.plist" 2> /dev/null || echo "?")+bundled="$app/Contents/Resources/engine"+engine_id=$(cat "$bundled/.engine-id" 2> /dev/null || echo "none")+note "NX2Apple $version, $what"+note "engine_id $engine_id (Contents/Resources/engine)"+if [ -n "$manifest" ]; then+ want=$(plutil -extract engine_id raw -o - "$manifest")+ [ "$engine_id" = "$want" ] || die "the app carries engine $engine_id, latest.json of $target names $want"+ note "the app and its engine are the ones latest.json of $target names (channel $(plutil -extract channel raw -o - "$manifest"), engine SHA-256 $(plutil -extract engine.sha256 raw -o - "$manifest"))"+fi++args=(-autoUpdateApp '<false/>')+if [ "$own_repo" = 0 ]; then+ [ -d "$bundled" ] || die "this build has no Contents/Resources/engine. Use --own-repo to let the app choose its engine"+ if grep -qa engineChannel "$app/Contents/MacOS/NSPortBuilder"; then+ args+=(-engineChannel stable -engineID "$engine_id" -autoUpdateRepo '<false/>')+ mine=$(defaults read org.nxnative.NSPortBuilder engineID 2> /dev/null || true)+ if [ -n "$mine" ] && [ "$mine" != "$engine_id" ]; then args+=(-enginePreviousID "$mine"); fi+ if [ "$(defaults read org.nxnative.NSPortBuilder engineChannel 2> /dev/null || true)" = experimental ]; then+ note "your installed app follows the experimental channel. The test app saves stable: pick experimental again in Settings afterwards"+ fi+ else+ ditto "$bundled" "$dir/engine"+ args+=(-repoPath "$dir/engine" -autoUpdateRepo '<false/>')+ fi+fi++note "unpacked into $dir (delete it when you are done)"+if [ "$open_app" = 0 ]; then+ note "not opened (--no-open). To open it: open -n $(printf '%q' "$app") --args$(printf ' %q' "${args[@]}")"+ exit 0+fi+if pgrep -x NSPortBuilder > /dev/null; then+ die "NX2Apple is running. Quit it first: both copies would share one set of settings and saves"+fi+note "it shares settings and Application Support with an installed NX2Apple (see the top of tools/try-pr)"+open -n "$app" --args "${args[@]}"