1
- # .github/workflows/ci.yml
2
-
3
- name : CI
1
+ # This is the name of the workflow that will be displayed on GitHub
2
+ name : Rust CI
4
3
4
+ # This section defines when the workflow will run.
5
+ # It will trigger on any `push` to any branch, and on any `pull_request`.
5
6
on :
6
7
push :
7
- branches : [ main ]
8
+ branches : [ " main" ]
8
9
pull_request :
9
- branches : [ main ]
10
+ branches : [ "main" ]
11
+
12
+ # This defines the environment for the workflow. We set Cargo to use color output.
13
+ env :
14
+ CARGO_TERM_COLOR : always
10
15
16
+ # This section defines the jobs to be run. We have one job called "build".
11
17
jobs :
12
- build_and_test :
13
- name : Rust Project
14
- runs-on : ubuntu-latest
18
+ build :
19
+ # The name that will be displayed for this job on GitHub
20
+ name : Test on ${{ matrix.os }}
21
+
22
+ # This job will run on multiple operating systems to ensure cross-platform compatibility
23
+ runs-on : ${{ matrix.os }}
24
+ strategy :
25
+ matrix :
26
+ os : [ubuntu-latest, macos-latest, windows-latest]
27
+
28
+ # These are the individual steps the job will execute in order
15
29
steps :
16
- - uses : actions/checkout@v4
30
+ # 1. Check out the repository code so the workflow can access it
31
+ - uses : actions/checkout@v4
32
+
33
+ # 2. Cache the cargo directories to speed up future builds
34
+ - name : Cache cargo dependencies
35
+ uses : actions/cache@v4
36
+ with :
37
+ path : |
38
+ ~/.cargo/bin/
39
+ ~/.cargo/registry/index/
40
+ ~/.cargo/registry/cache/
41
+ ~/.cargo/git/db/
42
+ target/
43
+ key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
17
44
18
- - name : Install Rust toolchain
19
- uses : dtolnay/rust-toolchain@stable
20
- with :
21
- components : rustfmt
45
+ # 3. Check that the code is formatted correctly
46
+ - name : Check formatting
47
+ run : cargo fmt -- --check
22
48
23
- - name : Check formatting
24
- run : cargo fmt -- --check
49
+ # 4. Run Clippy to check for common mistakes and enforce idiomatic Rust
50
+ # The `-D warnings` flag treats all warnings as errors, failing the build.
51
+ - name : Run Clippy
52
+ run : cargo clippy -- -D warnings
25
53
26
- - name : Run Clippy
27
- run : cargo clippy -- -D warnings
54
+ # 5. Run the tests (if any are defined)
55
+ - name : Run tests
56
+ run : cargo test --verbose
28
57
29
- - name : Run tests
30
- run : cargo test
58
+ # 6. Build the project in release mode to ensure it compiles
59
+ - name : Build
60
+ run : cargo build --release --verbose
0 commit comments