Skip to content

Commit

Permalink
Add Basic CI (#13)
Browse files Browse the repository at this point in the history
* Update the benchmark.

Test both parsing and checking.

* Add basic CI.

* CI: Fix options of `cargo fmt`.

* CI: update toolchain to 1.70 for package `half`

It's required by criterion.

* CI: update toolchain to 1.74 for package `clap`

It's also required by criterion.

* CI: temporarily allow some warnings from clippy.

Fix those warnings later.

* Patch `unicode-width`.

0.1.13 and 0.1.11 produce different results, which cause test failures.

* CI: try to fix rustfmt-not-installed error.

* CI: add the benchmark.

* CI: correct job name.

* CI: add en endline to the last of ci.yml

* CI: try using bencher.

* CI: use dtolnay/rust-toolchain@v1 instead.

Also updated the toolchain used in checking and test coverage.

* CI: Move benchmark job to another file.

Replace `main` with corresponding branch name.

Also set `fail_ci_if_error` of test coverage to true.

* CI: update workflow names.

* Update benchmark measurement time.

As CI results suggested.

* CI: remove a redundant job and use default adapter of bencher.

* CI: remove a redundant space.

* CI: use `secrets.CODECOV_TOKEN` due to rate limits
  • Loading branch information
TheVeryDarkness authored Jun 15, 2024
1 parent 08e9925 commit b597196
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 10 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
push:
branches:
- main
- add-ci # Temporarily used for CI tests.

name: Benchmark

jobs:
benchmark:
name: Continuous Benchmarking with Bencher
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
- uses: bencherdev/bencher@main
- name: Track base branch benchmarks with Bencher
run: |
bencher run \
--project pest3 \
--token '${{ secrets.BENCHER_API_TOKEN }}' \
--branch ${{ github.ref_name }} \
--testbed ubuntu-latest \
--err \
cargo bench --workspace
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
on: [push]

name: Build, Lint and Test

jobs:
check:
name: Rust project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: 1.74
components: rustfmt, clippy
- name: cargo fmt
run: cargo fmt --all -- --check
- name: cargo clippy
run: cargo clippy --workspace --all-targets # -- -Dwarnings
- name: cargo test
run: cargo test --workspace
- name: cargo doc
run: cargo doc --workspace

coverage:
name: Test Coverage
needs: check
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: 1.74
components: llvm-tools-preview, rustfmt
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@cargo-llvm-cov
- name: Generate code coverage
run: cargo llvm-cov --workspace --lcov --output-path lcov.info
- name: Upload Results to Codecov
uses: codecov/codecov-action@v3
with:
file: lcov.info
flags: unittests
name: pest3-ci-coverage
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ package.license = "MIT OR Apache-2.0"
pest3 = { path = "./pest", package = "pest3" }
pest3_meta = { path = "./meta", package = "pest3_meta" }
pest3_generator = { path = "./generator", package = "pest3_generator" }
unicode-width = { version = "0.1.11" }
unicode-width = { version = "0.1.13" }
pest2 = { version = "2.7.8", package = "pest" }
pest2_derive = { version = "2.7.8", package = "pest_derive" }
26 changes: 18 additions & 8 deletions derive/benches/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use serde_json::{Map, Value};
pub struct JsonParser;

pub fn deep_object(c: &mut Criterion) {
let mut group = c.benchmark_group("json_deep_object");
let mut group = c.benchmark_group("json_deep_object_26_10");
group.sample_size(10);
group.measurement_time(Duration::from_secs(40));
group.measurement_time(Duration::from_secs(50));
let mut val = Value::Array(vec![]);
// 'a0': 0,
// ...
Expand All @@ -25,17 +25,22 @@ pub fn deep_object(c: &mut Criterion) {
}
let s = format!("{:#}", val);
println!("Input string has {} characters.", s.len());
group.bench_function("26*10", |b| {
group.bench_function("parse", |b| {
b.iter(|| {
let _ = rules::json::try_parse(&s);
let _ = rules::json::try_parse(&s).unwrap();
})
});
group.bench_function("check", |b| {
b.iter(|| {
let _ = rules::json::check(&s).unwrap();
})
});
}

pub fn shallow_object(c: &mut Criterion) {
let mut group = c.benchmark_group("json_shallow_object");
let mut group = c.benchmark_group("json_shallow_object_26_26_26");
group.sample_size(10);
group.measurement_time(Duration::from_secs(40));
group.measurement_time(Duration::from_secs(70));
// 'aaa': 0,
// ...
// 'zzz': 25 * 25 * 25,
Expand All @@ -56,9 +61,14 @@ pub fn shallow_object(c: &mut Criterion) {
);
let s = format!("{:#}", obj);
println!("Input string has {} characters.", s.len());
group.bench_function("26*26*26", |b| {
group.bench_function("parse", |b| {
b.iter(|| {
let _ = rules::json::try_parse(&s).unwrap();
})
});
group.bench_function("check", |b| {
b.iter(|| {
let _ = rules::json::try_parse(&s);
let _ = rules::json::check(&s).unwrap();
})
});
}
Expand Down
2 changes: 1 addition & 1 deletion pest/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ mod span {
assert_eq!(
msg,
" \
| v
| v
1 | ß␊
2 | ∆␊
3 | 中␊
Expand Down

0 comments on commit b597196

Please sign in to comment.