From 843c47ba9e4308c8e702109cccc5cbfeaa0fbe77 Mon Sep 17 00:00:00 2001 From: Folyd Date: Fri, 28 Jun 2024 22:30:09 -0700 Subject: [PATCH] Add build-index workflow --- .github/workflows/build-index.yml | 29 +++++++++++++ .github/workflows/{build.yml => deploy.yml} | 0 rust/Cargo.toml | 1 - rust/src/main.rs | 2 - rust/src/tasks/advisory.rs | 46 --------------------- rust/src/tasks/crates.rs | 4 +- rust/src/tasks/mod.rs | 2 - 7 files changed, 32 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/build-index.yml rename .github/workflows/{build.yml => deploy.yml} (100%) delete mode 100644 rust/src/tasks/advisory.rs diff --git a/.github/workflows/build-index.yml b/.github/workflows/build-index.yml new file mode 100644 index 0000000..b14e23c --- /dev/null +++ b/.github/workflows/build-index.yml @@ -0,0 +1,29 @@ +name: Build index +on: + workflow_dispatch: + +jobs: + build: + name: Build index + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: "Build index" + run: | + cd rust + RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=Cargo.toml books -d /tmp/books.js + RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=Cargo.toml lints -d /tmp/lints.js + RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=Cargo.toml labels -d /tmp/labels.js + RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=Cargo.toml rustc -d /tmp/rustc.js + RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=Cargo.toml targets -d /tmp/targets.js + git clone --depth 1 https://github.com/jplatte/caniuse.rs.git /tmp/caniuse + RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=Cargo.toml caniuse -r /tmp/caniuse -d /tmp/caniuse.js + git clone --depth 1 https://github.com/nrc/rfc-index.git /tmp/rfc-index + RUST_BACKTRACE=full cargo run --target-dir /tmp --manifest-path=Cargo.toml rfcs -r /tmp/rfc-index -d /tmp/rfcs.js + zip /tmp/index.zip /tmp/*.js + - name: "Upload Index Artifact" + uses: actions/upload-artifact@master + with: + name: index.zip + path: /tmp/index.zip + diff --git a/.github/workflows/build.yml b/.github/workflows/deploy.yml similarity index 100% rename from .github/workflows/build.yml rename to .github/workflows/deploy.yml diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 5ca7b86..03530a8 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -18,6 +18,5 @@ semver = { version = "1", features = ["serde"] } rayon = "1" regex = "1" argh = "0.1" -rustsec = "0" html-escape = "0" db-dump = "0.7.1" diff --git a/rust/src/main.rs b/rust/src/main.rs index 6687d08..de2accb 100644 --- a/rust/src/main.rs +++ b/rust/src/main.rs @@ -20,7 +20,6 @@ struct Options { #[argh(subcommand)] #[non_exhaustive] enum Subcommand { - Advisory(AdvisoryTask), Crates(CratesTask), Books(BooksTask), Caniuse(CaniuseTask), @@ -36,7 +35,6 @@ pub type Result = std::result::Result>; fn main() -> Result<()> { let options: Options = argh::from_env(); match options.subcommand { - Subcommand::Advisory(cmd) => cmd.execute()?, Subcommand::Crates(cmd) => cmd.execute()?, Subcommand::Books(cmd) => cmd.execute()?, Subcommand::Caniuse(cmd) => cmd.execute()?, diff --git a/rust/src/tasks/advisory.rs b/rust/src/tasks/advisory.rs deleted file mode 100644 index e17c0da..0000000 --- a/rust/src/tasks/advisory.rs +++ /dev/null @@ -1,46 +0,0 @@ -use argh::FromArgs; -use rayon::prelude::*; -use rustsec::{database::Query, Collection, Database}; -use std::{collections::HashMap, fs, io::Write, path::Path}; - -use super::Task; - -const ADVISORY_INDEX_PATH: &str = "../docs/static/advisory"; - -/// Advisory task -#[derive(FromArgs)] -#[argh(subcommand, name = "advisory")] -pub struct AdvisoryTask { - /// 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 db = Database::fetch()?; - for advisory in db - .query(&Query::new().collection(Collection::Crates).withdrawn(false)) - .into_iter() - { - map.entry(&advisory.metadata.package) - .or_insert_with(Vec::new) - .push(advisory); - } - - let path = Path::new(&self.dest_path); - if !path.exists() { - fs::create_dir(path)?; - } - map.par_iter_mut().for_each(|(package, advisories)| {≥ - // sort advisories by date - advisories.sort_by(|a, b| b.metadata.date.cmp(&a.metadata.date)); - let package = package.as_str().replace('-', "_"); - let mut file = fs::File::create(path.join(format!("{package}.json"))).unwrap(); - let json = serde_json::to_string_pretty(&advisories).unwrap(); - file.write_all(json.as_bytes()).unwrap(); - }); - Ok(()) - } -} diff --git a/rust/src/tasks/crates.rs b/rust/src/tasks/crates.rs index 7eac448..844147a 100644 --- a/rust/src/tasks/crates.rs +++ b/rust/src/tasks/crates.rs @@ -153,7 +153,9 @@ impl Task for CratesTask { return; } // Filter out aws_sdk crates and auto-generated google api crates. - if row.id.starts_with("aws_sdk_") || row.description.starts_with(GOOGLE_API_CRATES_FILTER_PREFIX) { + if row.name.starts_with("aws_sdk_") + || row.description.starts_with(GOOGLE_API_CRATES_FILTER_PREFIX) + { return; } crates.push(Crate { diff --git a/rust/src/tasks/mod.rs b/rust/src/tasks/mod.rs index d490230..5dc0c45 100644 --- a/rust/src/tasks/mod.rs +++ b/rust/src/tasks/mod.rs @@ -1,4 +1,3 @@ -pub use advisory::AdvisoryTask; pub use books::BooksTask; pub use caniuse::CaniuseTask; pub use crates::CratesTask; @@ -8,7 +7,6 @@ pub use rfcs::RfcsTask; pub use rustc::RustcTask; pub use targets::TargetsTask; -mod advisory; mod books; mod caniuse; mod crates;