Skip to content

Commit 798d656

Browse files
committed
Generate preview instances of the site on pull requests
1 parent 394b96c commit 798d656

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

justfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,21 @@ build settings="pelicanconf.py": prepare_fonts
3838
uv run pelican --fatal=errors -s {{settings}} -o output content
3939

4040
debug settings="pelicanconf.py": prepare_fonts
41-
uv run pelican --fatal=errors -s {{settings}} -o output content --debug
41+
uv run pelican --fatal=errors -s {{settings}} -o output content --debug --log-handler=plain
4242

4343
generate: (build "publishconf.py")
4444

45+
generate-debug: (debug "publishconf.py")
46+
47+
generate-for-preview: install-deps prepare_fonts
48+
#!/bin/bash
49+
set -e
50+
uv run pelican --fatal=errors\
51+
-s publishconf.py \
52+
-o output content \
53+
--debug --log-handler=plain \
54+
-e PHOTO_RESIZE_JOBS=1 "SITEURL=\"$DEPLOY_PRIME_URL\""
55+
4556
generate-dev: build
4657

4758
publish: generate upload invalidate

netlify.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[build]
2+
command = "just install-deps generate"
3+
publish = "output"
4+
# don't deploy on pushes to main
5+
ignore = "exit 0"
6+
7+
[build.environment]
8+
NODE_VERSION = "22"
9+
10+
[[plugins]]
11+
package = "./plugins/netlify-plugin-install-tools"
12+
13+
[context.deploy-preview]
14+
command = "just generate-for-preview"
15+
ignore = "exit 1"
16+
17+
[context.deploy-preview.environment]
18+
SITEURL = "$DEPLOY_PRIME_URL"
19+
NODE_VERSION = "22"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module.exports = {
2+
onPreBuild: async ({ utils }) => {
3+
const { run, build } = utils;
4+
5+
console.log("=== Installing build tools (mise, just, uv) ===");
6+
7+
try {
8+
// Check if mise is already installed (cached)
9+
const miseExists = await run.command(
10+
'command -v mise || echo "not-found"',
11+
{
12+
reject: false,
13+
},
14+
);
15+
16+
if (miseExists.stdout.includes("not-found")) {
17+
console.log("Installing mise...");
18+
await run.command("curl https://mise.run | sh");
19+
20+
// Add mise to PATH for subsequent commands
21+
process.env.PATH = `${process.env.HOME}/.local/bin:${process.env.PATH}`;
22+
} else {
23+
console.log("mise already installed (cached)");
24+
}
25+
26+
// Trust the mise configuration in this repo
27+
await run.command("mise trust");
28+
29+
// Install tools from mise.toml
30+
console.log("Installing tools from mise.toml...");
31+
await run.command("mise install");
32+
33+
// Install just and uv explicitly (latest versions)
34+
console.log("Installing just and uv...");
35+
await run.command("mise use just@latest");
36+
await run.command("mise use uv@latest");
37+
38+
// Activate mise environment for the build
39+
// This ensures just/uv are available in PATH
40+
await run.command("mise activate bash");
41+
42+
// Update PATH for the rest of the build
43+
const miseBinDir = `${process.env.HOME}/.local/share/mise/shims`;
44+
process.env.PATH = `${miseBinDir}:${process.env.PATH}`;
45+
46+
console.log("✓ Build tools installed successfully");
47+
} catch (error) {
48+
// Fail the build if tool installation fails
49+
build.failBuild("Failed to install build tools", { error });
50+
}
51+
},
52+
};
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name: netlify-plugin-install-tools
2+
inputs: []
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "netlify-plugin-install-tools",
3+
"version": "1.0.0",
4+
"description": "Installs mise, just, and uv for Netlify builds",
5+
"main": "index.js",
6+
"keywords": ["netlify", "netlify-plugin", "mise", "just", "uv"]
7+
}

publishconf.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22
# -*- coding: utf-8 -*- #
33
from __future__ import unicode_literals
44

5+
import multiprocessing
6+
57
# This file is only used if you use `make publish` or
68
# explicitly specify it as your config file.
7-
89
import os
910
import sys
10-
import multiprocessing
1111

1212
sys.path.append(os.curdir)
1313
from pelicanconf import * # noqa: F403, E402
1414

15-
SITEURL = "https://offby1.website"
15+
if "SITEURL" in os.environ:
16+
SITEURL = os.environ["SITEURL"]
17+
else:
18+
SITEURL = "https://offby1.website"
1619
RELATIVE_URLS = False
1720

1821
FEED_DOMAIN = SITEURL

0 commit comments

Comments
 (0)