-
Notifications
You must be signed in to change notification settings - Fork 13
199 lines (191 loc) · 6.65 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# yaml-language-server: $schema=https://raw.githubusercontent.com/softprops/github-actions-schemas/master/workflow.json
name: CI
on:
push:
branches: [ "main" ]
paths:
- "**.rs" # Any rust file
- "**/Cargo.toml" # Any Cargo.toml
- ".rustfmt.toml"
- ".github/workflows/ci.yml" # This action
pull_request:
branches: [ "main" ]
paths:
- "**.rs" # Any rust file
- "**/Cargo.toml" # Any Cargo.toml
- ".rustfmt.toml"
- ".github/workflows/ci.yml" # This action
env:
CARGO_TERM_COLOR: always
jobs:
# First check that we can build EVERYTHING and that tests pass
build_first:
name: "Build, check, and test with all features"
runs-on: ubuntu-latest
outputs:
cli: ${{ steps.filter.outputs.cli }}
lib: ${{ steps.filter.outputs.lib }}
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo-deps"
cache-targets: false
- name: Run Build
run: cargo check --verbose --workspace --bins --lib --examples --all-features
- name: Run Tests
run: cargo test --verbose --workspace --bins --lib --examples --tests --all-features
# Check what paths were modified so we only run the required tests
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
cli:
- 'crates/cli/**'
lib:
- 'crates/lib/**'
# If we were able to build then test different feature combinations compile with the library
build_lib:
runs-on: ubuntu-latest
needs: [ "build_first" ]
# Only run if library files were modified
if: ${{ needs.build_first.outputs.lib == 'true' }}
strategy:
fail-fast: false
matrix:
include:
- build_type: ""
build_name: "Default"
- build_type: "--no-default-features"
build_name: "No features"
- build_type: "--no-default-features --features games"
build_name: "Just games"
- build_type: "--no-default-features --features services"
build_name: "Just Services"
- build_type: "--no-default-features --features game_defs"
build_name: "Just Game definitions"
- build_type: "--no-default-features --features serde"
build_name: "Just serde"
name: "Build library ${{ matrix.build_name }}"
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo-deps"
cache-targets: false
save-if: false
- name: Run Build
run: cargo check -p gamedig --verbose --lib --examples --tests ${{ matrix.build_type }}
# If we were able to build then test different feature combinations compile with the CLI
build_cli:
runs-on: ubuntu-latest
needs: [ "build_first" ]
# Only run if CLI files were modified
if: ${{ needs.build_first.outputs.cli == 'true' }}
strategy:
fail-fast: false
matrix:
include:
- build_type: ""
build_name: "Default"
- build_type: "--no-default-features"
build_name: "No features"
name: "Build CLI ${{ matrix.build_name }}"
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo-deps"
cache-targets: false
save-if: false
- name: Run Build
run: cargo check -p gamedig-cli --verbose --bins --examples --tests ${{ matrix.build_type }}
# If we were able to build then test the MSRV compiles (for the libary as not enforced for CLI)
build_msrv:
name: "Build using MSRV (lib only)"
runs-on: ubuntu-latest
needs: [ "build_first" ]
# Only run if library files were modified
if: ${{ needs.build_first.outputs.lib == 'true' }}
# Unfortunate hard-coding of rustup directory so that rust-cache caches it
env:
RUSTUP_HOME: /home/runner/.rustup
steps:
# Act's rust runner has rustup in a different place
- if: ${{ env.ACT }}
run: mkdir -p /home/runner && ln -s /usr/share/rust/.rustup /home/runner/.rustup
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
cache-targets: false
cache-directories: ${{ env.RUSTUP_HOME }}/toolchains
- name: Install MSRV
uses: actions-rs/toolchain@v1
with:
toolchain: 1.65.0
override: true
- name: Run MSRV
run: cargo check -p gamedig
# Check the code is formatted properly
formatting:
name: "Check code formatting"
runs-on: ubuntu-latest
# Unfortunate hard-coding of rustup directory so that rust-cache caches it
env:
RUSTUP_HOME: /home/runner/.rustup
steps:
# Act's rust runner has rustup in a different place
- if: ${{ env.ACT }}
run: mkdir -p /home/runner && ln -s /usr/share/rust/.rustup /home/runner/.rustup
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
cache-targets: false
cache-directories: ${{ env.RUSTUP_HOME }}/toolchains
- name: Install Formatting nightly
uses: actions-rs/toolchain@v1
with:
toolchain: nightly-2023-07-09
components: rustfmt
override: true
- name: Run Formatting check
run: cargo fmt --check --verbose
# If we were able to build then lint the codebase with clippy
clippy:
name: "Run clippy tests"
runs-on: ubuntu-latest
needs: [ "build_first" ]
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo-deps"
cache-targets: false
save-if: false
# Run github actions version of clippy that adds annotations
- name: Run Clippy
uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --bins --lib --examples --tests --all-features
if: ${{ !env.ACT }} # skip during local actions testing
# Run clippy binary
- name: Run clippy (local)
run: cargo clippy --verbose --workspace --bins --lib --examples --tests --all-features
if: ${{ env.ACT }} # only run during local actions testing
# If we were able to build then test that rustdoc (and rustdoc examples) compile
doc:
name: "Check rustdoc"
runs-on: ubuntu-latest
needs: [ "build_first" ]
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
shared-key: "cargo-deps"
cache-targets: false
save-if: false
- name: "Run cargo doc"
run: cargo doc --workspace
env:
RUSTDOCFLAGS: "-D warnings"