CI: coverage build step

This commit is contained in:
realaravinth
2021-05-08 13:59:13 +05:30
parent 5466d1f136
commit 9809cb7bea
5 changed files with 57 additions and 4 deletions

View File

@@ -66,7 +66,7 @@ jobs:
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
command: run command: run
args: --bin tests-migrate args: --bin tests-migrate -- --build
env: env:
DATABASE_URL: postgres://postgres:password@localhost:5432/postgres DATABASE_URL: postgres://postgres:password@localhost:5432/postgres

View File

@@ -65,6 +65,8 @@ rand = "0.8"
sailfish = "0.3.2" sailfish = "0.3.2"
mime = "0.3.16"
[build-dependencies] [build-dependencies]
serde_yaml = "0.8.17" serde_yaml = "0.8.17"
serde_json = "1" serde_json = "1"

View File

@@ -35,7 +35,7 @@ pub mod routes {
impl Docs { impl Docs {
pub const fn new() -> Self { pub const fn new() -> Self {
Docs { Docs {
home: "/docs/", home: "/docs",
spec: "/docs/openapi.json", spec: "/docs/openapi.json",
assets: "/docs/{_:.*}", assets: "/docs/{_:.*}",
} }
@@ -84,6 +84,7 @@ async fn spec() -> HttpResponse {
} }
async fn index() -> HttpResponse { async fn index() -> HttpResponse {
println!("getting index");
handle_embedded_file("index.html") handle_embedded_file("index.html")
} }

View File

@@ -14,6 +14,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
use std::env;
use lazy_static::lazy_static; use lazy_static::lazy_static;
@@ -32,8 +33,57 @@ lazy_static! {
#[cfg(not(tarpaulin_include))] #[cfg(not(tarpaulin_include))]
#[actix_rt::main] #[actix_rt::main]
async fn main() { async fn main() {
pretty_env_logger::init();
let data = Data::new().await; 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(); 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();
}

View File

@@ -65,7 +65,7 @@
</a> </a>
</li> </li>
<li class="secondary-menu__item"> <li class="secondary-menu__item">
<a class="secondary-menu__item-link" href="<.= crate::DOCS.home .>"> <a class="secondary-menu__item-link" href="<.= crate::DOCS.home .>/">
<img class="secondary-menu__icon" src="<.= crate::FILES.get("./static-assets/img/svg/file-text.svg").unwrap() .>" alt="" /> <img class="secondary-menu__icon" src="<.= crate::FILES.get("./static-assets/img/svg/file-text.svg").unwrap() .>" alt="" />
<div class="secondary-menu__item-name"> <div class="secondary-menu__item-name">
API Docs API Docs