Skip to content

Commit

Permalink
Split into three rust projects: core,cli,webserver (#12)
Browse files Browse the repository at this point in the history
Split into three rust projects: core,cli,webserver.
  • Loading branch information
timKraeuter authored Apr 7, 2024
1 parent a5c8414 commit 6e701f9
Show file tree
Hide file tree
Showing 104 changed files with 5,046 additions and 251 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/bencher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@ on:
workflow_dispatch:
push:
paths:
- src/**
- core/**
- cli/**
pull_request:

jobs:
benchmark_with_bencher:
name: Continuous Benchmarking with Bencher
runs-on: ubuntu-latest
defaults:
run:
working-directory: cli
env:
BENCHER_PROJECT: rust-bpmn-analyzer
BENCHER_TESTBED: ubuntu-latest
BENCHER_ADAPTER: shell

steps:
- uses: actions/checkout@v4
- name: Install hyperfine
run: wget https://github.com/sharkdp/hyperfine/releases/download/v1.18.0/hyperfine_1.18.0_amd64.deb &&
sudo dpkg -i hyperfine_1.18.0_amd64.deb
- uses: actions/checkout@v4
- name: Build APP
run: cargo build --release
- uses: bencherdev/bencher@main
Expand All @@ -30,4 +35,4 @@ jobs:
--branch "$GITHUB_REF_NAME" \
--token "${{ secrets.BENCHER_API_TOKEN }}" \
--err \
"hyperfine -L bpmnModel benchmark_input/p10x01.bpmn,benchmark_input/p15x01.bpmn,benchmark_input/p17x01.bpmn './target/release/rust_bpmn_analyzer -f ./{bpmnModel} -p safeness,option-to-complete,proper-completion,no-dead-activities' --export-json results.json"
"hyperfine -L bpmnModel benchmark_input/p10x01.bpmn,benchmark_input/p15x01.bpmn,benchmark_input/p17x01.bpmn './target/release/rust_bpmn_analyzer_cli -f ./{bpmnModel} -p safeness,option-to-complete,proper-completion,no-dead-activities' --export-json results.json"
12 changes: 7 additions & 5 deletions .github/workflows/rust.yml → .github/workflows/cli.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
name: Rust compile, lint & test
name: Rust compile, lint & test CLI

on:
workflow_dispatch:
push:
paths:
- src/**
- cli/**
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest
defaults:
run:
working-directory: cli

steps:
- uses: actions/checkout@v4
- name: Build
run: cargo build
- name: Format
run: cargo fmt --check
- name: Lint
run: cargo clippy -- -Dwarnings
- name: Build
run: cargo build
- name: Run tests
run: cargo test -- --show-output
30 changes: 30 additions & 0 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Rust compile, lint & test core

on:
workflow_dispatch:
push:
paths:
- core/**
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest
defaults:
run:
working-directory: core

steps:
- uses: actions/checkout@v4
- name: Format
run: cargo fmt --check
- name: Lint
run: cargo clippy -- -Dwarnings
- name: Build
run: cargo build
- name: Run tests
run: cargo test -- --show-output
43 changes: 43 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build & Push to Azure and Dockerhub

on:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest
defaults:
run:
working-directory: webserver

steps:
- uses: actions/checkout@v4
- name: Add x86_64-unknown-linux-musl target
run: rustup target add x86_64-unknown-linux-musl
- name: Build rust_bpmn_analyzer
run: cargo build --release --target x86_64-unknown-linux-musl
- name: Build docker image
run: docker build -t tg2022.azurecr.io/rust_bpmn_analyzer:v1 .

- name: Login to Azure Container Registry
uses: docker/login-action@v3
with:
registry: ${{ secrets.AZURE_REGISTRY }}
username: ${{ secrets.AZURE_USERNAME }}
password: ${{ secrets.AZURE_PASSWORD }}
- name: Push to Azure
run: docker push tg2022.azurecr.io/rust_bpmn_analyzer:v1

- name: Login to Dockerhub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Tag image
run: docker tag tg2022.azurecr.io/rust_bpmn_analyzer:v1 tkra/rust_bpmn_analyzer
- name: Push to Dockerhub
run: docker push tkra/rust_bpmn_analyzer
29 changes: 29 additions & 0 deletions .github/workflows/webserver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Rust compile, lint & test webserver

on:
workflow_dispatch:
push:
paths:
- webserver/**
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
build:
runs-on: ubuntu-latest
defaults:
run:
working-directory: webserver

steps:
- uses: actions/checkout@v4
- name: Format
run: cargo fmt --check
- name: Lint
run: cargo clippy -- -Dwarnings
- name: Build
run: cargo build
- name: Run tests
run: cargo test -- --show-output
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target
.idea
8 changes: 7 additions & 1 deletion .idea/RustBPMNAnalyzer.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Rust](https://github.com/timKraeuter/rust_bpmn_analyzer/actions/workflows/rust.yml/badge.svg)](https://github.com/timKraeuter/RustBPMNAnalyzer/actions/workflows/rust.yml)
[![Rust](https://github.com/timKraeuter/rust_bpmn_analyzer/actions/workflows/rust.yml/badge.svg)](https://github.com/timKraeuter/Rustrust_bpmn_analyzer/actions/workflows/rust.yml)

[Benchmarks using Bencher🐰](https://bencher.dev/console/projects/rust-bpmn-analyzer/perf)

Expand All @@ -8,6 +8,20 @@ This is a simple BPMN analyzer written in Rust. It is able to parse BPMN files a
certain properties. The analyzer is able to detect deadlocks, livelocks, and other properties of
BPMN models.

# Docker

Building the image is done using GitHub actions (see release.yml).

Pull the application image:
```bash
docker pull tkra/rust_bpmn_analyzer
```

Run the application image:
```bash
docker run -p 8080:8080 tkra/rust_bpmn_analyzer
```

# BPMN coverage

The BPMN elements in green are supported by the analyzer. We follow the structure of
Expand Down Expand Up @@ -375,12 +389,4 @@ Markers, data and artifacts are ignored.
</tr>

</tbody>
</table>

# Build release for the current platform

```bash
cargo build --release
```

Use WSL to build for linux on windows.
</table>
1 change: 1 addition & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
13 changes: 11 additions & 2 deletions Cargo.lock → cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "rust_bpmn_analyzer_cli"
version = "1.0.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.4", features = ["derive"] }
colored = "2.1.0"
rust_bpmn_analyzer = { path = "../core" }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 18 additions & 19 deletions src/lib.rs → cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
mod bpmn;
mod model_checking;
mod output;
mod states;
use clap::Parser;

use crate::bpmn::collaboration::Collaboration;
use crate::bpmn::reader;
use crate::bpmn::reader::UnsupportedBpmnElementsError;
pub use crate::model_checking::properties::{ModelCheckingResult, Property};
use crate::output::property_info::output_property_results;
use crate::output::state_space_info::output_state_information;
use clap::Parser;
use rust_bpmn_analyzer::{ModelCheckingResult, Property};
use std::process;
use std::time::{Duration, Instant};

/// CLI BPMN Analyzer written in Rust
Expand All @@ -24,18 +19,22 @@ pub struct Config {
#[arg(short, long, value_enum, value_delimiter = ',')]
pub properties: Vec<Property>,
}
pub fn run(collaboration: &Collaboration, properties: Vec<Property>) -> ModelCheckingResult {
let start_time = Instant::now();
let result: ModelCheckingResult = collaboration.explore_state_space(properties);
let runtime = start_time.elapsed();

output_result(&result, runtime);

result
}

pub fn read_bpmn_file(file_path: &String) -> Result<Collaboration, UnsupportedBpmnElementsError> {
reader::read_bpmn_file(file_path)
fn main() {
let config = Config::parse();
let collaboration = rust_bpmn_analyzer::read_bpmn_from_file(&config.file_path);
match collaboration {
Ok(collaboration) => {
let start_time = Instant::now();
let result = rust_bpmn_analyzer::run(&collaboration, config.properties);
let runtime = start_time.elapsed();
output_result(&result, runtime);
}
Err(e) => {
eprintln!("Application error: {e}");
process::exit(1);
}
};
}

fn output_result(result: &ModelCheckingResult, runtime: Duration) {
Expand Down
File renamed without changes.
44 changes: 5 additions & 39 deletions src/output/property_info.rs → cli/src/output/property_info.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::model_checking::properties::{ModelCheckingResult, Property, PropertyResult};
use crate::states::state_space::{State, StateSpace};
use colored::{ColoredString, Colorize};
use std::fmt::{Display, Formatter};
use colored::Colorize;
use rust_bpmn_analyzer::model_checking::properties::{
ModelCheckingResult, Property, PropertyResult,
};
use rust_bpmn_analyzer::states::state_space::StateSpace;

pub fn output_property_results(result: &ModelCheckingResult) {
for property_result in result.property_results.iter() {
Expand All @@ -22,21 +23,6 @@ pub fn output_property_results(result: &ModelCheckingResult) {
}
}

impl Display for Property {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", get_property_string(self))
}
}

fn get_property_string(property: &Property) -> ColoredString {
match property {
Property::Safeness => "Safeness".blue().bold(),
Property::OptionToComplete => "Option to complete".blue().bold(),
Property::ProperCompletion => "Proper completion".blue().bold(),
Property::NoDeadActivities => "No dead activities".blue().bold(),
}
}

fn print_result_unfulfilled_details(property_result: &PropertyResult, state_space: &StateSpace) {
match property_result.property {
Property::Safeness => {
Expand Down Expand Up @@ -111,23 +97,3 @@ fn print_counter_example(property_result: &PropertyResult, state_space: &StateSp
}
}
}

impl Display for State<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"messages: {:?}, snapshots: {{ {} }}",
self.messages,
get_state_string(self)
)
}
}

fn get_state_string(state: &State) -> String {
state
.snapshots
.iter()
.map(|snapshot| format!("{}: {:?}", snapshot.id, snapshot.tokens))
.collect::<Vec<String>>()
.join(", ")
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::model_checking::properties::ModelCheckingResult;
use colored::Colorize;
use rust_bpmn_analyzer::model_checking::properties::ModelCheckingResult;
use std::time::Duration;

pub fn output_state_information(result: &ModelCheckingResult, runtime: Duration) {
Expand Down
Loading

0 comments on commit 6e701f9

Please sign in to comment.