Fix advisory CI

This commit is contained in:
Folyd 2023-03-22 23:00:54 +08:00
parent 3b9796a8a3
commit 9b27c12fea
3 changed files with 17 additions and 17 deletions

View file

@ -20,6 +20,5 @@ jobs:
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
git clone --depth 1 https://github.com/jplatte/caniuse.rs.git /tmp/caniuse
git clone --depth 1 https://github.com/nrc/rfc-index.git /tmp/rfcs
git clone --depth 1 https://github.com/rustsec/advisory-db.git /tmp/advisory-db
- name: Deloy docs
run: ./scripts/deploy-docs.sh

View file

@ -1,7 +1,7 @@
use std::{collections::HashMap, io::Write, path::Path};
use argh::FromArgs;
use rustsec::{database::Query, Advisory, Collection, Database, Repository};
use rustsec::{database::Query, Advisory, Collection, Database};
use super::Task;
@ -11,16 +11,15 @@ const ADVISORY_INDEX_PATH: &str = "../docs/static/advisory";
#[derive(FromArgs)]
#[argh(subcommand, name = "advisory")]
pub struct AdvisoryTask {
/// advisory-db repository path
#[argh(option, short = 'r')]
repo_path: String,
/// destination path
#[argh(option, short = 'd', default = "ADVISORY_INDEX_PATH.to_string()")]
dest_path: String,
}
impl Task for AdvisoryTask {
fn execute(&self) -> crate::Result<()> {
let mut map = HashMap::new();
let repo = Repository::open(&self.repo_path)?;
let db = Database::load_from_repo(&repo)?;
let db = Database::fetch()?;
for advisory in db
.query(&Query::new().collection(Collection::Crates).withdrawn(false))
.into_iter()
@ -30,19 +29,21 @@ impl Task for AdvisoryTask {
.push(advisory);
}
for (package, advisories) in map {
generate_advisory_json(package.as_str(), &advisories)?;
self.generate_advisory_json(package.as_str(), &advisories)?;
}
Ok(())
}
}
fn generate_advisory_json(package: &str, advisory: &[&Advisory]) -> crate::Result<()> {
let path = Path::new(ADVISORY_INDEX_PATH);
if !path.exists() {
std::fs::create_dir(path)?;
impl AdvisoryTask {
fn generate_advisory_json(&self, package: &str, advisory: &[&Advisory]) -> crate::Result<()> {
let path = Path::new(&self.dest_path);
if !path.exists() {
std::fs::create_dir(path)?;
}
let mut file = std::fs::File::create(path.join(format!("{package}.json")))?;
let json = serde_json::to_string_pretty(&advisory)?;
file.write_all(json.as_bytes())?;
Ok(())
}
let mut file = std::fs::File::create(path.join(format!("{package}.json")))?;
let json = serde_json::to_string_pretty(&advisory)?;
file.write_all(json.as_bytes())?;
Ok(())
}

View file

@ -7,6 +7,7 @@ build
# Create dir in advance
mkdir -p /tmp/public/index
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml advisory -d docs/static/advisory
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml books -d /tmp/public/index/books.js
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml lints -d /tmp/public/index/lints.js
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml labels -d /tmp/public/index/labels.js
@ -14,7 +15,6 @@ RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml targets -d /tmp/public/index/targets.js
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml caniuse -r /tmp/caniuse -d /tmp/public/index/caniuse.js
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml rfcs -r /tmp/rfcs -d /tmp/public/index/rfcs.js
RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=rust/Cargo.toml advisory -r /tmp/advisory-db
# Copy commands.js
cp extension/index/commands.js /tmp/public/index/commands.js