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
123 changes: 64 additions & 59 deletions .github/workflows/preview-fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
workflow_dispatch:

permissions:
contents: write
contents: read

concurrency:
group: preview-fixtures
Expand All @@ -15,15 +15,20 @@ concurrency:
jobs:
refresh:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: auto
R2_BUCKET: ${{ secrets.R2_BUCKET }}
R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }}
steps:
# The main ruleset exempts this deploy key, because it cannot exempt the workflow token.
- uses: actions/checkout@v7
- name: Check out main
uses: actions/checkout@v7
with:
ref: main
fetch-depth: 0
ssh-key: ${{ secrets.MAIN_PUSH_KEY }}

- run: rustup install --no-self-update
- name: Install Rust
run: rustup install --no-self-update

- name: Install system dependencies
run: |
Expand All @@ -34,65 +39,65 @@ jobs:
librsvg2-dev \
patchelf

- uses: oven-sh/setup-bun@v2
- name: Install Bun
uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- run: bun install --frozen-lockfile

- name: Snapshot, verify and publish
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
set -euo pipefail

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

must() {
"$@" || { echo "::error::preview fixture step failed: $*"; exit 1; }
}

must_in() {
local directory="$1"
shift
(cd "$directory" && "$@") ||
{ echo "::error::preview fixture step failed in $directory: $*"; exit 1; }
}
- name: Install dependencies
run: bun install --frozen-lockfile

attempt_publish() {
must git fetch origin main
must git reset --hard origin/main

# Live ModWorkshop data at the app's own rate limit: five games take a few minutes.
must_in apps/desktop/src-tauri cargo test --test export_preview_fixtures -- --ignored --nocapture
- name: Install AWS CLI
run: |
curl -fsSL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
unzip -q awscliv2.zip
sudo ./aws/install --update

# Publish only a snapshot that the browser preview can render.
must_in apps/desktop bun --bun run test:preview
# The exporter keeps the previous news file when the news site blocks the runner.
- name: Download current snapshot
run: |
set -euo pipefail
aws s3 sync "s3://${R2_BUCKET}/preview/" apps/desktop/src/renderer/preview/fixtures/ \
--endpoint-url "${R2_ENDPOINT}" --exclude manifest.json

must git add apps/desktop/src/renderer/preview/fixtures
if git diff --cached --quiet; then
echo "Fixtures are already current."
return 0
fi
must git commit -m "chore(desktop): refresh preview fixtures"
- name: Export snapshot
working-directory: apps/desktop/src-tauri
env:
PREVIEW_FIXTURES_DIR: ${{ github.workspace }}/apps/desktop/src/renderer/preview/fixtures
run: |
set -euo pipefail
# Live ModWorkshop data at the app's own rate limit: five games take a few minutes.
cargo test --test export_preview_fixtures -- --ignored --nocapture

# Never force: a concurrent main update keeps its commit, and the next
# attempt rebuilds the fixtures and tests them on that new revision.
if git push origin HEAD:main; then
return 0
fi
echo "main advanced during this run; recomputing from fresh main."
return 1
}
# Publish only a snapshot that the browser preview can render.
- name: Verify snapshot
working-directory: apps/desktop
env:
PREVIEW_FIXTURES_READY: '1'
run: |
set -euo pipefail
bun --bun run test:preview

for attempt in 1 2 3; do
echo "::group::Attempt $attempt"
if attempt_publish; then
echo "::endgroup::"
exit 0
fi
echo "::endgroup::"
done
- name: Write manifest
working-directory: apps/desktop/src/renderer/preview/fixtures
run: |
set -euo pipefail
find . -type f -name '*.json' | sed 's|^\./||' | sort | jq -R . | jq -s . > "$RUNNER_TEMP/manifest.json"
[ "$(jq length "$RUNNER_TEMP/manifest.json")" -gt 0 ] || { echo "::error::snapshot is empty"; exit 1; }

echo "main kept advancing; leaving the next scheduled run to publish."
exit 1
- name: Upload snapshot and manifest
run: |
set -euo pipefail
aws s3 cp apps/desktop/src/renderer/preview/fixtures/ "s3://${R2_BUCKET}/preview/" \
--recursive --endpoint-url "${R2_ENDPOINT}" \
--content-type application/json --cache-control 'no-cache'
aws s3 cp "$RUNNER_TEMP/manifest.json" "s3://${R2_BUCKET}/preview/manifest.json" \
--endpoint-url "${R2_ENDPOINT}" \
--content-type application/json --cache-control 'no-cache'

