From 39ec80c486b77e4c0751e711e131e4e7f0769d25 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Thu, 28 Nov 2024 16:43:08 +1100 Subject: [PATCH] publish docs to /docs/main --- .github/workflows/publish-main-to-pages.yaml | 39 +++++++++++++++ Cargo.lock | 8 +++ Cargo.toml | 2 +- docs/book.toml | 4 +- docs/mdbook.sh | 6 ++- website/Cargo.toml | 8 +++ website/src/main.rs | 52 ++++++++++++++++++++ 7 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/publish-main-to-pages.yaml create mode 100644 website/Cargo.toml create mode 100644 website/src/main.rs diff --git a/.github/workflows/publish-main-to-pages.yaml b/.github/workflows/publish-main-to-pages.yaml new file mode 100644 index 000000000..c3f75954a --- /dev/null +++ b/.github/workflows/publish-main-to-pages.yaml @@ -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 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 038791f70..ff31f3b7a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5804,6 +5804,14 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "website" +version = "0.1.0" +dependencies = [ + "anyhow", + "subprocess", +] + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 366e90819..b9cc28acf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ members = [ "test-helpers", "custom-transforms-example", "ec2-cargo", - "windsock-cloud-docker", + "windsock-cloud-docker", "website", ] resolver = "2" diff --git a/docs/book.toml b/docs/book.toml index ab99a4289..49bcb55f2 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -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" diff --git a/docs/mdbook.sh b/docs/mdbook.sh index 0593744e9..60b12782c 100755 --- a/docs/mdbook.sh +++ b/docs/mdbook.sh @@ -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 diff --git a/website/Cargo.toml b/website/Cargo.toml new file mode 100644 index 000000000..722f14ea0 --- /dev/null +++ b/website/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "website" +version = "0.1.0" +edition = "2021" + +[dependencies] +subprocess.workspace = true +anyhow.workspace = true diff --git a/website/src/main.rs b/website/src/main.rs new file mode 100644 index 000000000..d6915cb11 --- /dev/null +++ b/website/src/main.rs @@ -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 { + 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() + )) + } +}