Skip to content

Commit

Permalink
chore: add release-check
Browse files Browse the repository at this point in the history
  • Loading branch information
hardfist committed Dec 3, 2024
1 parent 2ec1cf5 commit 9d30493
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 19 deletions.
35 changes: 22 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ rspack_plugin_wasm = { version = "0.2.0", path = "crates/rsp
rspack_plugin_web_worker_template = { version = "0.2.0", path = "crates/rspack_plugin_web_worker_template" }
rspack_plugin_worker = { version = "0.2.0", path = "crates/rspack_plugin_worker" }
rspack_regex = { version = "0.2.0", path = "crates/rspack_regex" }
rspack_swc_plugin_import = { version = "0.2.0", path = "crates/swc_plugin_import" }
rspack_testing = { version = "0.2.0", path = "crates/rspack_testing" }
rspack_tracing = { version = "0.2.0", path = "crates/rspack_tracing" }
rspack_util = { version = "0.2.0", path = "crates/rspack_util" }
swc_plugin_import = { version = "0.2.0", path = "crates/swc_plugin_import" }
[workspace.metadata.release]
rate-limit = { existing-packages = 70, new-packages = 70 }
[profile.dev]
Expand Down
3 changes: 2 additions & 1 deletion crates/rspack_error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ swc_core = { workspace = true, features = ["common", "common_concurren
termcolor = "1"
textwrap = "0.15.2"
thiserror = "1"
unicode-width = "0.2.0"

unicode-width = "0.2.0"
2 changes: 1 addition & 1 deletion crates/rspack_loader_swc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ rspack_core = { workspace = true }
rspack_error = { workspace = true }
rspack_loader_runner = { workspace = true }
rspack_plugin_javascript = { workspace = true }
rspack_swc_plugin_import = { workspace = true }
rspack_util = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
stacker = { workspace = true }
swc = { workspace = true, features = ["manual-tokio-runtmie"] }
swc_config = { workspace = true }
swc_core = { workspace = true, features = ["base", "ecma_ast", "common"] }
swc_plugin_import = { workspace = true }
url = "2.5.0"
2 changes: 1 addition & 1 deletion crates/rspack_loader_swc/src/options.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use rspack_swc_plugin_import::{ImportOptions, RawImportOptions};
use serde::Deserialize;
use swc_config::config_types::BoolConfig;
use swc_core::base::config::{
Config, ErrorConfig, FileMatcher, InputSourceMap, IsModule, JscConfig, ModuleConfig, Options,
SourceMapsConfig,
};
use swc_plugin_import::{ImportOptions, RawImportOptions};

#[derive(Default, Deserialize, Debug)]
#[serde(rename_all = "camelCase", default)]
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_loader_swc/src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! either {
#[allow(clippy::too_many_arguments)]
pub(crate) fn transform(rspack_experiments: &RspackExperiments) -> impl Pass + '_ {
either!(rspack_experiments.import, |options| {
swc_plugin_import::plugin_import(options)
rspack_swc_plugin_import::plugin_import(options)
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/rspack_plugin_remove_duplicate_modules/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
description = "remove duplicate modules"
edition = "2021"
license = "MIT"
name = "rspack_plugin_remove_duplicate_modules"
repository = "https://github.com/web-infra-dev/rspack"
version = "0.2.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/swc_plugin_import/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
description = "babel-plugin-import rewritten in Rust"
edition = "2021"
license = "MIT"
name = "swc_plugin_import"
name = "rspack_swc_plugin_import"
repository = "https://github.com/web-infra-dev/rspack"
version = "0.2.0"

Expand Down
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ ready:
# Publish Rust crates to crates.io
release-rust:
cargo release publish --no-verify --execute --no-confirm
# Check crate whether have correct fields for publish
release-check:
cargo run -p release-check

# Format Rust, TOML files, and JavaScript code
fmt:
Expand Down
19 changes: 19 additions & 0 deletions tasks/release-check/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "release-check"
description = "check whether crates missing field for publish"
version = "0.1.0"
edition = "2021"
authors.workspace = true
categories.workspace = true
documentation.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

[dependencies]
toml = { version = "0.8.9"}
miette = { version = "5", features = ["fancy"] }
thiserror = "1"

[lints]
workspace = true
75 changes: 75 additions & 0 deletions tasks/release-check/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use std::fs;
use std::path::Path;

use miette::{miette, Diagnostic, IntoDiagnostic, Report, Result};
use thiserror::Error;
use toml::Value;
fn main() -> Result<()> {
let required_fields = vec![
"description",
"version",
"license",
"repository",
"homepage",
"documentation",
];
let optional_fields = ["repository", "homepage", "documentation"];
let mut diagnostics: Vec<Report> = vec![];
// iterate all crate in crates folder
let crates_dir = Path::new("crates");

for entry in fs::read_dir(crates_dir).into_diagnostic()? {
let entry = entry.into_diagnostic()?;
let path = entry.path();

if path.is_dir() {
let cargo_toml_path = path.join("Cargo.toml");
if cargo_toml_path.exists() {
let content = fs::read_to_string(&cargo_toml_path).into_diagnostic()?;
let cargo_toml: Value = toml::from_str(&content).into_diagnostic()?;
if let Some(package) = cargo_toml.get("package") {
let mut has_optional = false;
for field in &required_fields {
if optional_fields.contains(field) {
if package.get(field).is_some() {
has_optional = true
}
} else if package.get(field).is_none() {
diagnostics.push(miette!(
"Missing required field: {} in {}",
field,
cargo_toml_path.display(),
));
}
}
if !has_optional {
let msg = optional_fields.join(",");
let error = miette!(
"You have at least have one of these fields {} section in {}",
msg,
cargo_toml_path.display()
);
diagnostics.push(error);
}
} else {
diagnostics.push(miette!("Missing [package] section"));
}
}
}
}
#[derive(Debug, Diagnostic, Error)]
#[error("release-check failed")]
struct ReleaseCheckError {
#[related]
others: Vec<Report>,
}
if diagnostics.is_empty() {
Ok(())
} else {
let error = ReleaseCheckError {
others: diagnostics,
}
.into();
Err(error)
}
}

0 comments on commit 9d30493

Please sign in to comment.