- name: Trigger preview rebuild
env:
DEPLOY_HOOK_URL: ${{ secrets.CLOUDFLARE_APP_PREVIEW_DEPLOY_HOOK_URL }}
run: |
set -euo pipefail
curl -fsS -X POST "${DEPLOY_HOOK_URL}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,5 @@ out/
apps/index/index.db*
apps/index/builder-state.db*
apps/index/index-stats.json

apps/desktop/src/renderer/preview/fixtures/
11 changes: 7 additions & 4 deletions apps/desktop/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bun lint # oxlint on renderer source and scripts
bun lint:fix # oxlint with auto-fix
bun run test # Run all tests: Rust (cargo test) then renderer (vitest)
bun test:renderer # Run only renderer TypeScript tests (vitest)
cd src-tauri && cargo test --test export_preview_fixtures -- --ignored # Refresh preview fixtures from live modworkshop
cd src-tauri && cargo test --test export_preview_fixtures -- --ignored # Export live ModWorkshop data locally, or to PREVIEW_FIXTURES_DIR when set
bun generate-licenses # Regenerate THIRD_PARTY_LICENSES.md (run after adding/updating deps)
cargo clippy # Rust lints (run from src-tauri/); the tree is clippy-clean and CI enforces it with -D warnings — any warning is signal. Deliberate exceptions carry #[allow] at the site (too_many_arguments on the four archive-install commands, dead_code on the unwired ue4ss_modstxt read helpers)
cargo fmt # Format Rust code (run from src-tauri/)
Expand All @@ -51,9 +51,12 @@ combination. `library`, `network`, `games`, and `onboarding` are parsed and vali
dimension that owns the behavior, and add a new dimension only for a genuinely independent state.
Do not add cross-product names such as `offline-large-library`.

Remote browse content is generated by `src-tauri/src/preview_fixtures.rs` and refreshed by
`preview-fixtures.yml`. Installed-library volume profiles are generated deterministically from those
records in `preview/library.ts`; do not hand-author large JSON libraries. The old `?scenario=` values
Remote browse content is generated by `src-tauri/src/preview_fixtures.rs`, published to R2 by
`preview-fixtures.yml`, and never committed: the preview, renderer test and renderer typecheck scripts download it from
`https://index.modrex.net/preview/` into the ignored fixtures directory, and `PREVIEW_FIXTURES_READY=1`
skips the download to test a local export. Installed-library volume profiles are generated
deterministically from those records in `preview/library.ts`; do not hand-author large JSON
libraries. The old `?scenario=` values
remain read-only compatibility aliases for shared links and must not gain new states.

Optional dev tooling (machine setup, not required by any script or CI): `cargo nextest run` (inside `src-tauri/`) is a faster drop-in test runner with the same name-filter syntax (`cargo nextest run strip_priority`); CI stays on `cargo test`. `sccache` is configured machine-wide as the rustc wrapper (`~/.cargo/config.toml`: `[build] rustc-wrapper = "sccache"`) so dependency compiles are cached across clones (`modrex-main`, `modrex-main-nexus`); delete that line to disable it if a toolchain issue is ever suspected.
Expand Down
10 changes: 5 additions & 5 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"scripts": {
"dev": "tauri dev",
"dev-renderer": "vite",
"dev-preview": "vite --mode preview",
"dev-preview": "bun scripts/preview-fixtures.mts && vite --mode preview",
"build": "tauri build --config src-tauri/tauri.local.conf.json",
"build:signed": "tauri build --config src-tauri/tauri.release.conf.json",
"build-renderer": "vite build",
"build-preview": "vite build --mode preview",
"build-preview": "bun scripts/preview-fixtures.mts && vite build --mode preview",
"dist": "tauri build --config src-tauri/tauri.local.conf.json",
"dist:win": "tauri build --target x86_64-pc-windows-msvc --config src-tauri/tauri.local.conf.json",
"dist:linux": "tauri build --target x86_64-unknown-linux-gnu --config src-tauri/tauri.local.conf.json",
Expand Down Expand Up @@ -40,14 +40,14 @@
"preversion": "bun -e \"console.error('Run bun release patch, minor, or major from the repository root.'); process.exit(1)\"",
"test": "bun run test:scripts && cargo test --manifest-path src-tauri/Cargo.toml && vitest run && bun run test:preview",
"test:scripts": "bun test --timeout 60000 ./scripts",
"test:renderer": "vitest run",
"test:preview": "vitest run --config vitest.preview.config.ts",
"test:renderer": "bun scripts/preview-fixtures.mts && vitest run",
"test:preview": "bun scripts/preview-fixtures.mts && vitest run --config vitest.preview.config.ts",
"format": "bun fmt --no-script",
"format:check": "bun fmt --no-script --check",
"lint": "oxlint src/renderer/src src/renderer/preview src/shared/i18n-values.mts scripts/*.mts",
"lint:fix": "oxlint src/renderer/src src/renderer/preview src/shared/i18n-values.mts scripts/*.mts --fix",
"generate-licenses": "bun scripts/generate-licenses.mts",
"typecheck:renderer": "bun check",
"typecheck:renderer": "bun scripts/preview-fixtures.mts && bun check",
"typecheck:config": "bun check -p tsconfig.config.json",
"typecheck:i18n": "bun check -p tsconfig.i18n.json"
},
Expand Down
38 changes: 38 additions & 0 deletions apps/desktop/scripts/preview-fixtures.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mkdir, writeFile } from 'node:fs/promises'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'

