Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wiki check toml #907

Merged
merged 1 commit into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Alexhuszagh marked this conversation as resolved.
Show resolved Hide resolved

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