Skip to content
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
37 changes: 37 additions & 0 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on:
pull_request:
branches: [master]

jobs:
build-lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

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

- name: Install protoc
uses: arduino/setup-protoc@v3

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

- name: Install Task
uses: arduino/setup-task@v2
with:
version: 3.x

- name: Check formatting
run: task fmt:check

- name: Run clippy
run: task lint

- name: Run tests
run: task test
27 changes: 27 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"

tasks:
fmt:
desc: "Format Rust code"
cmds: [cargo fmt]

fmt:check:
desc: "Check Rust code formatting"
cmds: [ cargo fmt --check]

lint:
desc: "Lint Rust code"
cmds: [cargo clippy --all-targets --all-features -- -D warnings]

test:
desc: "Test Rust code"
cmds:
# We want to be sure every workspace member is always tested.
# However, some members need special parameters
# (e.g. event-plugin tests must run in a single thread),
# so a single 'cargo test' can't cover everything correctly.
# Therefore, task:test runs every workspace member EXCEPT the
# excluded ones (e.g. event-plugin), and the excluded members
# are run separately with their own command.
- cargo test --workspace --exclude event-plugin

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should create separate tasks/makefiles for each project and define a naming convention for tasks across all plugins (like, each plugin should have task called test, build, etc)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have that one and thats sounds pretty logical. However, I'd like to go with more error-prone way. To have a task/makefile for each project is fine for me, but:

  • requires code reduplicating - e.g. we would need to write the same cargo fmt task command for each project taskfile. Of course, we can create a single taskfile and just import what we need from it, however, we'd like to make plugins independent from each other;
  • for an every new plugin we should update the root taskfile. And that's might be fine, but we should always remember to do so. If the testing command is somehow slipped from adding to the root taskfile, then we are risking to leave the plugin without tests which may lead to the unwanted consequences.

The approach that I introduced here helps us to mitigate cases stated above - the code is always tested no matter a new plugin was introduced or not; no additional steps are required (unless there're some special testing cases that we might introduce); no code duplicated; plugins are independent. What do you think about my intention?

- cargo test -p event-plugin -- --test-threads=1
Loading