const baseUrl = 'https://index.modrex.net/preview/'
const fixturesDir = fileURLToPath(new URL('../src/renderer/preview/fixtures/', import.meta.url))

async function download(path: string): Promise<Response> {
const url = new URL(path, baseUrl)
const response = await fetch(url).catch((cause: unknown) => {
throw new Error(`Failed to download ${url}`, { cause })
})
if (!response.ok) {
throw new Error(`Failed to download ${url}: ${response.status} ${response.statusText}`)
}
return response
}

// The refresh workflow tests a fresh export before uploading it, so the download must not overwrite it.
if (process.env.PREVIEW_FIXTURES_READY !== '1') {
const manifest: unknown = await (await download('manifest.json')).json()
if (
!Array.isArray(manifest) ||
manifest.length === 0 ||
!manifest.every(
(path): path is string =>
typeof path === 'string' && /^(?:[\w-]+\/)*[\w-]+\.json$/.test(path)
)
) {
throw new Error(`Invalid fixture manifest at ${baseUrl}manifest.json`)
}
for (const path of manifest) {
const response = await download(path)
const destination = join(fixturesDir, path)
await mkdir(dirname(destination), { recursive: true })
await writeFile(destination, new Uint8Array(await response.arrayBuffer()))
}
}
16 changes: 11 additions & 5 deletions apps/desktop/src-tauri/src/preview_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ use crate::game_package::SourceBinding;
const FIXTURES_DIR: &str = "../src/renderer/preview/fixtures";
const LISTING_LIMIT: u32 = 24;

fn fixtures_dir() -> std::path::PathBuf {
std::env::var_os("PREVIEW_FIXTURES_DIR")
.map(std::path::PathBuf::from)
.unwrap_or_else(|| std::path::PathBuf::from(FIXTURES_DIR))
}

#[derive(Serialize)]
struct ModRecord {
detail: ModDetail,
Expand All @@ -26,7 +32,7 @@ async fn get(path: &str, query: &[(&str, &str)]) -> Value {
}

fn write<T: Serialize>(name: &str, value: &T) {
let path = std::path::PathBuf::from(format!("{FIXTURES_DIR}/{name}.json"));
let path = fixtures_dir().join(format!("{name}.json"));
let dir = path.parent().expect("fixture path has a parent");
std::fs::create_dir_all(dir).unwrap_or_else(|e| panic!("cannot create {}: {e}", dir.display()));
let mut text = Vec::new();
Expand Down Expand Up @@ -73,16 +79,16 @@ pub fn export_preview_fixtures() {
let folders = crate::commands::mods::list_mod_folders(game_id.to_string())
.unwrap_or_else(|e| panic!("{game_id} mod folders: {e}"));
write(&format!("{game_id}/mod-folders"), &folders);
// The news site blocks datacenter runners, so a failed fetch keeps the committed
// The news site blocks datacenter runners, so a failed fetch keeps the existing
// snapshot instead of failing the refresh of every other fixture.
if !package.news.is_empty() {
match crate::commands::news::fetch_news_page(game_id.to_string(), 1).await {
Ok(news) => write(&format!("{game_id}/news"), &news),
Err(e) => {
let kept = format!("{FIXTURES_DIR}/{game_id}/news.json");
let kept = fixtures_dir().join(format!("{game_id}/news.json"));
assert!(
std::path::Path::new(&kept).exists(),
"{game_id} news: {e}, and no committed snapshot exists to keep"
kept.exists(),
"{game_id} news: {e}, and no previous snapshot exists to keep"
);
println!("::warning::{game_id} news kept from the last snapshot: {e}");
}
Expand Down
Loading
Loading