diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..190dbee --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,60 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: CI + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - '**.md' + - '.gitignore' + push: + branches: + - "main" + paths-ignore: + - '**.md' + - '.gitignore' + +env: + CARGO_TERM_COLOR: always + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - run: cargo fmt --all -- --check + - run: cargo clippy --all-targets -- -D warnings + - run: cargo check + + coverage: + name: Coverage + runs-on: ubuntu-latest + env: + CARGO_TERM_COLOR: always + steps: + - uses: actions/checkout@v4 + - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@cargo-llvm-cov + - name: Generate code coverage + run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v4 + with: + files: lcov.info + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..289cf4b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +name: Release +run-name: publish packages by @${{ github.actor }} + +on: + push: + tags: + - "v*.*.*" + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: cargo publish --token ${{ secrets.CRATES_TOKEN }} diff --git a/Cargo.toml b/Cargo.toml index 7167c70..49f3c89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,12 @@ name = "grok-rs" version = "0.1.0" edition = "2021" +readme = "README.md" +description = "Rust port of elastic Grok processor" +repository = "https://github.com/GreptimeTeam/promql-parser" +authors = ["yuanbohan"] +keywords = ["grok", "elastic", "logstash", "ETL"] +license = "Apache-2.0" [dependencies] glob = "0.3.1" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..826f3c8 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +SHELL=/bin/bash + +.PHONY: clean build check + +build: + cargo build + +clean: + cargo clean + +check: + cargo fmt --all -- --check + cargo clippy --all-targets -- -D warnings + cargo test -- --show-output + cargo check diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..3cd0f1e --- /dev/null +++ b/codecov.yml @@ -0,0 +1,36 @@ +# Copyright 2023 Greptime Team +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +coverage: + status: + project: + default: + threshold: 1% + target: 80% # increase the target in the future + paths: + - "src" + informational: false + patch: + default: + threshold: 1% + target: 80% # increase the target in the future + paths: + - "src" + informational: true + +comment: + show_critical_paths: true + +ignore: + - "src/patterns" diff --git a/src/lib.rs b/src/lib.rs index a1b3cc1..76443fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -202,13 +202,13 @@ mod tests { named_capture_only: bool, } - fn assert<'a>(c: Case<'a>) { - let grok = Grok::from_iter(c.patterns.into_iter()); + fn assert(c: Case<'_>) { + let grok = Grok::from_iter(c.patterns); let pattern = grok.compile(c.pattern, c.named_capture_only).unwrap(); assert_eq!(c.expected, pattern.parse(c.input).unwrap()); } - fn asserts<'a>(cases: Vec>) { + fn asserts(cases: Vec>) { for c in cases { assert(c); } @@ -252,7 +252,7 @@ mod tests { .collect::>(); { - let grok = Grok::from_iter([("NAME", r"[A-z0-9._-]+")].into_iter()); + let grok = Grok::from_iter([("NAME", r"[A-z0-9._-]+")]); let pattern = grok.compile("%{NAME}", false).unwrap(); assert_eq!(expected, pattern.parse("admin").unwrap()); } @@ -411,7 +411,7 @@ mod tests { false, ) ].into_iter().map(|(patterns, pattern, input, expected, named_capture_only)| Case { - patterns: patterns.into_iter().map(|(k, v)| (k, v)).collect(), + patterns: patterns.into_iter().collect(), pattern, input, expected: expected.into_iter().map(|(k, v)| (k.to_string(), v)).collect(), @@ -457,7 +457,7 @@ mod tests { .into_iter() .map( |(patterns, pattern, input, expected, named_capture_only)| Case { - patterns: patterns.into_iter().map(|(k, v)| (k, v)).collect(), + patterns: patterns.into_iter().collect(), pattern, input, expected: expected @@ -510,7 +510,7 @@ mod tests { .into_iter() .map( |(patterns, pattern, input, expected, named_capture_only)| Case { - patterns: patterns.into_iter().map(|(k, v)| (k, v)).collect(), + patterns: patterns.into_iter().collect(), pattern, input, expected: expected @@ -797,13 +797,4 @@ mod tests { } } } - - #[test] - fn test_re() { - let s = r"(?:0[1-9]|1[0-2])"; - // let s = r"(?:1[0-2])"; - let r = Regex::new(s).unwrap(); - let result = r.find("12").unwrap(); - println!("{:?}", result); - } }