Skip to content

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

Engine publishing: signature optional for now, experimental channel only from main

v0lumehi5864dd3e53ca
diff --git a/.github/workflows/build-mac-app.yml b/.github/workflows/build-mac-app.yml
index 4d833422..297d2771 100644
--- a/.github/workflows/build-mac-app.yml
+++ b/.github/workflows/build-mac-app.yml
@@ -11,9 +11,11 @@
# The app carries the engine (issues #214 and #227): `tools/engine.py tree` builds the engine tree (seedds/nxnative at the pin plus the patch
# series, no git history) into Contents/Resources/engine, and the launcher copies it to Application Support on first use. The same tree goes up
# as a release asset (NX2Apple-engine.zip) together with latest.json and its Ed25519 signature latest.json.sig (tools/release_manifest.py), which
-# is what the launcher reads to update the engine without an app release. The signing key is the repository secret ENGINE_SIGNING_KEY: a tag build
-# fails at its first step when the secret is missing or is not the key in frontend/engine-signing.pub (compiled into the launcher). Other builds
-# run the same steps as a dry run with a throwaway key and upload nothing. It also carries its build tools (zstd, glslangValidator, spirv-cross, xcodegen) and a Python with the packages the build scripts import,
+# is what the launcher reads to update the engine without an app release. The signing key is the repository secret ENGINE_SIGNING_KEY and it is
+# optional for now: when it is set, the engine is signed, and a tag build fails at its first step when the key is not the one in
+# frontend/engine-signing.pub (compiled into the launcher). When it is not set, a tag build publishes without latest.json.sig and prints a warning.
+# Signing becomes mandatory before any download source other than GitHub is added (LNPANDY/NX2Apple#268, Cloudflare R2).
+# Other builds run the same steps as a dry run with a throwaway key and upload nothing. It also carries its build tools (zstd, glslangValidator, spirv-cross, xcodegen) and a Python with the packages the build scripts import,
# 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).
#
@@ -44,13 +46,14 @@ jobs:
- name: Install the signing tool's package
run: python -m pip install -r tools/requirements-release.txt
- - name: Signing key (a release without a matching key must not ship)
+ - name: Signing key (a warning without one, a failure with a key that does not match)
if: startsWith(github.ref, 'refs/tags/')
env:
ENGINE_SIGNING_KEY: ${{ secrets.ENGINE_SIGNING_KEY }}
run: |
- # Fails when the secret is missing, or when its public key is not the one in frontend/engine-signing.pub, the value the launcher
- # compiles in (EngineManifest.verify): a manifest signed with any other key would be rejected by every installed app.
+ # Warns when the secret is not set (the release then goes out unsigned). Fails when it is set and its public key is not the one in
+ # frontend/engine-signing.pub, the value the launcher compiles in (EngineManifest.verify): a manifest signed with any other key
+ # would be rejected by every installed app.
python tools/release_manifest.py check-key --pub frontend/engine-signing.pub
- name: Engine tree (tools/engine.py tree)
@@ -205,7 +208,8 @@ jobs:
ENGINE_SIGNING_KEY: ${{ secrets.ENGINE_SIGNING_KEY }}
run: |
# 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. The zip goes first, the signature last.
+ # 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.
python 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" \
diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml
index 09c1f6d3..e06140c8 100644
--- a/.github/workflows/sync-upstream.yml
+++ b/.github/workflows/sync-upstream.yml
@@ -11,12 +11,16 @@
# runs the checks itself before it opens the PR. A repository secret SYNC_TOKEN (a fine-grained token
# with contents, pull requests and issues write) makes the PR start tests.yml as well.
#
-# The experimental engine channel (LNPANDY/NX2Apple#227): after the sync job passed its checks (the series applies, the tests, the host build)
-# the publish-experimental job builds the engine tree of the bumped branch (tools/engine.py tree), writes latest.json with channel
-# "experimental" and "built", signs it with the repository secret ENGINE_SIGNING_KEY (tools/release_manifest.py) and replaces the assets
+# The experimental engine channel (LNPANDY/NX2Apple#227): it is built and published from main only, and only after the nightly bump of the sync
+# job went green (the pin moved and every check passed, or upstream had nothing new). The publish-experimental job runs only on the ref
+# refs/heads/main, so a manual run on a pull request branch or any other ref never builds it and never sees the signing key. It builds
+# the engine tree of main (tools/engine.py tree), writes latest.json with channel "experimental" and "built", and replaces the assets
# (NX2Apple-engine.zip, latest.json, latest.json.sig) of the pre-release tag engine-experimental, which it creates when missing and keeps a
-# pre-release that is never "latest". A workflow artifact cannot serve: the launcher has no token. It only publishes after a green sync job,
-# and its failure (a missing or wrong key) never opens the "sync blocked" issue. `force_experimental` publishes main's engine by hand.
+# pre-release that is never "latest". A workflow artifact cannot serve: the launcher has no token. An engine that is already published
+# is not uploaded again. The bump itself is a pull request: its engine reaches this channel after it is merged.
+# The repository secret ENGINE_SIGNING_KEY is optional for now: with it latest.json.sig is made, without it the engine goes out unsigned and
+# the log says so. Signing becomes mandatory before any download source other than GitHub is added (LNPANDY/NX2Apple#268, Cloudflare R2).
+# A failure of the publish job (a wrong key) never opens the "sync blocked" issue.
name: Sync upstream
on:
@@ -25,7 +29,7 @@ on:
workflow_dispatch:
inputs:
force_experimental:
- description: "Also publish the engine of main to the engine-experimental tag (the first time, or after the tag was removed)"
+ description: "Publish the engine of main to the engine-experimental tag even when that engine is already there (a run on main only)"
type: boolean
default: false
@@ -38,7 +42,7 @@ jobs:
sync:
runs-on: macos-latest # the host build needs clang + macOS headers
outputs:
- branch: ${{ steps.pr.outputs.branch }} # the pushed sync branch, empty when nothing changed
+ bump: ${{ steps.bump.outputs.changed }} # yes (a PR was opened), no (already at upstream), conflict
env:
GH_TOKEN: ${{ secrets.SYNC_TOKEN || secrets.GITHUB_TOKEN }}
steps:
@@ -131,10 +135,14 @@ jobs:
fi
publish-experimental:
- # Only after a green sync job (its checks are the "CI is green" of this channel). Separate from it so that a publishing problem
- # (no key, no release permission) does not read as a blocked sync above.
+ # Main only, and only after a green bump. The ref test is what keeps a run on another ref (a manual run on a pull request branch) from
+ # building and publishing: the job then never starts. Separate from the sync job so that a publishing problem (a wrong key, no release
+ # permission) does not read as a blocked sync above.
needs: sync
- if: needs.sync.result == 'success' && (needs.sync.outputs.branch != '' || inputs.force_experimental)
+ if: >-
+ github.ref == 'refs/heads/main' &&
+ needs.sync.result == 'success' &&
+ (needs.sync.outputs.bump == 'yes' || needs.sync.outputs.bump == 'no')
runs-on: ubuntu-latest
timeout-minutes: 20
concurrency: engine-experimental # two runs must not replace the assets at the same time
@@ -147,18 +155,17 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
- ref: ${{ needs.sync.outputs.branch || github.event.repository.default_branch }}
+ ref: ${{ github.sha }} # the main commit this run started on, never a sync branch
persist-credentials: false
- uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
with:
python-version: '3.14'
- run: python -m pip install -r tools/requirements-release.txt
- - name: Signing key (fails when the secret is missing or is not the key in frontend/engine-signing.pub)
+ - name: Signing key (a warning when the secret is not set, a failure when it is not the key in frontend/engine-signing.pub)
run: python tools/release_manifest.py check-key --pub frontend/engine-signing.pub
- - name: "Main's tests must be green (a bump branch was just checked, a hand-started publish of main was not)"
- if: needs.sync.outputs.branch == ''
+ - name: "Main's tests must be green"
run: |
c=$(gh run list -R "${{ github.repository }}" --workflow tests.yml --branch "${{ github.event.repository.default_branch }}" --event push --limit 1 --json conclusion --jq '.[0].conclusion')
echo "latest tests.yml on main: ${c:-none}"
@@ -169,7 +176,19 @@ jobs:
python tools/engine.py sync
python tools/engine.py tree --out "$RUNNER_TEMP/engine-tree" --zip "$RUNNER_TEMP/engine-out/NX2Apple-engine.zip"
+ - name: Is this engine already published?
+ id: published
+ run: |
+ new=$(cat "$RUNNER_TEMP/engine-tree/.engine-id")
+ old=$(gh release download engine-experimental -R "${{ github.repository }}" -p latest.json -O - 2> /dev/null | python -c 'import json, sys; print(json.load(sys.stdin).get("engine_id", ""))' 2> /dev/null || true)
+ echo "published: ${old:-none}, main: $new"
+ if [ "$new" = "$old" ] && [ "${{ inputs.force_experimental }}" != "true" ]; then
+ echo "same=yes" >> "$GITHUB_OUTPUT"
+ echo "Already published: nothing to upload."
+ fi
+
- name: Publish to the engine-experimental pre-release
+ if: steps.published.outputs.same != 'yes'
run: |
APPV=$(sed -n 's/.*static let appVersion = "\(.*\)".*/\1/p' frontend/Sources/NSPortBuilder/ContentView.swift)
python tools/release_manifest.py publish \
diff --git a/frontend/engine-signing.pub b/frontend/engine-signing.pub
index 72b5ab9b..fea65b21 100644
--- a/frontend/engine-signing.pub
+++ b/frontend/engine-signing.pub
@@ -1,3 +1,4 @@
# The public half of the key that signs latest.json (Ed25519, base64 of the 32 raw bytes), one line below. Empty until the key exists.
# The launcher (EngineManifest.verify's publicKey) compiles in the same value, and the release workflow fails when the repository
-# secret ENGINE_SIGNING_KEY does not belong to it (tools/release_manifest.py check-key). Lines starting with # are comments.
+# secret ENGINE_SIGNING_KEY is set and does not belong to it (tools/release_manifest.py check-key). Without the secret the engine is
+# published unsigned for now. Lines starting with # are comments.
diff --git a/patches/README.md b/patches/README.md
index 69803617..6b1f7c3f 100644
--- a/patches/README.md
+++ b/patches/README.md
@@ -115,11 +115,26 @@ a synced `engine/` (`dm/`, `scripts/`, `docs/`, `ref/`, `AGENTS.md`, `LICENSE`,
the pin alone does not name a tree). The zip is deterministic (sorted, fixed timestamps), so its SHA-256 is reproducible.
`python3 tools/release_manifest.py publish ...` writes `latest.json` (version, pin, `engine_id`, channel, built, the engine and app assets with
-SHA-256 and size, sources) and `latest.json.sig` (a detached Ed25519 signature over its exact bytes, base64), and with `--upload` puts
-`NX2Apple-engine.zip`, `latest.json` and `latest.json.sig` on a GitHub release. Without `--upload` it is a dry run. The key is the repository
-secret `ENGINE_SIGNING_KEY` (base64 of the 32 raw private bytes), checked against `frontend/engine-signing.pub`, which the launcher compiles in
-(`python3 tools/release_manifest.py keygen` makes a pair). `build-mac-app.yml` does this for a release tag (stable channel, the tree also goes
-into `Contents/Resources/engine`), `sync-upstream.yml` for the pre-release tag `engine-experimental` after a green nightly bump.
+SHA-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`).
+`sync-upstream.yml` does it for the pre-release tag `engine-experimental`.
+
+### Signing is optional for now
+
+The key is the repository secret `ENGINE_SIGNING_KEY` (base64 of the 32 raw private bytes). `python3 tools/release_manifest.py keygen` makes a pair.
+Its public half is `frontend/engine-signing.pub`, which the launcher compiles in.
+- With the secret set, `publish` signs and verifies the result. A key that does not belong to `frontend/engine-signing.pub` stops the release.
+- Without the secret, `publish` writes and uploads `latest.json` without a signature and prints a warning, a workflow annotation in CI. A `latest.json.sig` left on the release by an earlier signed run is removed, because it would not match the new manifest.
+- `python3 tools/release_manifest.py verify --manifest latest.json` checks a signature the way the launcher does. A missing `latest.json.sig` passes with a warning while the secret is not set, and fails when the secret is set or `--require-signature` is given.
+- Signing becomes mandatory before any download source other than GitHub is added (#268, Cloudflare R2). `publish --source` already refuses to run without a key.
+
+### The experimental channel
+
+The pre-release `engine-experimental` is built and published from `main` only, by the `publish-experimental` job of `sync-upstream.yml`.
+The job starts only on the ref `refs/heads/main` and only when the sync job of the nightly run succeeded with a green bump.
+It builds the engine of `main` and uploads it when its `engine_id` is not the one already published. A bump reaches the channel once its pull request is merged.
+A run on a pull request branch or any other ref never starts the job. The `force_experimental` input of a manual run on `main` uploads again even when the `engine_id` is the same.
Locally: `python3 tools/engine.py sync`, then `tree --out /tmp/t --zip /tmp/e/NX2Apple-engine.zip`, then `publish --engine-zip /tmp/e/NX2Apple-engine.zip
--version 0.0.0 --channel experimental --tag engine-experimental --out /tmp/p --ephemeral-key` runs every step except the upload.
diff --git a/tools/release_manifest.py b/tools/release_manifest.py
index 9904b784..60a46064 100755
--- a/tools/release_manifest.py
+++ b/tools/release_manifest.py
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
-"""latest.json for the engine, signed (LNPANDY/NX2Apple#227): what the launcher reads to update the engine without an app release.
+"""latest.json for the engine, signed when a key is set (LNPANDY/NX2Apple#227): what the launcher reads to update the engine without an app release.
The manifest has the shape of EngineManifest.Manifest (frontend/Sources/NSPortBuilder/EngineManifest.swift), plus `engine_id`:
@@ -13,18 +13,24 @@ The manifest has the shape of EngineManifest.Manifest (frontend/Sources/NSPortBu
manifest cannot disagree with the asset it describes. The signature is a detached Ed25519 signature over the exact bytes of
latest.json, base64, in latest.json.sig next to it (EngineManifest.verify(manifest:signature:publicKey:)).
-The private key is the repository secret ENGINE_SIGNING_KEY: base64 of the 32 raw bytes. Its public key must equal the one in
-frontend/engine-signing.pub, which the launcher compiles in. `check-key` fails when the secret is missing or belongs to another key,
-so a release can never ship with signing off or with a key the launcher does not trust.
+The private key is the repository secret ENGINE_SIGNING_KEY: base64 of the 32 raw bytes. Signing is optional for now. When the secret is
+set, `publish` signs, and its public key must equal the one in frontend/engine-signing.pub, which the launcher compiles in: a key that
+does not belong to that file stops the release. When the secret is not set, `publish` writes and uploads latest.json without a signature
+and prints a warning (a GitHub annotation in CI). Signing becomes mandatory before any download source other than GitHub is added
+(LNPANDY/NX2Apple#268, Cloudflare R2): `publish --source` already refuses to run without a key.
Subcommands (Python 3.9+, `pip install -r tools/requirements-release.txt`):
keygen print a new key pair (private base64 for the secret, public base64 for engine-signing.pub)
- check-key [--pub FILE] exit 0 when $ENGINE_SIGNING_KEY is set and matches the public key file
+ check-key [--pub FILE] exit 0 when $ENGINE_SIGNING_KEY is unset (warning: releases go out unsigned) or set and matching the
+ public key file, exit 2 when it is set and malformed or not the key of the file
publish --engine-zip Z --version V --channel stable|experimental --tag T --out DIR [--app-zip A] [--upload]
- write latest.json and latest.json.sig (and copies of the zips) to DIR and verify them. With --upload,
- put the zip, latest.json and latest.json.sig on the GitHub release TAG (gh). Without it nothing is
- uploaded: that is the dry run. --ephemeral-key signs with a throwaway key (dry runs only, never uploads)
- verify --manifest F --sig F [--pub FILE] check a signature the way the launcher does
+ write latest.json and, when a key is set, latest.json.sig (and copies of the zips) to DIR and verify them. With --upload,
+ put the zip, latest.json and (when signed) latest.json.sig on the GitHub release TAG (gh). Without it
+ nothing is uploaded: that is the dry run. --ephemeral-key signs with a throwaway key (dry runs only,
+ never uploads)
+ 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 while
+ ENGINE_SIGNING_KEY is not set, and is an error when the key is set or --require-signature is given
"""
import argparse
import base64
@@ -57,6 +63,17 @@ def say(*a):
print(*a, flush=True)
+def warn(msg):
+ """A warning that stands out in the CI log (a workflow annotation) and reads fine in a terminal."""
+ if os.environ.get('GITHUB_ACTIONS') == 'true': print(f'::warning title=Engine is not signed::{msg}', flush=True)
+ else: print(f'WARNING: {msg}', flush=True)
+
+
+def unsigned_warning():
+ warn(f'{KEY_ENV} is not set, so latest.json is published without a signature. Signing becomes mandatory before any download '
+ f'source other than GitHub is added (LNPANDY/NX2Apple#268).')
+
+
def ed25519():
try:
from cryptography.hazmat.primitives.asymmetric import ed25519
@@ -97,13 +114,14 @@ def read_pub(path):
def signing_key(pub_file, ephemeral=False):
- """The private key to sign with, after checking it belongs to the committed public key. (key, its public base64)."""
+ """The private key to sign with, after checking it belongs to the committed public key: (key, its public base64).
+ (None, None) when signing is off, which is when the secret is not set."""
if ephemeral:
ed, _ = ed25519()
k = ed.Ed25519PrivateKey.generate()
return k, public_b64(k)
secret = os.environ.get(KEY_ENV, '').strip()
- if not secret: raise Fail(f'the repository secret {KEY_ENV} is not set: a release must be signed')
+ if not secret: return None, None
key = private_key(secret)
want = read_pub(pub_file)
have = public_b64(key)
@@ -171,7 +189,8 @@ def gh(*a, check=True):
def upload(files, tag, repo, channel, notes):
- """Engine zip first, the manifest and its signature last, so a launcher that reads the new manifest finds its zip."""
+ """Engine zip first, the manifest and its signature last, so a launcher that reads the new manifest finds its zip.
+ Without a signature among the files, an older latest.json.sig on the release is removed first: it would not match the new manifest."""
exists = gh('release', 'view', tag, '-R', repo, check=False).returncode == 0
if channel == 'experimental':
# A pre-release under a fixed tag, never "latest", so it never becomes what the app's own update looks at.
@@ -179,6 +198,8 @@ def upload(files, tag, repo, channel, notes):
else: gh('release', 'create', tag, '-R', repo, '--prerelease', '--latest=false', '--title', 'Engine (experimental)', '--notes', notes)
elif not exists:
raise Fail(f'the release {tag} does not exist: the release workflow creates it before it publishes the engine')
+ if SIGNATURE not in [Path(f).name for f in files]:
+ gh('release', 'delete-asset', tag, SIGNATURE, '-R', repo, '--yes', check=False)
for f in files:
gh('release', 'upload', tag, str(f), '-R', repo, '--clobber')
say(f'uploaded {Path(f).name} to {repo} {tag}')
@@ -187,17 +208,26 @@ def upload(files, tag, repo, channel, notes):
def cmd_publish(a):
if a.upload and a.ephemeral_key: raise Fail('--ephemeral-key signs with a throwaway key: it never uploads')
key, pub = signing_key(a.pub, a.ephemeral_key)
+ if key is None and a.source:
+ raise Fail(f'--source adds a download source other than GitHub, which needs a signature: set {KEY_ENV}')
out = Path(a.out)
out.mkdir(parents=True, exist_ok=True)
zsrc = Path(a.engine_zip)
data = build_manifest(zsrc, a.version, a.channel, a.tag, a.app_zip, a.repo, a.built, a.source or ())
- files = [out / zsrc.name, out / MANIFEST, out / SIGNATURE]
+ files = [out / zsrc.name, out / MANIFEST]
if zsrc.resolve() != files[0].resolve(): shutil.copyfile(zsrc, files[0])
files[1].write_bytes(data)
- files[2].write_text(base64.b64encode(key.sign(data)).decode()) # no newline: Data(base64Encoded:) rejects one
- if not verify_signature(files[1].read_bytes(), files[2].read_text(), pub): raise Fail('the signature just made does not verify')
+ sigfile = out / SIGNATURE
+ if key is not None:
+ files.append(sigfile)
+ sigfile.write_text(base64.b64encode(key.sign(data)).decode()) # no newline: Data(base64Encoded:) rejects one
+ if not verify_signature(files[1].read_bytes(), sigfile.read_text(), pub): raise Fail('the signature just made does not verify')
+ elif sigfile.exists():
+ sigfile.unlink() # a signature left in --out by an earlier run does not belong to this manifest
m = json.loads(data)
- say(f'{MANIFEST}: {m["channel"]} {m["version"]} engine_id {m["engine_id"]} built {m["built"]}, signed ({"ephemeral key" if a.ephemeral_key else "ENGINE_SIGNING_KEY"})')
+ how = f'signed ({"ephemeral key" if a.ephemeral_key else KEY_ENV})' if key is not None else 'not signed'
+ say(f'{MANIFEST}: {m["channel"]} {m["version"]} engine_id {m["engine_id"]} built {m["built"]}, {how}')
+ if key is None: unsigned_warning()
if a.upload:
notes = (f'Engine {m["engine_id"]} (seedds/nxnative {m["pin"][:12]} + the patch series), built {m["built"]}. '
+ ('Experimental: built by the nightly sync and checked by CI only, not played on hardware. The launcher offers it as a manual, opt-in update.'
@@ -210,13 +240,23 @@ def cmd_publish(a):
def cmd_check_key(a):
key, pub = signing_key(a.pub)
+ if key is None:
+ unsigned_warning()
+ return 0
say(f'{KEY_ENV} matches {a.pub} ({pub})')
return 0
def cmd_verify(a):
+ sig = Path(a.sig) if a.sig else Path(a.manifest).with_name(SIGNATURE)
+ if not sig.is_file():
+ if a.require_signature or os.environ.get(KEY_ENV, '').strip():
+ say(f'signature MISSING: {sig} does not exist')
+ return 1
+ warn(f'{sig} does not exist and {KEY_ENV} is not set: the manifest is accepted without a signature.')
+ return 0
pub = read_pub(a.pub)
- ok = verify_signature(Path(a.manifest).read_bytes(), Path(a.sig).read_text(), pub)
+ ok = verify_signature(Path(a.manifest).read_bytes(), sig.read_text(), pub)
say('signature valid' if ok else 'signature INVALID')
return 0 if ok else 1
@@ -236,7 +276,8 @@ def main(argv=None):
sub = ap.add_subparsers(dest='cmd', required=True)
sub.add_parser('keygen').set_defaults(f=cmd_keygen)
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', required=True); s.add_argument('--pub', default=str(PUB_FILE)); s.set_defaults(f=cmd_verify)
+ 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('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.py
index 7a6ad6bd..11da5967 100644
--- a/tools/tests/test_release_manifest.py
+++ b/tools/tests/test_release_manifest.py
@@ -1,6 +1,6 @@
"""tools/release_manifest.py (LNPANDY/NX2Apple#227): latest.json has the shape EngineManifest.Manifest decodes, the signature is a
-detached Ed25519 signature over its exact bytes, the release fails without the right key, and uploads go in the right order with a
-fake `gh`. The keys are generated here: nothing secret is used and nothing touches the network."""
+detached Ed25519 signature over its exact bytes, a key that is set but wrong stops the release, no key means an unsigned release with
+a warning, and uploads go in the right order with a fake `gh`. The keys are generated here: nothing secret is used and nothing touches the network."""
import base64
import hashlib
import importlib
@@ -121,17 +121,25 @@ class Manifest(unittest.TestCase):
out = self.publish()
args = ['verify', '--manifest', str(out / 'latest.json'), '--sig', str(out / 'latest.json.sig'), '--pub', str(self.pubfile)]
self.assertEqual(R.main(args), 0)
+ self.assertEqual(R.main(['verify', '--manifest', str(out / 'latest.json'), '--pub', str(self.pubfile)]), 0) # the .sig next to it
(out / 'latest.json').write_bytes((out / 'latest.json').read_bytes().replace(b'stable', b'rolling'))
self.assertEqual(R.main(args), 1)
+ def test_verify_fails_for_a_missing_signature_while_the_key_is_set(self):
+ out = self.publish()
+ (out / 'latest.json.sig').unlink()
+ self.assertEqual(R.main(['verify', '--manifest', str(out / 'latest.json'), '--pub', str(self.pubfile)]), 1)
+
# ---- the key check ----
- def test_a_release_fails_without_the_secret(self):
+ def test_without_the_secret_the_key_check_passes_with_a_warning(self):
+ import contextlib, io
del os.environ[R.KEY_ENV]
- self.assertEqual(R.main(['check-key', '--pub', str(self.pubfile)]), 2)
- self.publish(expect=2)
+ buf = io.StringIO()
+ with contextlib.redirect_stdout(buf): self.assertEqual(R.main(['check-key', '--pub', str(self.pubfile)]), 0)
+ self.assertIn('ENGINE_SIGNING_KEY is not set', buf.getvalue()); self.assertIn('WARNING', buf.getvalue())
os.environ[R.KEY_ENV] = ' '
- self.assertEqual(R.main(['check-key', '--pub', str(self.pubfile)]), 2)
+ self.assertEqual(R.main(['check-key', '--pub', str(self.pubfile)]), 0)
def test_a_release_fails_when_the_key_is_not_the_one_in_the_repository(self):
os.environ[R.KEY_ENV] = new_key()[1]
@@ -139,9 +147,10 @@ class Manifest(unittest.TestCase):
self.publish(expect=2)
self.assertFalse((self.tmp / 'out' / 'latest.json').exists())
- def test_a_release_fails_while_the_repository_has_no_public_key(self):
+ def test_a_set_key_fails_while_the_repository_has_no_public_key(self):
self.pubfile.write_text('# nothing yet\n')
self.assertEqual(R.main(['check-key', '--pub', str(self.pubfile)]), 2)
+ self.publish(expect=2)
self.pubfile.unlink()
self.assertEqual(R.main(['check-key', '--pub', str(self.pubfile)]), 2)
@@ -223,6 +232,80 @@ class Manifest(unittest.TestCase):
self.publish()
self.assertFalse(log.exists())
+ def test_a_signed_upload_does_not_delete_the_signature_asset(self):
+ log = self.fake_gh(exists=True)
+ self.publish('--upload')
+ self.assertFalse([c for c in self.calls(log) if c[:2] == ['release', 'delete-asset']])
+
+
+class Unsigned(unittest.TestCase):
+ """No ENGINE_SIGNING_KEY: the engine is published without a signature and the log says so. Needs no `cryptography`."""
+ def setUp(self):
+ self.tmp = Path(tempfile.mkdtemp(prefix='test-manifest-unsigned-'))
+ 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.tmp / 'NX2Apple-engine.zip'
+ with zipfile.ZipFile(self.engine, 'w') as z:
+ z.writestr('.engine-id', EID + '\n'); z.writestr('.upstream-ref', PIN + '\n'); z.writestr('dm/a.c', 'x')
+ 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 publish(self, *extra, channel='stable', tag='v0.8.0', out='out', expect=0):
+ import contextlib, io
+ args = ['publish', '--engine-zip', str(self.engine), '--version', '0.8.0', '--channel', channel, '--tag', tag,
+ '--out', str(self.tmp / out), '--pub', str(self.pubfile), '--built', '2026-10-31T02:00:00Z', *extra]
+ buf = io.StringIO()
+ with contextlib.redirect_stdout(buf): self.assertEqual(R.main(args), expect)
+ return self.tmp / out, buf.getvalue()
+
+ def fake_gh(self):
+ d = self.tmp / 'bin'; d.mkdir(exist_ok=True)
+ log = self.tmp / 'gh.log'
+ gh = d / 'gh'
+ gh.write_text(f'#!/bin/sh\necho "$@" >> "{log}"\nexit 0\n')
+ gh.chmod(gh.stat().st_mode | stat.S_IXUSR)
+ os.environ['PATH'] = f'{d}:{os.environ["PATH"]}'
+ return log
+
+ def test_the_manifest_is_written_without_a_signature_and_with_a_warning(self):
+ out, text = self.publish()
+ self.assertTrue((out / 'latest.json').is_file()); self.assertFalse((out / 'latest.json.sig').exists())
+ self.assertEqual(json.loads((out / 'latest.json').read_text())['engine_id'], EID)
+ self.assertIn('not signed', text); self.assertIn('WARNING: ENGINE_SIGNING_KEY is not set', text)
+ self.assertIn('LNPANDY/NX2Apple#268', text)
+
+ def test_in_ci_the_warning_is_a_workflow_annotation(self):
+ os.environ['GITHUB_ACTIONS'] = 'true'
+ self.assertIn('::warning title=Engine is not signed::ENGINE_SIGNING_KEY is not set', self.publish()[1])
+
+ def test_a_signature_left_in_the_output_folder_is_removed(self):
+ (self.tmp / 'out').mkdir()
+ (self.tmp / 'out' / 'latest.json.sig').write_text('stale')
+ self.assertFalse((self.publish()[0] / 'latest.json.sig').exists())
+
+ def test_the_upload_drops_an_older_signature_and_sends_no_new_one(self):
+ log = self.fake_gh()
+ self.publish('--upload', channel='experimental', tag='engine-experimental')
+ calls = [l.split() for l in log.read_text().splitlines()]
+ self.assertEqual([c[3] for c in calls if c[:2] == ['release', 'delete-asset']], ['latest.json.sig'])
+ self.assertEqual([Path(c[3]).name for c in calls if c[:2] == ['release', 'upload']], ['NX2Apple-engine.zip', 'latest.json'])
+ self.assertLess([c[:2] for c in calls].index(['release', 'delete-asset']), [c[:2] for c in calls].index(['release', 'upload']))
+
+ def test_a_download_source_other_than_github_needs_a_key(self):
+ out, _ = self.publish('--source', 'https://mirror.example/engine/', expect=2)
+ self.assertFalse((out / 'latest.json').exists())
+
+ def test_verify_accepts_an_unsigned_manifest_with_a_warning_unless_a_signature_is_required(self):
+ out, _ = self.publish()
+ args = ['verify', '--manifest', str(out / 'latest.json'), '--pub', str(self.pubfile)]
+ self.assertEqual(R.main(args), 0)
+ self.assertEqual(R.main([*args, '--require-signature']), 1)
+
if __name__ == '__main__':
unittest.main()