Skip to content

Commit

Permalink
Merge pull request #4 from yuanbohan/github-actions
Browse files Browse the repository at this point in the history
ci: github action
  • Loading branch information
yuanbohan authored Jun 7, 2024
2 parents 30c5d0b + 56836ac commit fe67cfe
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 16 deletions.
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -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"
23 changes: 7 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Case<'a>>) {
fn asserts(cases: Vec<Case<'_>>) {
for c in cases {
assert(c);
}
Expand Down Expand Up @@ -252,7 +252,7 @@ mod tests {
.collect::<HashMap<String, Value>>();

{
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());
}
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

0 comments on commit fe67cfe

Please sign in to comment.