Skip to content

Commit d43d716

Browse files
authored
feat: versioned docs (#414)
(Finally) sets up versioned docs with a version selector. we deploy on every push to `main` on the `main` tag, and on every release on the tag of that release + update `latest` this finally fixes the issue we were having around missing schema files. tested it on a fork. :) Todo - [x] update schema url in default config - [x] Before merging: delete gh-pages branch closes #312 fixes #319
1 parent 3698af5 commit d43d716

File tree

7 files changed

+29
-485
lines changed

7 files changed

+29
-485
lines changed

.github/workflows/deploy_docs.yml

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: Build and Deploy Documentation
22

33
on:
4+
push:
5+
branches:
6+
- main
47
release:
5-
types: [released]
6-
workflow_dispatch:
8+
types: [published]
79

810
permissions:
911
contents: write
@@ -13,25 +15,34 @@ permissions:
1315
jobs:
1416
build:
1517
runs-on: ubuntu-latest
16-
1718
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v4
19+
- uses: actions/checkout@v4
2020
with:
2121
fetch-depth: 0
2222

2323
- name: Install uv
2424
uses: astral-sh/setup-uv@v5
2525
with:
26-
enable-cache: true
26+
enable-cache: true
2727

2828
- name: Set up Python
2929
run: uv python install
3030

3131
- name: Install the project
3232
run: uv sync --all-extras --dev
3333

34-
- run: uv run mkdocs gh-deploy --force
34+
- name: Configure Git
35+
run: |
36+
git config user.name 'github-actions[bot]'
37+
git config user.email 'github-actions[bot]@users.noreply.github.com'
38+
39+
- name: Build Docs Website
40+
run: |
41+
if [ "${{ github.event_name }}" = "release" ]; then
42+
uv run mike deploy --push --update-aliases ${{ github.event.release.tag_name }} latest
43+
else
44+
uv run mike deploy --push main
45+
fi
3546
3647
deploy:
3748
needs: build
@@ -44,12 +55,16 @@ jobs:
4455
uses: actions/checkout@v4
4556
with:
4657
ref: gh-pages
58+
4759
- name: Setup Pages
4860
uses: actions/configure-pages@v5
61+
4962
- name: Upload artifact
5063
uses: actions/upload-pages-artifact@v3
5164
with:
5265
path: '.'
66+
5367
- name: Deploy to GitHub Pages
5468
id: deployment
5569
uses: actions/deploy-pages@v4
70+

crates/pgt_workspace/src/configuration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ pub fn create_config(
186186
configuration.schema = node_schema_path.to_str().map(String::from);
187187
} else if VERSION == "0.0.0" {
188188
// VERSION is 0.0.0 if it has not been explicitly set (e.g local dev, as fallback)
189-
configuration.schema = Some("https://pgtools.dev/schemas/latest/schema.json".to_string());
189+
configuration.schema = Some("https://pgtools.dev/latest/schema.json".to_string());
190190
} else {
191-
configuration.schema = Some(format!("https://pgtools.dev/schemas/{VERSION}/schema.json"));
191+
configuration.schema = Some(format!("https://pgtools.dev/{VERSION}/schema.json"));
192192
}
193193

194194
let contents = serde_json::to_string_pretty(&configuration)

docs/codegen/src/schema.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use pgt_configuration::{PartialConfiguration, VERSION};
1+
use pgt_configuration::PartialConfiguration;
22
use schemars::{
33
schema::{RootSchema, Schema, SchemaObject},
44
schema_for,
@@ -10,25 +10,10 @@ use std::{fs, path::Path};
1010
///
1111
/// * `docs_dir`: Path to the docs directory.
1212
pub fn generate_schema(docs_dir: &Path) -> anyhow::Result<()> {
13-
let schemas_dir = docs_dir.join("schemas");
14-
let latest_schema_dir = schemas_dir.join("latest");
15-
let latest_schema_path = latest_schema_dir.join("schema.json");
16-
17-
let version_schema_dir = schemas_dir.join(VERSION);
18-
let version_schema_path = version_schema_dir.join("schema.json");
19-
20-
if !latest_schema_dir.exists() {
21-
fs::create_dir_all(&latest_schema_dir)?;
22-
}
23-
24-
if !version_schema_dir.exists() {
25-
fs::create_dir_all(&version_schema_dir)?;
26-
}
27-
13+
let schema_path = docs_dir.join("schema.json");
2814
let schema_content = get_configuration_schema_content()?;
2915

30-
fs::write(latest_schema_path, &schema_content)?;
31-
fs::write(version_schema_path, &schema_content)?;
16+
fs::write(schema_path, &schema_content)?;
3217

3318
Ok(())
3419
}
File renamed without changes.

0 commit comments

Comments
 (0)