Skip to content

Commit

Permalink
feat: format (#133)
Browse files Browse the repository at this point in the history
Co-authored-by: Clay McLeod <clay.l.mcleod@gmail.com>
Co-authored-by: Peter Huene <peter@huene.dev>
Co-authored-by: Clay McLeod <3411613+claymcleod@users.noreply.github.com>
  • Loading branch information
4 people authored Oct 15, 2024
1 parent 1571c98 commit afb540a
Show file tree
Hide file tree
Showing 89 changed files with 20,287 additions and 756 deletions.
43 changes: 26 additions & 17 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
format:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update nightly && rustup default nightly
- name: Install rustfmt
Expand All @@ -20,7 +20,7 @@ jobs:
lint:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- name: Install clippy
Expand All @@ -30,53 +30,62 @@ jobs:
test:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo test --all-features

test-examples:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo test --all-features --examples

docs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo doc

gauntlet:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo run --release --bin gauntlet

arena:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo run --release --bin gauntlet -- --arena

workspace-lints-enabled:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- run: cargo install cargo-workspace-lints --locked
- run: cargo workspace-lints

msrv:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- name: Install cargo-binstall
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Install cargo-msrv
run: cargo binstall -y --version 0.16.0-beta.23 cargo-msrv
- name: Verify the MSRV
working-directory: ./wdl
run: cargo msrv verify --output-format minimal --all-features
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable && rustup default stable
- name: Install cargo-binstall
run: curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
- name: Install cargo-msrv
run: cargo binstall -y --version 0.16.0-beta.23 cargo-msrv
- name: Verify the MSRV
working-directory: ./wdl
run: cargo msrv verify --output-format minimal --all-features
70 changes: 44 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[workspace]
members = [ "ci",
members = [
"ci",
"gauntlet",
"wdl",
"wdl-analysis",
"wdl-ast",
"gauntlet",
"wdl-format",
"wdl-grammar",
"wdl-lint",
"wdl-lsp",
Expand All @@ -19,40 +21,56 @@ repository = "https://github.com/stjude-rust-labs/wdl"
rust-version = "1.80.0"

[workspace.dependencies]
anyhow = "1.0.86"
approx = "0.5.1"
clap = { version = "4.5.7", features = ["derive"] }
clap-verbosity-flag = "2.2.1"
codespan-reporting = "0.11.1"
colored = "2.1.0"
convert_case = "0.6.0"
dirs = "5.0.1"
faster-hex = "0.9.0"
futures = "0.3.30"
git2 = "0.18.3"
id-arena = "2.2.1"
indexmap = { version = "2.2.6", features = ["serde"] }
indicatif = "0.17.8"
itertools = "0.13.0"
line-index = "0.1.1"
logos = "0.14.0"
nonempty = "0.10.0"
parking_lot = "0.12.3"
path-clean = "1.0.1"
petgraph = "0.6.5"
pretty_assertions = "1.4.0"
rayon = "1.10.0"
reqwest = "0.12.5"
rowan = "0.15.15"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0.120"
serde_with = "3.8.1"
tempfile = "3.10.1"
tokio = { version = "1.38.0", features = ["full"] }
toml = "0.8.14"
tower-lsp = "0.20.0"
tracing = "0.1.40"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
logos = "0.14.0"
rowan = "0.15.15"
pretty_assertions = "1.4.0"
rayon = "1.10.0"
approx = "0.5.1"
codespan-reporting = "0.11.1"
anyhow = "1.0.86"
dirs = "5.0.1"
faster-hex = "0.9.0"
git2 = "0.18.3"
tempfile = "3.10.1"
url = "2.5.2"
urlencoding = "2.1.3"
parking_lot = "0.12.3"
reqwest = "0.12.5"
petgraph = "0.6.5"
futures = "0.3.30"
walkdir = "2.5.0"
path-clean = "1.0.1"
indicatif = "0.17.8"
tower-lsp = "0.20.0"
line-index = "0.1.1"
serde_json = "1.0.120"
uuid = "1.10.0"
id-arena = "2.2.1"
clap-verbosity-flag = "2.2.1"
tracing-log = "0.2.0"
walkdir = "2.5.0"

[workspace.lints.rust]
missing_docs = "warn"
nonstandard-style = "warn"
rust-2018-idioms = "warn"
rust-2021-compatibility = "warn"
rust-2024-compatibility = "warn"
edition_2024_expr_fragment_specifier = "allow"

[workspace.lints.rustdoc]
broken_intra_doc_links = "warn"

[workspace.lints.clippy]
missing_docs_in_private_items = "warn"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ cargo run --bin wdl --features cli -- $ARGS

Where `$ARGS` are the command line arguments to the `wdl` CLI tool.

The `wdl` CLI tool currently supports three subcommands:
The `wdl` CLI tool currently supports the following subcommands:

* `parse` - Parses a WDL document and prints both the parse diagnostics and the
resulting Concrete Syntax Tree (CST).
Expand All @@ -137,6 +137,8 @@ The `wdl` CLI tool currently supports three subcommands:
document scopes and exits with a status code of `0` if the documents are
valid; otherwise, prints the validation diagnostics and exits with a status
code of `1`.
* `format` - Parses, validates, and then formats a single WDL document, printing
the result to STDOUT.

Each of the subcommands supports passing `-` as the file path to denote reading
from STDIN instead of a file on disk.
Expand Down
3 changes: 3 additions & 0 deletions ci/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ clap.workspace = true
reqwest = { workspace = true, features = ["blocking", "rustls-tls"] }
toml.workspace = true
toml_edit = { version = "0.22.21", features = ["serde"] }

[lints]
workspace = true
47 changes: 39 additions & 8 deletions ci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,55 +48,82 @@ use std::time::Duration;
use clap::Parser;
use toml_edit::DocumentMut;

// note that this list must be topologically sorted by dependencies
/// Crates names to publish.
// Note that this list must be topologically sorted by dependencies.
const SORTED_CRATES_TO_PUBLISH: &[&str] = &[
"wdl-grammar",
"wdl-ast",
"wdl-lint",
"wdl-format",
"wdl-analysis",
"wdl-lsp",
"wdl",
];

/// Paths to ignore.
const IGNORE_PATHS: &[&str] = &["target", "tests", "examples", "benches", "book", "docs"];

/// An in-memory representation of a crate.
#[derive(Debug, Clone)]
struct Crate {
/// The manifest file.
manifest: DocumentMut,

/// The path to the manifest.
manifest_path: PathBuf,

/// The path to the changelog.
changelog_path: Option<PathBuf>,

/// The name of the crate.
name: String,

/// The version of the crate.
version: String,

/// Whether the version should be bumped.
should_bump: bool,
}

/// The command line arguments.
#[derive(Parser)]
struct Opts {
struct Args {
/// The subcommand.
#[clap(subcommand)]
subcmd: SubCommand,
command: Subcommand,
}

/// The subcommand to use.
#[derive(Parser)]
enum SubCommand {
enum Subcommand {
/// Request to bump a crate/crates.
Bump(Bump),

/// Publishes a crate/crates.
Publish(Publish),
}

/// The arguments to the `bump` subcommand.
#[derive(Parser)]
struct Bump {
/// Whether or not the bump should be a patch version increase.
#[clap(short, long)]
patch: bool,

/// The list of crate names to bump.
#[clap(short, long)]
crates_to_bump: Vec<String>,
}

/// The arguments to the `publish` subcommand.
#[derive(Parser)]
struct Publish {
/// Whether or not to perform a dry-run of the publishing.
#[clap(short, long)]
dry_run: bool,
}

/// The main function.
fn main() {
let mut all_crates: Vec<Rc<RefCell<Crate>>> = Vec::new();
find_crates(".".as_ref(), &mut all_crates);
Expand All @@ -108,9 +135,9 @@ fn main() {
.collect::<HashMap<_, _>>();
all_crates.sort_by_key(|krate| publish_order.get(&krate.borrow().name[..]));

let opts = Opts::parse();
match opts.subcmd {
SubCommand::Bump(Bump {
let opts = Args::parse();
match opts.command {
Subcommand::Bump(Bump {
patch,
crates_to_bump,
}) => {
Expand Down Expand Up @@ -150,7 +177,7 @@ fn main() {
.success()
);
}
SubCommand::Publish(Publish { dry_run }) => {
Subcommand::Publish(Publish { dry_run }) => {
// We have so many crates to publish we're frequently either
// rate-limited or we run into issues where crates can't publish
// successfully because they're waiting on the index entries of
Expand All @@ -177,6 +204,7 @@ fn main() {
}
}

/// Finds crates in a particular directory.
fn find_crates(dir: &Path, dst: &mut Vec<Rc<RefCell<Crate>>>) {
if dir.join("Cargo.toml").exists() {
if let Some(krate) = read_crate(&dir.join("Cargo.toml")) {
Expand All @@ -195,6 +223,7 @@ fn find_crates(dir: &Path, dst: &mut Vec<Rc<RefCell<Crate>>>) {
}
}

/// Reads a crate from a manifest.
fn read_crate(manifest_path: &Path) -> Option<Crate> {
let contents = fs::read_to_string(manifest_path).expect("failed to read manifest");
let mut manifest =
Expand Down Expand Up @@ -223,6 +252,7 @@ fn read_crate(manifest_path: &Path) -> Option<Crate> {
})
}

/// Bumps the version of a crate.
fn bump_version(krate: &Crate, crates: &[Rc<RefCell<Crate>>], patch: bool) {
let mut new_manifest = krate.manifest.clone();

Expand Down Expand Up @@ -289,6 +319,7 @@ fn bump(version: &str, patch_bump: bool) -> String {
}
}

/// Publishes a crate.
fn publish(krate: &Crate, dry_run: bool) -> bool {
if !SORTED_CRATES_TO_PUBLISH.iter().any(|s| *s == krate.name) {
return true;
Expand Down
3 changes: 3 additions & 0 deletions gauntlet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ tracing.workspace = true
tracing-subscriber.workspace = true
anyhow.workspace = true
codespan-reporting.workspace = true

[lints]
workspace = true
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
reorder_impl_items = true
style_edition = "2024"
use_field_init_shorthand = true
wrap_comments = true
style_edition = "2024"
3 changes: 3 additions & 0 deletions wdl-analysis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ tempfile = { workspace = true }
default = []
codespan = ["wdl-ast/codespan"]

[lints]
workspace = true

[[test]]
name = "analysis"
required-features = ["codespan"]
Expand Down
1 change: 0 additions & 1 deletion wdl-analysis/src/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use tokio::sync::mpsc;
use tokio::sync::oneshot;
use url::Url;
use walkdir::WalkDir;
use wdl_ast::AstNode;
use wdl_ast::Diagnostic;
use wdl_ast::Severity;
use wdl_ast::SyntaxNode;
Expand Down
1 change: 0 additions & 1 deletion wdl-analysis/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use tracing::debug;
use tracing::info;
use url::Url;
use uuid::Uuid;
use wdl_ast::AstNode;
use wdl_ast::Diagnostic;
use wdl_ast::SyntaxNode;
use wdl_ast::Validator;
Expand Down
Loading

0 comments on commit afb540a

Please sign in to comment.