Files
skylar taylor-barrickandDylan M. Taylor e08bf3b8d4 nightly: run the shared nightly pipeline for any reviewed registry app (PhotoCraft unchanged) (#363)
* nightly: derive Linux package names from the app name

The nightly Linux package checks compared deb, rpm, Arch and Flatpak names against PhotoCraft
literals. scripts/nightly_linux_names.py derives them from inputs.app-name (the reviewed registry
identity when present, else ai.storyteller.<app>.nightly), and the checks and smoke steps use it.

* nightly: read the names registry from its fixed checkout path

nightly_linux_names.py no longer takes a --registry path (Sonar S8707): it reads the nightly-apps.json
beside scripts/ in its own checkout, and the workflow stops passing one.

* nightly: refuse partial package reads and test the checks' behaviour

Each deb, rpm and .PKGINFO read is its own assignment, so a tool failure after partial output
refuses instead of passing a matching name. New tests run the workflow's own check steps against
package-metadata fixtures with stub tools: designcraft packages pass, PhotoCraft-named ones and
partial reads refuse.

* nightly: run the shared nightly pipeline for any reviewed registry app

The registry row gains display_name, env_prefix and per-platform entrypoints, and
scripts/nightly_app.py (replacing nightly_linux_names.py) derives every app-specific name
from it. An admit-app job replaces the literal PhotoCraft gates in nightly-unsigned.yml,
nightly-release.yml takes a required app-name, and the compile and smoke steps use the
row's build prefix and binary paths. A plain Linux nightly tar may start through a short
launcher that execs the registry-named x86_64 ELF with the nightly profile; the smoke runs
the ELF directly. Every PhotoCraft name and fixture is unchanged.

* test: compare PhotoCraft's registry row with a fixture, not git history

CI checkouts are shallow, so `git show 8f58b6d0:nightly-apps.json` failed with exit 128. The
pre-change PhotoCraft row is now tests/fixtures/nightly-apps-photocraft-targets-8f58b6d0.json.

* nightly: launcher grammar, launcher layout at admission, optional pending (CodeRabbit)

- nightly_unix: a launcher must match a fixed grammar (its directory, quoted profile-root values with only
  parameter expansions, a case on $1, set -e/-eu, and the exec of the GUI binary); any other command,
  command substitution or backticks refuses.
- nightly_app: admission requires the GUI binary in or below its launcher's directory, the layout the
  archive check derives the exec path from.
- nightly_signing: the optional pending file is resolved once and used for both the inventory and the
  final Mac check, so omitting --pending no longer fails after signing.

* nightly: one canonical Linux launcher template instead of validating scripts

The Linux nightly tar's entrypoint is now either the GUI ELF itself or, byte for byte,
scripts/nightly-launcher.sh.in rendered for the app (only the registry row's strictly validated
binary path and the app's package identity are substituted). The template resolves its own
directory once, makes the directory, target and profile root readonly, sets the profile root from
XDG data home (or HOME) and the app identity, and execs the target with the nightly launch profile.
The line-grammar launcher validator is removed. `nightly_app.py launcher` prints the rendered file.

* nightly: launcher passes the Launcher's own profile argv through unchanged

The ArtCraft Launcher starts the tar's entrypoint with `--launch-profile nightly-v1 --profile-root
<per-install root> -- [files...]`. Wrapping that again gave the app two profile pairs, with the fixed
root overriding the Launcher's. When $1 is exactly --launch-profile, the template now execs the
readonly target with "$@" unchanged and lets the app's own parser validate the pair; everything
else keeps the fixed profile.

---------

Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
2026-11-25 11:19:37 -05:00

100 lines
4.2 KiB
Python

#!/usr/bin/env python3
"""Credential-free admission for a reviewed app's nightly caller (the app comes from NIGHTLY_APP).
Manual actors must be a reviewed literal JSON array in caller workflow source,
never an untrusted dispatch input. This prevents accidental use, not a writer
from editing or bypassing the workflow. It does not admit platforms or app code.
"""
from collections.abc import Mapping
import json
import os
from pathlib import Path
import re
import sys
# Run with `python -I`: only this tooling checkout's own siblings (nightly_app), never app code.
sys.path.insert(0, str(Path(__file__).resolve().parent))
MAX_ACTORS_BYTES = 4096
MAX_ACTORS = 64
MAX_LOGIN_LENGTH = 39
MAX_ATTEMPT_DIGITS = 20
LOGIN = re.compile(r'[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*')
ATTEMPT = re.compile(r'[1-9][0-9]{0,19}')
def valid_login(value):
"""GitHub login grammar, with an optional case-insensitive [bot] suffix."""
if not isinstance(value, str) or not 0 < len(value) <= MAX_LOGIN_LENGTH + 5:
return False
base = value[:-5] if value.lower().endswith('[bot]') else value
return 0 < len(base) <= MAX_LOGIN_LENGTH and LOGIN.fullmatch(base) is not None
def manual_actors(actors_json):
"""Bound parsing before allocation and return distinct normalized logins."""
if not isinstance(actors_json, str) or len(actors_json) > MAX_ACTORS_BYTES:
raise ValueError('manual actor JSON must be a bounded string')
try:
if len(actors_json.encode('utf-8')) > MAX_ACTORS_BYTES:
raise ValueError('manual actor JSON exceeds byte limit')
except UnicodeEncodeError:
raise ValueError('manual actor JSON contains invalid Unicode') from None
try:
actors = json.loads(actors_json)
except (ValueError, RecursionError):
raise ValueError('manual actor JSON is invalid') from None
if not isinstance(actors, list) or len(actors) > MAX_ACTORS:
raise ValueError('manual actors must be a bounded JSON array')
normalized = set()
for actor in actors:
if not valid_login(actor):
raise ValueError('manual actors contain an invalid login')
login = actor.lower()
if login in normalized:
raise ValueError('manual actors contain duplicate logins')
normalized.add(login)
return normalized
def require_invocation(environment, actors_json='[]'):
"""Allow the initial schedule, or a reviewed current manual/re-run actor.
Never fall back to GITHUB_ACTOR: it identifies the original initiator, not the
person requesting a re-run. Invalid configuration also refuses initial runs.
"""
actors = manual_actors(actors_json)
if not isinstance(environment, Mapping):
raise ValueError('invocation environment must be a mapping')
import nightly_app as apps
if environment.get('GITHUB_REPOSITORY') != apps.current(environment).repository:
raise ValueError('invocation requires the reviewed app repository')
if environment.get('GITHUB_REF') != 'refs/heads/main':
raise ValueError('invocation requires the main branch')
event = environment.get('GITHUB_EVENT_NAME')
if event not in ('schedule', 'workflow_dispatch'):
raise ValueError('invocation requires schedule or workflow dispatch')
actor = environment.get('GITHUB_TRIGGERING_ACTOR')
if not valid_login(actor):
raise ValueError('invocation requires a valid current triggering actor')
attempt = environment.get('GITHUB_RUN_ATTEMPT')
if not isinstance(attempt, str) or len(attempt) > MAX_ATTEMPT_DIGITS or not ATTEMPT.fullmatch(attempt):
raise ValueError('invocation requires a bounded positive run attempt')
if (event == 'workflow_dispatch' or attempt != '1') and actor.lower() not in actors:
raise ValueError('current triggering actor is not approved for manual runs or re-runs')
return True
def main():
try:
require_invocation(os.environ, os.environ.get('NIGHTLY_MANUAL_ACTORS', '[]'))
except ValueError as error:
# Diagnostics are fixed text: never echo environment or JSON contents.
print(f'nightly invocation refused: {error}', file=sys.stderr)
return 1
return 0
if __name__ == '__main__':
sys.exit(main())