Skip to content

Commit ec36914

Browse files
committed
fix(mobile): refresh upstream and repair command output import
2 parents 3d191dd + d2d59fa commit ec36914

149 files changed

Lines changed: 9371 additions & 1079 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: CI changes
2+
description: Decide which CI jobs a change needs. See .github/scripts/ci-changes.cjs.
3+
outputs:
4+
typecheck:
5+
value: ${{ steps.detect.outputs.typecheck }}
6+
build:
7+
value: ${{ steps.detect.outputs.build }}
8+
test:
9+
value: ${{ steps.detect.outputs.test }}
10+
test_packages:
11+
value: ${{ steps.detect.outputs.test_packages }}
12+
test_web:
13+
value: ${{ steps.detect.outputs.test_web }}
14+
test_server:
15+
value: ${{ steps.detect.outputs.test_server }}
16+
rust:
17+
value: ${{ steps.detect.outputs.rust }}
18+
release_smoke:
19+
value: ${{ steps.detect.outputs.release_smoke }}
20+
mobile_native:
21+
value: ${{ steps.detect.outputs.mobile_native }}
22+
runs:
23+
using: composite
24+
steps:
25+
- id: detect
26+
shell: bash
27+
env:
28+
EVENT_NAME: ${{ github.event_name }}
29+
BEFORE_SHA: ${{ github.event.before }}
30+
run: |
31+
set -uo pipefail
32+
33+
decide() {
34+
node .github/scripts/ci-changes.cjs "$@" | tee -a "$GITHUB_OUTPUT"
35+
exit "${PIPESTATUS[0]}"
36+
}
37+
38+
fail_open() {
39+
echo "$* Running every job."
40+
decide
41+
}
42+
43+
# Reads the change from git rather than the REST API: every job that
44+
# runs this shares the repository's 1,000 requests/hour GITHUB_TOKEN quota.
45+
if [[ "$EVENT_NAME" == pull_request ]]; then
46+
# A pull request checks out GitHub's merge commit with fetch-depth: 2,
47+
# so its first parent is the base branch and the diff is the PR's change.
48+
base=HEAD^1
49+
mode=()
50+
else
51+
base=$BEFORE_SHA
52+
git fetch --quiet --no-tags --depth=1 --filter=blob:none origin "$base" \
53+
|| fail_open "Could not fetch ${base}."
54+
# main keeps a full run as the backstop for anything the gate misses.
55+
mode=(--full)
56+
fi
57+
58+
# --no-renames lists a rename as its old and new path: renaming a file out
59+
# of a package changes that package just like editing it. It also keeps
60+
# git from fetching file contents to score renames.
61+
git diff --name-only --no-renames "$base" HEAD > "$RUNNER_TEMP/changed-paths" \
62+
|| fail_open "Could not diff against ${base}."
63+
decide --paths "$RUNNER_TEMP/changed-paths" "${mode[@]}"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Setup CI dependencies
2+
description: Install Vite+ and the workspace dependencies from cache.
3+
runs:
4+
using: composite
5+
steps:
6+
# setup-vp reuses an installed exact version, so restoring its home skips the
7+
# installer download on every job.
8+
- name: Resolve Vite+ version
9+
id: vp
10+
shell: bash
11+
run: |
12+
echo "version=$(sed -nE 's/^ vite-plus: ([0-9][^ ]*)$/\1/p' pnpm-workspace.yaml)" >> "$GITHUB_OUTPUT"
13+
14+
- name: Cache Vite+
15+
if: steps.vp.outputs.version != ''
16+
uses: actions/cache@v6
17+
with:
18+
path: ~/.vite-plus
19+
key: vite-plus-home-v1-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}
20+
21+
# The pnpm store stays a cache tarball on the runner's own disk. A store on a
22+
# Blacksmith sticky disk mounts in under a second, but pnpm then copies every
23+
# package across filesystems instead of hard-linking it: install took 28-49s
24+
# against 9s plus an 11s restore.
25+
- name: Setup Vite+
26+
uses: voidzero-dev/setup-vp@v1
27+
with:
28+
node-version-file: package.json
29+
cache: true
30+
run-install: true

