Skip to content
New issue

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

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

Already on GitHub? # to your account

chore(ci): improving CI #301

Merged
merged 19 commits into from
Jun 23, 2023
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
34 changes: 34 additions & 0 deletions .github/workflows/clearcache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# From: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cleanup caches by a branch
on:
pull_request:
types:
- closed

jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Cleanup
run: |
gh extension install actions/gh-actions-cache

REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"

echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )

## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22 changes: 22 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Code Coverage

on: [push]
jobs:
test:
name: Coverage
runs-on: ubuntu-latest
container:
image: xd009642/tarpaulin:develop-nightly
options: --security-opt seccomp=unconfined
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Generate code coverage
run: |
cargo +nightly tarpaulin --verbose --all-features --workspace --timeout 120 --out Xml

- name: Upload to codecov.io
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
46 changes: 0 additions & 46 deletions .github/workflows/rust.yml

This file was deleted.

58 changes: 58 additions & 0 deletions .github/workflows/rustbench.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
on:
pull_request:
paths:
- '**.rs'
- '**/Cargo.toml'
workflow_dispatch:

name: Benchmark

permissions:
pull-requests: write

jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Install Critcmp
uses: baptiste0928/cargo-install@v2
with:
crate: critcmp
version: latest

- name: Run Benchmarks on changes
run: cargo bench --bench bench -- --save-baseline changes

- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.sha }}
clean: false

- name: Run Benchmarks before changes
run: cargo bench --bench bench -- --save-baseline before

- name: Compare benchmarks
run: |
echo 'results<<EOF' >> $GITHUB_OUTPUT
critcmp before changes >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT

id: compare

- name: Comment PR with execution number
uses: thollander/actions-comment-pull-request@v2
with:
message: |
Benchmark results:
```
${{ steps.compare.outputs.results }}
```
comment_tag: benchmarks
16 changes: 16 additions & 0 deletions .github/workflows/rustcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on:
pull_request:
paths:
- '**.rs'
- '**/Cargo.toml'
workflow_dispatch:

name: Cargo check

jobs:
cargo_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: taiki-e/install-action@cargo-hack
- run: cargo hack check --feature-powerset --no-dev-deps
25 changes: 25 additions & 0 deletions .github/workflows/rustdoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
pull_request:
paths:
- '**.rs'
- '**/Cargo.toml'
workflow_dispatch:

name: Rustdoc

jobs:
publish:
name: Build docs
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Check rustdoc build
run: RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --all-features -Zunstable-options -Zrustdoc-scrape-examples
59 changes: 59 additions & 0 deletions .github/workflows/rustlib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
on:
pull_request:
paths:
- '**.rs'
- '**/Cargo.toml'
workflow_dispatch:

name: Library testing

jobs:
rustdoc:
name: Rustdoc
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@nightly

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Check rustdoc build
run: RUSTDOCFLAGS='--cfg docsrs' cargo +nightly doc --all-features -Zunstable-options -Zrustdoc-scrape-examples

tests:
name: Tests
strategy:
matrix:
rust:
- stable
- beta
- nightly
os:
- macos-latest
- ubuntu-latest
- windows-latest

runs-on: ${{ matrix.os }}
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt

- name: Cache dependencies
uses: Swatinem/rust-cache@v2

- name: Check that code compiles
uses: actions-rs/cargo@v1
with:
command: test
args: --verbose
39 changes: 39 additions & 0 deletions .github/workflows/rustlints.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
on:
pull_request:
paths:
- '**.rs'
- '**/Cargo.toml'
workflow_dispatch:

name: Rust lints

jobs:
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy

- name: Check clippy
run: cargo clippy --all-features -- -D warnings

rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v3

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt

- name: Check format
run: cargo fmt --check
27 changes: 27 additions & 0 deletions .github/workflows/rustmsrv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
pull_request:
paths:
- '**.rs'
- '**/Cargo.toml'
workflow_dispatch:

name: MSRV check

jobs:
msrv_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable

- name: Install Cargo MSRV
uses: baptiste0928/cargo-install@v1
with:
crate: cargo-msrv
args: --no-default-features
version: ^0.15.1

- name: Check MSRV
run: cd logos && cargo msrv verify -- cargo check --all-features
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ which can be used to put data into a variant:
// Callbacks can use closure syntax, or refer
// to a function defined elsewhere.
//
// Each pattern can have it's own callback.
// Each pattern can have its own callback.
#[regex("[0-9]+", |lex| lex.slice().parse().ok())]
#[regex("[0-9]+k", kilo)]
#[regex("[0-9]+m", mega)]
Expand Down Expand Up @@ -162,7 +162,7 @@ Loops or optional blocks are ignored, while alternations count the shortest alte

+ `[a-zA-Z]+` has a priority of 1 (lowest possible), because at minimum it can match a single byte to a class.
+ `foobar` has a priority of 12.
+ `(foo|hello)(bar)?` has a priority of 6, `foo` being it's shortest possible match.
+ `(foo|hello)(bar)?` has a priority of 6, `foo` being its shortest possible match.

If two definitions compute to the same priority and can match the same input **Logos** will
fail to compile, point out the problematic definitions, and ask you to specify a manual
Expand Down
1 change: 1 addition & 0 deletions logos-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ syn = { version = "2.0.13", features = ["full"] }
quote = "1.0.3"
proc-macro2 = "1.0.9"
regex-syntax = "0.6"
lazy_static = "1.4.0"

[dev-dependencies]
pretty_assertions = "0.6.1"
9 changes: 1 addition & 8 deletions logos-codegen/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@ use quote::{quote_spanned, ToTokens, TokenStreamExt};

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Default)]
pub struct Errors {
collected: Vec<SpannedError>,
}

impl Default for Errors {
fn default() -> Self {
Errors {
collected: Vec::new(),
}
}
}

impl Errors {
pub fn err<M>(&mut self, message: M, span: Span) -> &mut Self
where
Expand Down
3 changes: 3 additions & 0 deletions logos-codegen/src/generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ impl<'a> Generator<'a> {
fn goto(&mut self, id: NodeId, mut ctx: Context) -> &TokenStream {
let key = (id, ctx);

// Allow contains_key + insert because self.generate_ident borrows a mutable ref to self
// too.
#[allow(clippy::map_entry)]
if !self.gotos.contains_key(&key) {
let meta = &self.meta[id];
let enters_loop = !meta.loop_entry_from.is_empty();
Expand Down
Loading