Skip to content

Commit

Permalink
publish docs to /docs/main
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Nov 29, 2024
1 parent de0d1a3 commit 39ec80c
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 5 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/publish-main-to-pages.yaml
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
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
"test-helpers",
"custom-transforms-example",
"ec2-cargo",
"windsock-cloud-docker",
"windsock-cloud-docker", "website",
]
resolver = "2"

Expand Down
4 changes: 2 additions & 2 deletions docs/book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ title = "Shotover"

[output.html]

[output.linkcheck]
#[output.linkcheck]
# Should we check links on the internet? Enabling this option adds a
# non-negligible performance impact
follow-web-links = false
#follow-web-links = false

warning-policy = "error"
6 changes: 4 additions & 2 deletions docs/mdbook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ set -e; set -u
if [ ! -d "mdbook_bin" ]; then
mkdir -p mdbook_bin
pushd mdbook_bin
curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.13/mdbook-v0.4.13-x86_64-unknown-linux-gnu.tar.gz | tar xvz
wget https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/v0.7.6/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip -O linkcheck.zip
#curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.13/mdbook-v0.4.13-x86_64-unknown-linux-gnu.tar.gz | tar xvz
curl -L https://github.com/rust-lang/mdBook/releases/download/v0.4.13/mdbook-v0.4.13-x86_64-apple-darwin-gnu.tar.gz | tar -xvz
chmod +x mdbook
curl https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/download/v0.7.6/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip -o linkcheck.zip
unzip linkcheck.zip
chmod +x mdbook-linkcheck
popd
Expand Down
8 changes: 8 additions & 0 deletions website/Cargo.toml
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
52 changes: 52 additions & 0 deletions website/src/main.rs
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()
))
}
}

0 comments on commit 39ec80c

Please sign in to comment.