‎.github/scripts/ci-changes.cjs‎

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// Decides which CI jobs a change needs. Prints `key=value` lines for
2+
// $GITHUB_OUTPUT; a job runs unless its key is "false".
3+
//
4+
// node ci-changes.cjs --paths <file> gate by the listed paths
5+
// node ci-changes.cjs --paths <file> --full run every Linux job, gate only the macOS lint
6+
// node ci-changes.cjs changed paths unknown: run everything
7+
//
8+
// Every changed path maps to workspace packages, which then pull in their
9+
// dependents from package.json. A path this file does not recognize runs
10+
// everything, so a new root file or directory can only cost minutes.
11+
const fs = require("node:fs");
12+
const path = require("node:path");
13+
14+
const root = path.resolve(__dirname, "../..");
15+
16+
// Never read by a build, typecheck, or test. Lint still formats them.
17+
const INERT = [
18+
/^docs\//,
19+
/^\.(agents|cursor|vscode|devcontainer|macroscope|repos)\//,
20+
/^[^/]+\.md$/,
21+
/^LICENSE$/,
22+
];
23+
24+
// Run everything: the root vite.config.ts loads the first as setup for every
25+
// package's tests, and the vendored mobile tarballs are installed dependencies.
26+
const RUNS_EVERYTHING = [
27+
/^packages\/shared\/src\/(HostProcess|testing\/longTempDir)\.ts$/,
28+
/^apps\/mobile\/deps\//,
29+
];
30+
31+
// Paths outside a package, or files inside one that other packages read
32+
// through relative imports rather than a package.json dependency.
33+
const EXTRA_OWNERS = [
34+
// Vite configs and tsconfigs of these apps import scripts/lib directly.
35+
[/^scripts\/lib\//, ["@t3tools/desktop", "@t3tools/mobile", "@t3tools/web", "t3"]],
36+
// scripts/build-desktop-artifact.ts reads the GNOME extension manifest.
37+
[/^apps\/desktop\/gnome-extension\//, ["@t3tools/scripts"]],
38+
[/^native\/browser-secret\//, ["@t3tools/desktop"]],
39+
[/^native\/libghostty-vt\//, ["@t3tools/web"]],
40+
];
41+
const RUST = /^native\/(resource-monitor|kde-snap-shot|hyprland-snap-shot)\//;
42+
43+
// Tests that read another package's files without declaring it. The scripts
44+
// tests read app manifests, assets, and sources (cursor-sdk-packaging,
45+
// third-party-licenses, brand-assets, build-desktop-artifact).
46+
const TEST_ONLY_DEPS = {
47+
"@t3tools/provider-pi": ["@t3tools/client-runtime"],
48+
"@t3tools/scripts": [
49+
"@t3tools/desktop",
50+
"@t3tools/mobile",
51+
"@t3tools/web",
52+
"t3",
53+
"@t3tools/provider-cursor",
54+
],
55+
};
56+
// Declared dependencies that only feed a build step: the server bundles the
57+
// built web app (apps/server/vite.config.ts) but never imports it.
58+
const BUILD_ONLY_DEPS = { t3: ["@t3tools/web"] };
59+
60+
// Sources scripts/mobile-native-static-check.ts lints, plus the tool and rule
61+
// configuration that decides how it lints them, plus the root package.json
62+
// that defines the lint:mobile command.
63+
const MOBILE_NATIVE =
64+
/^apps\/mobile\/.*\.(swift|kt|kts)$|^apps\/mobile\/(\.swiftlint\.yml|detekt\.yml|\.editorconfig|Brewfile)$|^scripts\/mobile-native-static-check\.ts$|^package\.json$|^\.github\/workflows\/ci\.yml$|^\.github\/scripts\/ci-changes\.cjs$|^\.github\/actions\/ci-changes\//;
65+
66+
// Jobs that test every package except these, which have jobs of their own.
67+
const OWN_TEST_JOB = new Set(["t3", "@t3tools/web", "@t3tools/monorepo"]);
68+
69+
function readWorkspace() {
70+
const patterns = [];
71+
let inPackages = false;
72+
for (const line of fs.readFileSync(path.join(root, "pnpm-workspace.yaml"), "utf8").split("\n")) {
73+
if (/^\S/.test(line)) inPackages = line.startsWith("packages:");
74+
const entry = inPackages && line.match(/^\s+-\s+["']?([^"'\s]+)/);
75+
if (entry) patterns.push(entry[1]);
76+
}
77+
78+
const dirs = patterns.flatMap((pattern) => {
79+
if (!pattern.endsWith("/*")) return [pattern];
80+
const parent = pattern.slice(0, -2);
81+
return fs.readdirSync(path.join(root, parent)).map((name) => `${parent}/${name}`);
82+
});
83+
84+
const packages = [];
85+
for (const dir of dirs) {
86+
const manifestPath = path.join(root, dir, "package.json");
87+
if (!fs.existsSync(manifestPath)) continue;
88+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
89+
const deps = {
90+
...manifest.dependencies,
91+
...manifest.devDependencies,
92+
...manifest.peerDependencies,
93+
};
94+
packages.push({
95+
name: manifest.name,
96+
dir,
97+
hasTest: Boolean(manifest.scripts?.test),
98+
deps: Object.keys(deps).filter(
99+
(dep) =>
100+
String(deps[dep]).startsWith("workspace:") &&
101+
!BUILD_ONLY_DEPS[manifest.name]?.includes(dep),
102+
),
103+
});
104+
}
105+
return packages;
106+
}
107+
108+
// Returns the packages a path touches, [] for an inert path, or null when the
109+
// path is not understood and everything must run.
110+
function ownersOf(file, packages) {
111+
if (INERT.some((pattern) => pattern.test(file))) return [];
112+
// A manifest can change dependencies or versions other packages read.
113+
if (path.posix.basename(file) === "package.json") return null;
114+
if (RUNS_EVERYTHING.some((pattern) => pattern.test(file))) return null;
115+
// scripts/build-desktop-artifact.test.ts reads the crates' sources.
116+
if (RUST.test(file)) return ["@t3tools/scripts"];
117+
118+
const extra = EXTRA_OWNERS.flatMap(([pattern, names]) => (pattern.test(file) ? names : []));
119+
const owner = packages
120+
.filter((pkg) => file.startsWith(`${pkg.dir}/`))
121+
.sort((a, b) => b.dir.length - a.dir.length)[0];
122+
if (owner) return [owner.name, ...extra];
123+
return extra.length > 0 ? extra : null;
124+
}
125+
126+
function decide(files, packages, full) {
127+
const all = new Set(packages.map((pkg) => pkg.name));
128+
let affected = new Set();
129+
let everything = full || files === null;
130+
let rust = false;
131+
132+
for (const file of files ?? []) {
133+
if (RUST.test(file)) rust = true;
134+
const owners = ownersOf(file, packages);
135+
if (owners === null) {
136+
everything = true;
137+
console.error(`Runs everything: ${file}`);
138+
} else {
139+
for (const owner of owners) affected.add(owner);
140+
}
141+
}
142+
143+
// Release smoke reads scripts/ itself, not what the scripts tests read.
144+
let scriptsChanged = everything;
145+
if (everything) {
146+
affected = all;
147+
} else {
148+
// Add dependents until nothing changes.
149+
let grew = true;
150+
while (grew) {
151+
grew = false;
152+
for (const pkg of packages) {
153+
if (!affected.has(pkg.name) && pkg.deps.some((dep) => affected.has(dep))) {
154+
affected.add(pkg.name);
155+
grew = true;
156+
}
157+
}
158+
}
159+
scriptsChanged = affected.has("@t3tools/scripts");
160+
for (const [name, deps] of Object.entries(TEST_ONLY_DEPS)) {
161+
if (deps.some((dep) => affected.has(dep))) affected.add(name);
162+
}
163+
}
164+
165+
const tested = packages.filter(
166+
(pkg) => pkg.hasTest && !OWN_TEST_JOB.has(pkg.name) && affected.has(pkg.name),
167+
);
168+
const has = (name) => affected.has(name);
169+
170+
return {
171+
affected: [...affected].sort(),
172+
outputs: {
173+
typecheck: affected.size > 0,
174+
build: has("@t3tools/desktop") || has("t3") || has("@t3tools/web"),
175+
test: tested.length > 0,
176+
// Empty means every package the Test job covers.
177+
test_packages: everything ? "" : tested.map((pkg) => pkg.name).join(" "),
178+
test_web: has("@t3tools/web"),
179+
test_server: has("t3"),
180+
rust: everything || rust,
181+
release_smoke: scriptsChanged,
182+
mobile_native: files === null || files.some((file) => MOBILE_NATIVE.test(file)),
183+
},
184+
};
185+
}
186+
187+
function main() {
188+
const args = process.argv.slice(2);
189+
const pathsIndex = args.indexOf("--paths");
190+
const files =
191+
pathsIndex === -1
192+
? null
193+
: fs
194+
.readFileSync(args[pathsIndex + 1], "utf8")
195+
.split("\n")
196+
.filter(Boolean);
197+
const { affected, outputs } = decide(files, readWorkspace(), args.includes("--full"));
198+
199+
console.error(`Affected packages: ${affected.join(", ") || "none"}`);
200+
for (const [key, value] of Object.entries(outputs)) console.log(`${key}=${value}`);
201+
}
202+
203+
main();

0 commit comments

Comments
 (0)