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
21 changes: 20 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -417,6 +429,7 @@ jobs:
timeout-minutes: 15
needs:
- docker_build
- compile_and_lint
- hurl_examples
strategy:
fail-fast: false
Expand All @@ -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 }}"

Expand Down Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/official-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
13 changes: 8 additions & 5 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 '<example-path>'` 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.
Expand All @@ -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.
4 changes: 2 additions & 2 deletions examples/official-site/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM lovasoa/sqlpage:main

COPY ./sqlpage /etc/sqlpage
COPY . /var/www
COPY --chown=sqlpage:sqlpage ./sqlpage /etc/sqlpage
COPY --chown=sqlpage:sqlpage . /var/www
13 changes: 13 additions & 0 deletions examples/official-site/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/official-site/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
services:
web:
build: .
build: ../../target/official-site
ports:
- "8080:8080"
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
packages = cargoRuntime pkgs;
env = cargoEnv pkgs // playwrightEnv pkgs;
script = inBrowserWorkspace ''
npm --prefix ../.. run site:build
npx playwright test "$@"
'';
};
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
59 changes: 59 additions & 0 deletions scripts/site-build.mjs
Original file line number Diff line number Diff line change
@@ -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();
45 changes: 0 additions & 45 deletions tests/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"<button type="submit" form="poem" formaction="?action"#),
"{body_str}\nexpected to contain a button with formaction"
);
}

#[actix_web::test]
async fn test_official_website_basic_auth_example() {
let resp = response_with_data(
"/examples/authentication/basic_auth.sql",
make_app_data_for_official_website().await,
)
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::UNAUTHORIZED);
let body_str = crate::common::read_body_string(resp).await;
assert!(
body_str.contains("Unauthorized"),
"{body_str}\nexpected to contain Unauthorized"
);
}

async fn make_app_data_for_official_website() -> actix_web::web::Data<AppState> {
crate::common::init_log();
let config_path = std::path::Path::new("examples/official-site/sqlpage");
let mut app_config = sqlpage::app_config::load_from_directory(config_path).unwrap();
app_config.web_root = std::path::PathBuf::from("examples/official-site");
app_config.database_url = "sqlite::memory:".to_string();
let app_state = make_app_data_from_config(app_config.clone()).await.unwrap();
webserver::database::migrations::apply(&app_config, &app_state.db)
.await
.unwrap();
app_state
}
16 changes: 15 additions & 1 deletion tests/end-to-end/official-site.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ test("Open documentation", async ({ page }) => {
await expect(
example.getByRole("link", { name: "The list component" }),
).toBeVisible();

const response = await page.goto("/component.sql?component=button");
expect(response?.status()).toBe(200);
await expect(
page
.locator('button[type="submit"][form="poem"][formaction^="?action"]')
.first(),
).toBeVisible();
});

async function expectContrast(
Expand Down Expand Up @@ -674,7 +682,13 @@ test("login labels target the fields in their own example", async ({
);
});

test("Authentication example", async ({ page }) => {
test("Authentication example", async ({ page, request }) => {
const unauthorized = await request.get(
"/examples/authentication/basic_auth.sql",
);
expect(unauthorized.status()).toBe(401);
expect(await unauthorized.text()).toContain("Unauthorized");

await page.goto("/examples/authentication/login.sql");
await expect(page.locator("h1", { hasText: "Authentication" })).toBeVisible();

Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default defineConfig({
{
name: "official site",
command: sqlpage,
cwd: "../../examples/official-site",
cwd: path.join(repository, "target", "official-site"),
env: { SQLPAGE_LISTEN_ON: listenOn(18080) },
wait: { stderr: officialSite.announcement },
timeout: compileAndStart,
Expand Down
Loading