xtask: Add check for consistent version numbers in docs
This commit is contained in:
parent
0c1e1df8ad
commit
3a5e356d65
@ -4,6 +4,10 @@ use xshell::pushd;
|
||||
|
||||
use crate::{cmd, Metadata, Result};
|
||||
|
||||
mod spec_links;
|
||||
|
||||
use spec_links::check_spec_links;
|
||||
|
||||
const MSRV: &str = "1.55";
|
||||
|
||||
/// Task to run CI tests.
|
||||
@ -37,7 +41,7 @@ impl CiTask {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_msrv(&self) -> xshell::Result<()> {
|
||||
fn build_msrv(&self) -> Result<()> {
|
||||
// Check all crates with all features except
|
||||
// * ruma (would pull in ruma-signatures)
|
||||
// * ruma-client (tested with default features due to optional HTTP client deps)
|
||||
@ -56,10 +60,10 @@ impl CiTask {
|
||||
cmd!("rustup run {MSRV} cargo check -p ruma-client").run()?;
|
||||
|
||||
// Check ruma crate with default features
|
||||
cmd!("rustup run {MSRV} cargo check -p ruma").run()
|
||||
cmd!("rustup run {MSRV} cargo check -p ruma").run().map_err(Into::into)
|
||||
}
|
||||
|
||||
fn build_stable(&self) -> xshell::Result<()> {
|
||||
fn build_stable(&self) -> Result<()> {
|
||||
// 1. Make sure everything compiles
|
||||
cmd!("rustup run stable cargo check --workspace --all-features").run()?;
|
||||
cmd!("rustup run stable cargo check -p ruma-client --no-default-features").run()?;
|
||||
@ -72,10 +76,10 @@ impl CiTask {
|
||||
let events_compat_res =
|
||||
cmd!("rustup run stable cargo test -p ruma-events --features compat compat").run();
|
||||
|
||||
workspace_res.and(events_compat_res)
|
||||
workspace_res.and(events_compat_res).map_err(Into::into)
|
||||
}
|
||||
|
||||
fn build_nightly(&self) -> xshell::Result<()> {
|
||||
fn build_nightly(&self) -> Result<()> {
|
||||
// Check formatting
|
||||
let fmt_res = cmd!("rustup run nightly cargo fmt -- --check").run();
|
||||
// Check `ruma` crate with `full` feature (sometimes things only compile with an unstable
|
||||
@ -106,7 +110,15 @@ impl CiTask {
|
||||
"
|
||||
)
|
||||
.run();
|
||||
// Check that all links point to the same version of the spec
|
||||
let spec_links = check_spec_links(&self.project_root.join("crates"));
|
||||
|
||||
fmt_res.and(check_full_res).and(clippy_default_res).and(clippy_all_res).and(sort_res)
|
||||
fmt_res
|
||||
.and(check_full_res)
|
||||
.and(clippy_default_res)
|
||||
.and(clippy_all_res)
|
||||
.and(sort_res)
|
||||
.map_err(Into::into)
|
||||
.and(spec_links)
|
||||
}
|
||||
}
|
||||
|
74
xtask/src/ci/spec_links.rs
Normal file
74
xtask/src/ci/spec_links.rs
Normal file
@ -0,0 +1,74 @@
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::{BufRead, BufReader},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
type VersionFn = fn(&str) -> bool;
|
||||
const SPLITS: &[(&str, VersionFn)] = &[
|
||||
("https://matrix.org/docs/spec/client_server/", |s| {
|
||||
// We cannot include the `#` because for every lib.rs file with spec docs the
|
||||
// URL is `../rx.x.x.html`
|
||||
s.starts_with("r0.6.1") || s.starts_with("unstable#")
|
||||
}),
|
||||
("https://matrix.org/docs/spec/server_server/", |s| {
|
||||
s.starts_with("r0.1.4") || s.starts_with("unstable#")
|
||||
}),
|
||||
("https://matrix.org/docs/spec/application_service/", |s| {
|
||||
s.starts_with("r0.1.2") || s.starts_with("unstable#")
|
||||
}),
|
||||
("https://matrix.org/docs/spec/identity_service/", |s| {
|
||||
s.starts_with("r0.3.0") || s.starts_with("unstable#")
|
||||
}),
|
||||
("https://matrix.org/docs/spec/push_gateway/", |s| {
|
||||
s.starts_with("r0.1.1") || s.starts_with("unstable#")
|
||||
}),
|
||||
];
|
||||
|
||||
pub(crate) fn check_spec_links(path: &Path) -> Result<()> {
|
||||
println!("Checking all Matrix Spec links point to same version...");
|
||||
// This is WAY overkill but since there are a few mixed in ruma-common
|
||||
// and this would catch any wrong version anywhere it's probably ok
|
||||
for (split, version_fn) in SPLITS {
|
||||
walk_dirs(path, split, *version_fn)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn walk_dirs(path: &Path, split: &str, version_match: fn(&str) -> bool) -> Result<()> {
|
||||
if path.is_dir() {
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
if path.is_dir() {
|
||||
walk_dirs(&path, split, version_match)?;
|
||||
} else {
|
||||
let mut buf = String::new();
|
||||
let mut content = BufReader::new(File::open(&path)?);
|
||||
|
||||
// We can assume a spec link will never overflow to another line
|
||||
while content.read_line(&mut buf)? > 0 {
|
||||
// If for some reason a line has 2 spec links
|
||||
for (idx, _) in buf.match_indices(split) {
|
||||
if !version_match(&buf[idx + split.len()..]) {
|
||||
return err(&path, &buf);
|
||||
}
|
||||
}
|
||||
buf.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn err(path: &Path, snippet: &str) -> Result<()> {
|
||||
Err(format!(
|
||||
"error: spec URL with wrong version number\nfile: {}\n\nsnippet:\n{}",
|
||||
path.display(),
|
||||
&snippet[0..25]
|
||||
)
|
||||
.into())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user