Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ jobs:
run: python3 scripts/release_dispatch_guard_tests.py

- name: Preview data wait tests
# preview-server.yml signs the preview manifest only after this script
# sees its data URLs served; the tests drive the script against a local
# HTTP server and check the publish job waits on every manifest data URL.
# The manifest is signed only after this script sees its data URLs
# served, so the tests drive it against a local HTTP server. They also
# run the publish step's own shell over a stubbed checkout, holding
# packaging/desktop-platforms.txt to the binaries that step uploads: a
# listed triple it does not publish leaves that desktop with no preview.
run: python3 scripts/preview_data_wait_tests.py

- name: Action pin checker unit tests
Expand Down Expand Up @@ -158,23 +160,23 @@ jobs:
# while only the .deb side was current.
run: python3 scripts/check_media_plugin_packaging.py

- name: Desktop platform mapping checker unit tests
- name: Desktop platform matrix checker unit tests
# Exercises the checker against throwaway trees only; it does not read
# this repository's own files. The direction that matters is refusal: an
# unreadable matrix reads as an empty published set, and the empty set is
# a subset of any mapping, so a checker that understood nothing would
# report a clean pass.
run: python3 scripts/check_shell_platform_mapping_tests.py

- name: Desktop platform mapping coverage
# Two directions across three files. Every platform shell-release.yml's
# build-shell matrix publishes must be a native_engine.rs ServerPlatform
# variant, or that desktop ships unable to fetch an engine; and every
# triple that enum resolves must reach release.yml signed, with both the
# binary and its signature attached, or the desktop's download 404s on
# whichever half is missing. The Rust-side test pins the pairs it expects
# and cannot see either set grow past them.
run: python3 scripts/check_shell_platform_mapping.py
# unreadable list must raise, not read as an empty list.
run: python3 scripts/check_desktop_platform_matrix_tests.py

- name: Desktop platform matrix coverage
# packaging/desktop-platforms.txt is the published desktop platform set.
# A platform shell-release.yml's build-shell matrix builds with no row
# there ships a desktop whose ServerPlatform resolves no triple, so it can
# never fetch an engine; preview-server.yml's build and release.yml's
# build-server triples are held to the same file by equality, so a triple
# published for no listed desktop is an error, not a harmless extra. The
# enum half is native_engine.rs's own test, which runs at tag time in
# shell-release.yml's shell-preflight — tauri-check is disabled here, so
# no PR-time job compiles it.
run: python3 scripts/check_desktop_platform_matrix.py

- name: Resolution-frame boundary guard
# Full-tree guard: legacy resolution keys are reader/fixture-only, and
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/preview-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ jobs:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
if: steps.publication-gate.outputs.already_published != 'true'
with:
# This job publishes `commit`, so it reads the scripts and the
# platform contract from it rather than from the workflow ref.
# Known split: the YAML around them still comes from the workflow ref,
# so a deploy one commit behind pairs an older contract with a newer
# binaries list. The sign step's diff refuses that pair, publishing
# nothing rather than a partial set, and the next deploy heals it.
ref: ${{ inputs.commit }}
persist-credentials: false

- name: Wait for the data files the manifest names
Expand Down Expand Up @@ -351,6 +358,20 @@ jobs:
# triple, which is the key the manifest publishes it under.
platform_of() { basename "$(dirname "$1")"; }

# Every desktop that asks for a preview has a row in the contract, so a
# listed triple with no binary above publishes no URL for it and that
# desktop silently never sees a preview. Held here, before the first
# upload: a mismatch publishes nothing rather than half a manifest.
listed_triples=$(awk '{sub(/#.*/, ""); if (NF) print $3}' packaging/desktop-platforms.txt | sort -u)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
published_triples=$(for binary in "${binaries[@]}"; do platform_of "$binary"; done | sort)
printf 'desktop-platforms.txt triples: %s\nthis job publishes: %s\n' \
"${listed_triples//$'\n'/ }" "${published_triples//$'\n'/ }"
if [ -z "$listed_triples" ] \
|| ! diff <(printf '%s\n' "$listed_triples") <(printf '%s\n' "$published_triples"); then
echo "::error::packaging/desktop-platforms.txt (<) is not the set of platforms this job publishes (>); a listed triple with no binary here gets no preview URL, and one published without a row goes to no desktop."
exit 1
fi

