Skip to content

Commit

Permalink
check wiki regularly for validity
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Jul 3, 2022
1 parent 4f0b147 commit 4fe17f2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 9 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ jobs:
- name: Build Docker image
id: build-docker-image
run: cargo xtask build-docker-image -v --no-cache --no-output --from-ci --no-fastfail --tag weekly
timeout-minutes: 1440
wiki:
name: Ensure wiki is valid
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust
- run: git clone ${wikirepo}
shell: bash
env:
wikirepo: https://github.com/${{ github.repository}}.wiki.git
- run: cargo test toml_check -- --nocapture
cargo-deny:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ You have three options to configure `cross`. All of these options use the TOML f
You can directly set [configuration values](docs/cross_toml.md) in your `Cargo.toml` file, under the `[package.metadata.cross]` table, i.e. key prefix.
An example config snippet would look like this:

```
```toml,cargo
[package.metadata.cross.target.aarch64-unknown-linux-gnu]
xargo = false
image = "test-image"
Expand Down
42 changes: 34 additions & 8 deletions src/tests/toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ use std::io::Read;
use once_cell::sync::Lazy;
use regex::{Regex, RegexBuilder};

use crate::ToUtf8;

static TOML_REGEX: Lazy<Regex> = Lazy::new(|| {
RegexBuilder::new(r#"```toml\n(.*?)```"#)
RegexBuilder::new(r#"```toml(.*?)\n(.*?)```"#)
.multi_line(true)
.dot_matches_new_line(true)
.build()
Expand Down Expand Up @@ -35,16 +37,40 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {
let mut contents = String::new();
file.read_to_string(&mut contents).unwrap();
for matches in TOML_REGEX.captures_iter(&contents) {
let fence = matches.get(1).unwrap();
let cargo = {
let t = matches.get(1).unwrap().as_str();
if t.is_empty() {
false
} else if t == ",cargo" {
true
} else {
println!("skipping {t}");
continue;
}
};
let fence = matches.get(2).unwrap();
let fence_content = fence
.as_str()
.replace("$TARGET", "x86_64-unknown-linux-gnu")
.replace("${target}", "x86_64-unknown-linux-gnu");

eprintln!(
"testing snippet at: {:?}:{:?}",
dir_entry.path(),
"testing snippet at: {}:{:?}",
dir_entry.path().to_utf8()?,
text_line_no(&contents, fence.range().start),
);
assert!(crate::cross_toml::CrossToml::parse_from_cross(
fence.as_str(),
crate::shell::MessageInfo::default()
)?
assert!(if !cargo {
crate::cross_toml::CrossToml::parse_from_cross(
&fence_content,
crate::shell::MessageInfo::default(),
)?
} else {
crate::cross_toml::CrossToml::parse_from_cargo(
&fence_content,
crate::shell::MessageInfo::default(),
)?
.unwrap_or_default()
}
.1
.is_empty());
}
Expand Down

0 comments on commit 4fe17f2

Please sign in to comment.