From 36552e8d7994e3723fd96999b631791658dc475e Mon Sep 17 00:00:00 2001 From: Ophir Lojkine Date: Mon, 23 Nov 2026 13:17:16 +0000 Subject: [PATCH 1/5] Use the same prepared official site for preview, tests, and deployment --- .github/workflows/ci.yml | 21 +++++++- .github/workflows/official-site.yml | 13 ++--- AGENTS.md | 13 +++-- CONTRIBUTING.md | 12 +++-- examples/official-site/Dockerfile | 4 +- examples/official-site/README.md | 13 +++++ examples/official-site/docker-compose.yml | 2 +- flake.nix | 1 + package.json | 3 +- scripts/site-build.mjs | 59 +++++++++++++++++++++++ tests/core/mod.rs | 45 ----------------- tests/end-to-end/official-site.spec.ts | 16 +++++- tests/end-to-end/playwright.config.ts | 2 +- 13 files changed, 135 insertions(+), 69 deletions(-) create mode 100644 scripts/site-build.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 496277efa..808d8bab7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,13 @@ jobs: save-if: ${{ github.ref == 'refs/heads/main' }} - run: cargo fmt --all -- --check - run: cargo clippy --all-targets --all-features -- -D warnings + - name: Prepare official website + run: npm run site:build + - name: Upload prepared website + uses: actions/upload-artifact@v7 + with: + name: official-site + path: target/official-site/ # The database matrix below runs the same Rust test harnesses against # different DATABASE_URL values. Package the Linux test executables once # here so those jobs do not recompile SQLPage or its dependencies. @@ -244,6 +251,11 @@ jobs: with: name: sqlpage-linux-debug path: ${{ runner.temp }}/sqlpage-bin + - name: Download prepared website + uses: actions/download-artifact@v8 + with: + name: official-site + path: target/official-site - name: Run Playwright tests run: | chmod +x "${{ runner.temp }}/sqlpage-bin/sqlpage" @@ -417,6 +429,7 @@ jobs: timeout-minutes: 15 needs: - docker_build + - compile_and_lint - hurl_examples strategy: fail-fast: false @@ -443,6 +456,12 @@ jobs: if [[ "$SQLPAGE_IMAGE_VARIANT" == minimal ]]; then docker tag "${{ env.REGISTRY_IMAGE }}:main" "${{ env.REGISTRY_IMAGE }}:latest" fi + - name: Download prepared website + if: matrix.example == 'examples/official-site' + uses: actions/download-artifact@v8 + with: + name: official-site + path: target/official-site - name: Run example Hurl test run: scripts/test-examples-hurl.sh "${{ matrix.example }}" @@ -521,7 +540,7 @@ jobs: docker buildx imagetools inspect "${REGISTRY_IMAGE}:${GITHUB_REF_NAME}${TAG_SUFFIX}" deploy_official_site: - needs: docker_push + needs: [compile_and_lint, docker_push] if: github.event_name == 'push' && github.ref == 'refs/heads/main' permissions: contents: read diff --git a/.github/workflows/official-site.yml b/.github/workflows/official-site.yml index cb28fcd80..efb2c473a 100644 --- a/.github/workflows/official-site.yml +++ b/.github/workflows/official-site.yml @@ -9,17 +9,14 @@ jobs: deploy_official_site: runs-on: ubuntu-latest steps: - - name: Cloning repo - uses: actions/checkout@v7 + - name: Download tested website + uses: actions/download-artifact@v8 with: - fetch-depth: 0 + name: official-site - id: get_gitsha - name: Make a commit for the official site + name: Package the site for Dokku run: | - cp -r examples/official-site /tmp/ - rm -rf * .[!.]* - cp -r /tmp/official-site/* . - git init . + git init --initial-branch=main . git config user.name "GitHub Actions Bot" git config user.email "<>" git add . diff --git a/AGENTS.md b/AGENTS.md index 953898163..a2cc6a4bd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -38,8 +38,11 @@ relevant tests and the formatting/lint checks in CONTRIBUTING.md before stopping Report unavailable checks and failures accurately; a test summary followed by a hung process is a failure. -The official site in `examples/official-site/` is rebuilt from its SQL migrations -on deployment. Update the existing page or documentation migration for changed -behavior; add a migration only for new documentation content. Document user-visible -changes there and in configuration.md when applicable. Add a concise CHANGELOG.md -entry only for user-visible changes, and never edit an already tagged release. +Update the existing page or documentation migration for changed behavior. Add a +migration only for new documentation content. + +Build and preview the official site with the commands in its [README](./examples/official-site/README.md). +Update `configuration.md` for configuration changes. + +Add a concise CHANGELOG.md entry only for user-visible changes, and never edit +an already tagged release. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 574ec089c..e55e268c6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,6 +56,7 @@ Keep formatting scoped to changed files. `npm test` checks formatting, lint, types, and frontend unit tests. Dynamic frontend changes also need Playwright: ```bash +npm run site:build cd tests/end-to-end npx playwright install --with-deps --only-shell chromium npm test @@ -74,6 +75,7 @@ The fixtures run on in-memory SQLite. To reproduce an issue with another databas For examples with `test.hurl`, run `scripts/test-examples-hurl.sh ''` from the repository root. +For the official site, run `npm run site:build` first. Integration tests use the shared request helpers in [tests/common](./tests/common/mod.rs) to exercise production routes and middleware and drain request pools. @@ -100,8 +102,10 @@ behavior and validation in the pull request. Keep changes and formatting focused Architectural constraints and documentation maintenance rules are in [AGENTS.md](./AGENTS.md). -User documentation lives in [the official-site SQL pages and migrations](./examples/official-site/). -Edit existing documentation in place: deployment recreates the site database. -Use nearby entries as examples rather than copying schemas into this guide. Update -[configuration.md](./configuration.md) for configuration changes and +Edit existing documentation in the [official site](./examples/official-site/) in place. +Deployment recreates the website's database from the site's SQL migrations. + +Run `npm run site` to preview changes using the same site build as deployment. + +Update [configuration.md](./configuration.md) for configuration changes and [CHANGELOG.md](./CHANGELOG.md) for user-visible changes in an unreleased version. diff --git a/examples/official-site/Dockerfile b/examples/official-site/Dockerfile index e7d8eb0fe..849b2861d 100644 --- a/examples/official-site/Dockerfile +++ b/examples/official-site/Dockerfile @@ -1,4 +1,4 @@ FROM lovasoa/sqlpage:main -COPY ./sqlpage /etc/sqlpage -COPY . /var/www \ No newline at end of file +COPY --chown=sqlpage:sqlpage ./sqlpage /etc/sqlpage +COPY --chown=sqlpage:sqlpage . /var/www diff --git a/examples/official-site/README.md b/examples/official-site/README.md index 39a528cb5..5c5fa9440 100644 --- a/examples/official-site/README.md +++ b/examples/official-site/README.md @@ -11,6 +11,19 @@ It is hosted as a simple Docker container on [sql-page.com](https://sql-page.com Feel free to [open a pull request](https://github.com/lovasoa/sqlpage/pulls) if you would like to add or change anything ! +## Preview and deployment + +Run `npm ci --ignore-scripts` from the repository root, then `npm run site`. +The preview uses the same build as CI and deployment. Rerun the command after editing the site. + +After `npm run build`, run `npm run site:build` to prepare the site under +`target/official-site/`. +Run SQLPage from that directory, or run +`docker compose -f examples/official-site/docker-compose.yml up --build` from +the repository root. + +## Landing page + The home page is rendered by `index.sql` and the `landing-page` custom template. Its styles, ES modules, model, lighting map, and static preview are under `assets/landing/`; no separate HTML entry point or frontend build is required. diff --git a/examples/official-site/docker-compose.yml b/examples/official-site/docker-compose.yml index 8e46ffc57..95ca5044e 100644 --- a/examples/official-site/docker-compose.yml +++ b/examples/official-site/docker-compose.yml @@ -1,5 +1,5 @@ services: web: - build: . + build: ../../target/official-site ports: - "8080:8080" diff --git a/flake.nix b/flake.nix index 62d37a252..a14acf604 100644 --- a/flake.nix +++ b/flake.nix @@ -207,6 +207,7 @@ packages = cargoRuntime pkgs; env = cargoEnv pkgs // playwrightEnv pkgs; script = inBrowserWorkspace '' + npm --prefix ../.. run site:build npx playwright test "$@" ''; }; diff --git a/package.json b/package.json index 752f16714..62cae9e5d 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "typecheck": "tsc && tsc -p tests/js && tsc -p tests/end-to-end", "format": "biome format --write .", "fix": "biome check --fix --unsafe .", - "site": "npm run build && cd examples/official-site && cargo run" + "site:build": "node scripts/site-build.mjs", + "site": "npm run build && npm run site:build && cd target/official-site && cargo run --locked --manifest-path ../../Cargo.toml" }, "repository": { "type": "git", diff --git a/scripts/site-build.mjs b/scripts/site-build.mjs new file mode 100644 index 000000000..96a3d5c90 --- /dev/null +++ b/scripts/site-build.mjs @@ -0,0 +1,59 @@ +import { + copyFileSync, + cpSync, + existsSync, + mkdirSync, + mkdtempSync, + renameSync, + rmSync, +} from "node:fs"; +import { dirname, join, relative, resolve } from "node:path"; + +const repository = resolve(import.meta.dirname, ".."); +const siteDirectory = join(repository, "target", "official-site"); +const source = join(repository, "examples", "official-site"); + +const excluded = new Set([ + "README.md", + "docker-compose.yml", + "test.hurl", + join("sqlpage", "sqlpage.db"), + join("sqlpage", "https"), +]); + +function buildSite() { + const parent = dirname(siteDirectory); + mkdirSync(parent, { recursive: true }); + const temporary = mkdtempSync(join(parent, ".official-site-")); + const next = join(temporary, "next"); + const previous = join(temporary, "previous"); + try { + cpSync(source, next, { + recursive: true, + filter: (file) => !excluded.has(relative(source, file)), + }); + copyFileSync( + join(repository, "configuration.md"), + join(next, "configuration.md"), + ); + // Stage the complete site before exchanging the previous preview. + try { + renameSync(siteDirectory, previous); + } catch (error) { + if (error.code !== "ENOENT") throw error; + } + try { + renameSync(next, siteDirectory); + } catch (error) { + if (!existsSync(siteDirectory) && existsSync(previous)) { + renameSync(previous, siteDirectory); + } + throw error; + } + console.log(`Prepared ${siteDirectory}`); + } finally { + rmSync(temporary, { force: true, recursive: true }); + } +} + +buildSite(); diff --git a/tests/core/mod.rs b/tests/core/mod.rs index 592360646..a3f2591e2 100644 --- a/tests/core/mod.rs +++ b/tests/core/mod.rs @@ -204,48 +204,3 @@ async fn test_hidden_files() { .contains("forbidden"), ); } - -#[actix_web::test] -async fn test_official_website_documentation() { - let app_data = make_app_data_for_official_website().await; - let resp = response_with_data("/component.sql?component=button", app_data) - .await - .unwrap_or_else(|e| { - panic!("Failed to get response for /component.sql?component=button: {e}") - }); - assert_eq!(resp.status(), StatusCode::OK); - let body_str = crate::common::read_body_string(resp).await; - assert!( - body_str.contains(r#"