declare -A sha256_of
for binary in "${binaries[@]}"; do
name=$(basename "$binary")
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1243,6 +1243,41 @@ jobs:
echo "EOF"
} >> "$GITHUB_OUTPUT"

- name: Verify the release assets are the ones desktops download
env:
RELEASE_FILES: ${{ steps.release-assets.outputs.files }}
run: |
set -euo pipefail
# fail_on_unmatched_files only ever sees the list above, so it cannot
# know a platform is missing from it: add a build target, forget this
# file, and every desktop on it 404s with all gates green. Immutable
# releases take no late upload, so this has to fail before the create.
status=0
# No nullglob: an absent or empty artifacts/ iterates this literally, failing the grep.
for binary in artifacts/phase-server-slim-*/*; do
case "$binary" in *.minisig) continue ;; esac
for asset in "$binary" "$binary.minisig"; do
printf '%s\n' "$RELEASE_FILES" | grep -qxF "$asset" ||
{ echo "::error::built $asset is missing from the release asset list"; status=1; }
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
done
done
# Both sides above are publisher-side spellings: rename a pair in the
# build and in the list, they still agree, and the desktop's download
# 404s. native_engine.rs asks for phase-server-slim-<triple>, and for
# that name plus .minisig, with .exe on windows; the contract's os and
# triple columns are where CI already holds that naming.
canonical=$(awk '{sub(/#.*/, ""); if (NF) print "phase-server-slim-" $3 ($1 == "windows" ? ".exe" : "")}' packaging/desktop-platforms.txt)
[ -n "$canonical" ] || { echo "::error::packaging/desktop-platforms.txt named no desktop platform"; exit 1; }
printf 'desktop download names: %s\n' "${canonical//$'\n'/ }"
published=$(printf '%s\n' "$RELEASE_FILES" | sed 's|.*/||')
while read -r binary; do
for asset in "$binary" "$binary.minisig"; do
printf '%s\n' "$published" | grep -qxF "$asset" ||
{ echo "::error::no release asset is published as $asset, which the desktop shell downloads by that exact name"; status=1; }
done
done <<<"$canonical"
exit $status

- name: Create release
uses: softprops/action-gh-release@3bb12739c298aeb8a4eeaf626c5b8d85266b0e65 # v2.6.2
with:
Expand Down
28 changes: 19 additions & 9 deletions client/src-tauri/src/native_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2166,9 +2166,8 @@ impl ServerPlatform {
];

