diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 1deb4774..bfad3921 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -66,7 +66,7 @@ jobs: uses: actions-rs/cargo@v1 with: command: run - args: --bin tests-migrate + args: --bin tests-migrate -- --build env: DATABASE_URL: postgres://postgres:password@localhost:5432/postgres diff --git a/Cargo.toml b/Cargo.toml index 8fe3b615..2d34dd1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,6 +65,8 @@ rand = "0.8" sailfish = "0.3.2" +mime = "0.3.16" + [build-dependencies] serde_yaml = "0.8.17" serde_json = "1" diff --git a/src/docs.rs b/src/docs.rs index c00b892d..f0b6a968 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -35,7 +35,7 @@ pub mod routes { impl Docs { pub const fn new() -> Self { Docs { - home: "/docs/", + home: "/docs", spec: "/docs/openapi.json", assets: "/docs/{_:.*}", } @@ -84,6 +84,7 @@ async fn spec() -> HttpResponse { } async fn index() -> HttpResponse { + println!("getting index"); handle_embedded_file("index.html") } diff --git a/src/tests-migrate.rs b/src/tests-migrate.rs index 377c6157..588b0948 100644 --- a/src/tests-migrate.rs +++ b/src/tests-migrate.rs @@ -14,6 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +use std::env; use lazy_static::lazy_static; @@ -32,8 +33,57 @@ lazy_static! { #[cfg(not(tarpaulin_include))] #[actix_rt::main] async fn main() { - pretty_env_logger::init(); let data = Data::new().await; + for arg in env::args() { + if arg == "--build" { + println!("Building cache buster config"); + build(); + } + } + sqlx::migrate!("./migrations/").run(&data.db).await.unwrap(); } + +fn build() { + use std::process::Command; + + // note: add error checking yourself. + let output = Command::new("git") + .args(&["rev-parse", "HEAD"]) + .output() + .unwrap(); + let git_hash = String::from_utf8(output.stdout).unwrap(); + println!("cargo:rustc-env=GIT_HASH={}", git_hash); + + let yml = include_str!("../openapi.yaml"); + let api_json: serde_json::Value = serde_yaml::from_str(yml).unwrap(); + println!( + "cargo:rustc-env=OPEN_API_DOCS={}", + serde_json::to_string(&api_json).unwrap() + ); + cache_bust(); +} + +fn cache_bust() { + use cache_buster::BusterBuilder; + let types = vec![ + mime::IMAGE_PNG, + mime::IMAGE_SVG, + mime::IMAGE_JPEG, + mime::IMAGE_GIF, + mime::APPLICATION_JAVASCRIPT, + mime::TEXT_CSS, + ]; + + let config = BusterBuilder::default() + .source("./static-assets") + .result("./static") + .mime_types(types) + .copy(true) + .follow_links(true) + .build() + .unwrap(); + + config.process().unwrap(); +} diff --git a/templates/panel/header/sidebar/index.html b/templates/panel/header/sidebar/index.html index f1d019ad..0996ba8d 100644 --- a/templates/panel/header/sidebar/index.html +++ b/templates/panel/header/sidebar/index.html @@ -65,7 +65,7 @@
  • - + " alt="" />
    API Docs