CI: add build + lint + test job - #7
Conversation
This workflow includes: - pulling rust-toolchain commands - caching the compiled dependencies and cargo registry after a run - calling cargo fmt - calling cargo clippy
…g task In order for tests being launched in both CI and a local environment, a Taskfile.yml is introduced. It contains a couple of linting and testing tasks. More important is the way that a test task was introduced. So, we want that every each workspace member is always tested. That is achivable through running 'cargo test', however, some workspace members may require running that command with additional parameters (such as event-plugin with test-threads=1). We want to have a persitent way of testing members, so creating a general Taskfile which will contain a separate test for each member won't suit us since we want can possibly slip some out. Therefore, following an approach where every each member is tested by default except the predefined will suit here better.
| # 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 |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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 fmttask 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?
Summary
Add a CI workflow that checks formatting, lints, and tests the Rust code on every PR into
master, using Task to drive the underlyingcargocommands instead of invoking them directly from the workflow.Changes
Taskfile.yml: definesfmt,fmt:check,lint, andtesttasks.testruns in two steps rather than a singlecargo test --workspace: the workspace is tested withevent-pluginexcluded, andevent-pluginis tested separately with--test-threads=1. This is becauseevent-plugin's config tests mutate shared process-wide environment variables and a shared temp config file, so running them in parallel with the rest of the suite races and produces flaky failures - single-threaded execution is required for that crate specifically..github/workflows/code.yml: newbuild-lint-testjob that checks out the code, installs the Rust toolchain (withrustfmt/clippy),protoc, sets up cargo caching, installs Task, and runstask fmt:check,task lint, andtask test.Related issue: 5