/// The pair as `std::env::consts::{OS, ARCH}` spells it, which is also how
/// the `build-shell` matrix spells its `os` and `arch`.
/// `scripts/check_shell_platform_mapping.py` reads these arms to hold that
/// matrix to this enum.
/// `packaging/desktop-platforms.txt` and the `build-shell` matrix spell
/// their `os` and `arch`.
fn os_arch(self) -> (&'static str, &'static str) {
match self {
Self::MacosAarch64 => ("macos", "aarch64"),
Expand Down Expand Up @@ -3464,14 +3463,25 @@ mod tests {

#[test]
fn server_target_triple_maps_every_published_desktop_platform() {
for (os, arch, triple) in [
("macos", "aarch64", "aarch64-apple-darwin"),
("windows", "x86_64", "x86_64-pc-windows-msvc"),
("linux", "x86_64", "x86_64-unknown-linux-musl"),
("linux", "aarch64", "aarch64-unknown-linux-musl"),
] {
let mut listed = HashSet::new();
for line in include_str!("../../../packaging/desktop-platforms.txt").lines() {
let content = line.split_once('#').map_or(line, |(before, _)| before);
let fields: Vec<&str> = content.split_whitespace().collect();
if fields.is_empty() {
continue;
}
let [os, arch, triple] = fields[..] else {
panic!("expected `os arch triple`, got {line:?}")
};
assert_eq!(server_target_triple(os, arch), Some(triple), "{os}-{arch}");
listed.insert((os, arch));
}
// The set, not its size: a duplicated row would otherwise stand in for
// a variant no row covers.
assert_eq!(
listed,
HashSet::from(ServerPlatform::ALL.map(ServerPlatform::os_arch))
);
for (os, arch) in [
("macos", "x86_64"),
("windows", "aarch64"),
Expand Down
11 changes: 11 additions & 0 deletions packaging/desktop-platforms.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Desktop platforms the shell release publishes: os arch triple.
# os/arch are spelled as std::env::consts::{OS, ARCH} spells them, which is also
# how shell-release.yml's build-shell matrix spells them. Held to that matrix by
# scripts/check_desktop_platform_matrix.py, and to native_engine.rs's
# ServerPlatform (whose triple each desktop downloads) by that module's own test.
# That script holds the triple column to preview-server.yml and release.yml too.
# preview-server.yml's publish job holds its own upload list to it at run time.
macos aarch64 aarch64-apple-darwin
windows x86_64 x86_64-pc-windows-msvc
linux x86_64 x86_64-unknown-linux-musl
linux aarch64 aarch64-unknown-linux-musl
78 changes: 78 additions & 0 deletions scripts/check_desktop_platform_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3
"""Hold the desktop build matrices to packaging/desktop-platforms.txt.

A platform shell-release.yml's build-shell matrix builds with no row there ships
a desktop whose ServerPlatform resolves no target triple, so it can never fetch
an engine; a triple preview-server.yml builds with no row there provisions a
preview no desktop asks for; a listed triple release.yml's build-server never
builds is a download URL that 404s. native_engine.rs's test cannot see any half.
"""

import os
import sys
from pathlib import Path

import yaml

ROOT = Path(os.environ.get("DESKTOP_PLATFORM_ROOT") or Path(__file__).resolve().parent.parent)
PLATFORMS = ROOT / "packaging" / "desktop-platforms.txt"
MATRIX = ROOT / ".github" / "workflows" / "shell-release.yml"
PREVIEW = ROOT / ".github" / "workflows" / "preview-server.yml"
RELEASE = ROOT / ".github" / "workflows" / "release.yml"
TRIPLE_SOURCES = [
Comment thread
lgray marked this conversation as resolved.
Resolved
(PREVIEW, "build", "no desktop would ever ask for that preview", ""),
(RELEASE, "build-server", "no desktop downloads it", "; the desktop's download URL 404s"),
]


def listed():
# read_text raises by design: an empty list fails a populated matrix anyway, but blames it.
rows = [line.split("#")[0].split() for line in PLATFORMS.read_text().splitlines()]
rows = [row for row in rows if row]
if malformed := [row for row in rows if len(row) != 3]:
sys.exit(f"::error::desktop-platforms.txt rows are not `os arch triple`: {malformed}")
return {tuple(row) for row in rows}


def include(path, job):
# A matrix runs the product of its free axes too, so reading include alone
# would report those builds as not happening.
matrix = yaml.safe_load(path.read_text())["jobs"][job]["strategy"]["matrix"]
if free := sorted(set(matrix) - {"include", "exclude"}):
sys.exit(f"::error::{path.name} {job} matrix has free axes {free}, whose product builds "
"platforms this checker cannot see")
return matrix["include"]


def built():
return {(entry["os"], entry["arch"]) for entry in include(MATRIX, "build-shell")}


def main():
rows = listed()
want, have = {row[:2] for row in rows}, built()
print(f"desktop-platforms.txt: {sorted(want)}")
print(f"build-shell matrix: {sorted(have)}")
for pair in sorted(have - want):
print(f"::error::build-shell builds {pair}, which desktop-platforms.txt does not "
"list; that desktop would ship unable to fetch an engine", file=sys.stderr)
for pair in sorted(want - have):
print(f"::error::desktop-platforms.txt lists {pair}, which build-shell does not build",
file=sys.stderr)
triples, agree = {row[2] for row in rows}, want == have
print(f"desktop-platforms.txt triples: {sorted(triples)}")
for path, job, unlisted, missing in TRIPLE_SOURCES:
builds = {entry["triple"] for entry in include(path, job)}
print(f"{path.stem} {job} matrix:".ljust(30), sorted(builds))
agree &= builds == triples
for triple in sorted(builds - triples):
print(f"::error::{path.stem} {job} has a row for {triple}, which "
f"desktop-platforms.txt does not list; {unlisted}", file=sys.stderr)
for triple in sorted(triples - builds):
print(f"::error::desktop-platforms.txt lists {triple}, which {path.stem} {job} "
f"does not build{missing}", file=sys.stderr)
return 0 if agree else 1


if __name__ == "__main__":
sys.exit(main())
102 changes: 102 additions & 0 deletions scripts/check_desktop_platform_matrix_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env python3
"""Legs for check_desktop_platform_matrix.py: agreement, a grown matrix, a
dropped platform, a missing list, a free matrix axis, a grown preview matrix, a
platform nothing releases, a malformed row. The direction that matters is
refusal: an unreadable list must raise, not read as an empty list.
"""

import os
import subprocess
import sys
import tempfile
from pathlib import Path

CHECKER = Path(__file__).resolve().parent / "check_desktop_platform_matrix.py"
MATRIX = """\
jobs:
build-shell:
strategy:
matrix:
include:
- {os: linux, arch: x86_64, runner: ubuntu-latest}
- {os: macos, arch: aarch64, runner: macos-latest}
"""
PREVIEW = """\
jobs:
build:
strategy:
matrix:
include:
- {triple: x86_64-unknown-linux-musl}
- {triple: aarch64-apple-darwin}
"""
RELEASE = """\
jobs:
build-server:
strategy:
matrix:
include:
- {triple: x86_64-unknown-linux-musl}
- {triple: aarch64-apple-darwin}
"""
LISTING = "# fields: os arch triple\nlinux x86_64 x86_64-unknown-linux-musl\nmacos aarch64 aarch64-apple-darwin\n"


def run(matrix, listing, preview=PREVIEW, release=RELEASE):
root = Path(tempfile.mkdtemp())
(root / ".github" / "workflows").mkdir(parents=True)
(root / ".github" / "workflows" / "shell-release.yml").write_text(matrix)
(root / ".github" / "workflows" / "preview-server.yml").write_text(preview)
(root / ".github" / "workflows" / "release.yml").write_text(release)
if listing is not None:
(root / "packaging").mkdir()
(root / "packaging" / "desktop-platforms.txt").write_text(listing)
return subprocess.run(
[sys.executable, str(CHECKER)], capture_output=True, text=True,
env={**os.environ, "DESKTOP_PLATFORM_ROOT": str(root)},
)


agree = run(MATRIX, LISTING)
assert agree.returncode == 0, agree.stderr
assert "('linux', 'x86_64')" in agree.stdout, agree.stdout
assert "('macos', 'aarch64')" in agree.stdout, agree.stdout

grown = run(MATRIX + " - {os: windows, arch: x86_64, runner: windows-latest}\n", LISTING)
assert grown.returncode != 0, grown.stdout
assert "('windows', 'x86_64')" in grown.stderr, grown.stderr

dropped = run(MATRIX, LISTING + "freebsd x86_64 nope\n")
assert dropped.returncode != 0, dropped.stdout
assert "('freebsd', 'x86_64')" in dropped.stderr, dropped.stderr

absent = run(MATRIX, None)
assert absent.returncode != 0, absent.stdout
assert "desktop-platforms.txt" in absent.stderr, absent.stderr
assert "('linux', 'x86_64')" not in absent.stdout, absent.stdout

free = run(MATRIX + " arch: [riscv64]\n", LISTING)
assert free.returncode != 0, free.stdout
assert "free axes ['arch']" in free.stderr, free.stderr

previewed = run(MATRIX, LISTING, PREVIEW + " - {triple: riscv64-unknown-linux-musl}\n")
assert previewed.returncode != 0, previewed.stdout
assert "riscv64-unknown-linux-musl" in previewed.stderr, previewed.stderr

# The reviewer's reproduction: a platform every other matrix gained, which the
# release never builds, so its desktop resolves a download URL that 404s.
unreleased = run(
MATRIX + " - {os: linux, arch: riscv64, runner: ubuntu-latest}\n",
LISTING + "linux riscv64 riscv64-unknown-linux-musl\n",
PREVIEW + " - {triple: riscv64-unknown-linux-musl}\n",
)
assert unreleased.returncode != 0, unreleased.stdout
assert "release build-server does not build" in unreleased.stderr, unreleased.stderr
assert "riscv64-unknown-linux-musl" in unreleased.stderr, unreleased.stderr

malformed = run(MATRIX, "linux x86_64\n")
assert malformed.returncode != 0, malformed.stdout
assert "['linux', 'x86_64']" in malformed.stderr, malformed.stderr

print("ok: agreement, grown matrix, dropped platform, missing list, free axis, "
"grown preview matrix, unreleased platform, malformed row")
Loading
Loading