From 3f37790f122243366e1d26802b14e95d20f4d7ad 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-to-pages.yaml | 41 +++++++++++++++ .gitignore | 1 + Cargo.lock | 8 +++ Cargo.toml | 1 + docs/book.toml | 4 +- docs/mdbook.sh | 6 ++- website/Cargo.toml | 10 ++++ website/src/main.rs | 68 +++++++++++++++++++++++++ 8 files changed, 135 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/publish-to-pages.yaml create mode 100644 website/Cargo.toml create mode 100644 website/src/main.rs diff --git a/.github/workflows/publish-to-pages.yaml b/.github/workflows/publish-to-pages.yaml new file mode 100644 index 000000000..14f868d2c --- /dev/null +++ b/.github/workflows/publish-to-pages.yaml @@ -0,0 +1,41 @@ +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: Setup Pages + uses: actions/configure-pages@v4 + - 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/.gitignore b/.gitignore index 7b69c6476..218ac7692 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ /.project /docs/book /docs/mdbook_bin +/website/root /shotover-proxy/build/packages /some_local_file /test-helpers/src/connection/kafka/node/node_modules \ 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..f355d903e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ members = [ "custom-transforms-example", "ec2-cargo", "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..e7e6e7c81 --- /dev/null +++ b/website/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "website" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +publish = false + +[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..6bf594603 --- /dev/null +++ b/website/src/main.rs @@ -0,0 +1,68 @@ +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. + let current_dir = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap(); + std::env::set_current_dir(current_dir).unwrap(); + + println!("Ensuring mdbook is installed"); + // TODO: Once mdbook starts doing macos aarch64 binary releases we should download the release directly instead of compiling. + // https://github.com/rust-lang/mdBook/pull/2500 + if !Command::new("cargo") + .args(["install", "mdbook", "--version", "0.4.43"]) + .status() + .unwrap() + .success() + { + return; + } + + if let Err(err) = run() { + println!("{err}"); + } + + let out = current_dir + .join("website") + .join("root") + .join("docs") + .join("main") + .join("index.html"); + println!( + "Succesfully generated website at: file://{}", + out.to_str().unwrap() + ); +} + +fn run() -> Result<()> { + run_command("docs", "mdbook", &["test"])?; + run_command( + "docs", + "mdbook", + &["build", "--dest-dir", "../website/root/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() + )) + } +}