-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
114 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: publish to github pages | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
|
||
# Cancel already running jobs | ||
concurrency: | ||
group: publish_to_pages_${{ github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
jobs: | ||
build: | ||
strategy: | ||
matrix: | ||
include: | ||
- name: Linux Publish | ||
runner: ubuntu-latest | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.setup_pages.outputs.base_url }} | ||
name: ${{ matrix.name }} | ||
runs-on: ${{ matrix.runner }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build website | ||
run: cargo run -p website | ||
- name: Upload pages | ||
uses: actions/upload-pages-artifact@v3 | ||
with: | ||
path: 'website/root' | ||
- name: Deploy pages | ||
uses: actions/deploy-pages@v4 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "website" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
subprocess.workspace = true | ||
anyhow.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use anyhow::{anyhow, Result}; | ||
use std::{path::Path, process::Command}; | ||
use subprocess::{Exec, Redirection}; | ||
|
||
fn main() { | ||
// Set standard path to root of repo so this always runs in the same directory, regardless of where the user ran it from. | ||
std::env::set_current_dir(Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap()).unwrap(); | ||
|
||
println!("Ensuring mdbook is installed"); | ||
if !Command::new("cargo") | ||
.args(["install", "mdbook", "--version", "0.4.43"]) | ||
.status() | ||
.unwrap() | ||
.success() | ||
{ | ||
return; | ||
} | ||
|
||
if let Err(err) = run() { | ||
println!("{err}"); | ||
} | ||
|
||
println!("Succesfully generated website"); | ||
} | ||
|
||
fn run() -> Result<()> { | ||
run_command("docs", "mdbook", &["test"])?; | ||
run_command("docs", "mdbook", &["build", "--dest-dir", "book/docs/main"])?; | ||
|
||
Ok(()) | ||
} | ||
|
||
pub fn run_command(dir: &str, command: &str, args: &[&str]) -> Result<String> { | ||
let data = Exec::cmd(command) | ||
.args(args) | ||
.cwd(dir) | ||
.stdout(Redirection::Pipe) | ||
.stderr(Redirection::Merge) | ||
.capture()?; | ||
|
||
if data.exit_status.success() { | ||
Ok(data.stdout_str()) | ||
} else { | ||
Err(anyhow!( | ||
"command {} {:?} exited with {:?} and output:\n{}", | ||
command, | ||
args, | ||
data.exit_status, | ||
data.stdout_str() | ||
)) | ||
} | ||
} |