-
Notifications
You must be signed in to change notification settings - Fork 1
198 lines (189 loc) · 6.16 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
# CI workflow for Rusty Pong
# Handles testing, code quality checks, and web deployment
name: CI
# Trigger on pushes to master branch, version tags, and PRs
on:
push:
branches:
- master
tags:
- "v*.*.*"
pull_request:
types: [opened, synchronize, reopened]
branches:
- master
env:
CARGO_TERM_COLOR: always
jobs:
# Check code formatting - fastest check
fmt:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev libudev-dev
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt --all --check
# Run clippy lints for code quality - second fastest check
clippy:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev libudev-dev
- uses: dtolnay/rust-toolchain@clippy
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo clippy --workspace --all-targets --all-features
# Run tests across multiple Rust toolchains and feature combinations
test:
needs: [clippy, fmt]
name: test ${{ matrix.rust }} ${{ matrix.flags }}
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
rust: ["stable", "beta", "nightly", "1.82"] # MSRV
flags: ["--no-default-features", "", "--all-features"]
exclude:
- rust: "1.82"
flags: "--all-features"
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev libudev-dev
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: check
if: ${{ matrix.rust == '1.82' }}
run: cargo check --workspace ${{ matrix.flags }}
- name: test
if: ${{ matrix.rust != '1.82' }}
run: cargo test --workspace ${{ matrix.flags }}
# Generate and upload code coverage information
coverage:
needs: [test]
name: Code Coverage
runs-on: ubuntu-latest
env:
LLVMCOV_VERSION: 0.5.14
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev libudev-dev
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
override: true
profile: minimal
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
with:
shared-key: rust-cache-coverage-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}-${{ env.LLVMCOV_VERSION }}
- name: Install cargo-llvm-cov
run: cargo install cargo-llvm-cov --version=${{ env.LLVMCOV_VERSION }} --locked
- name: Generate code coverage
run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: lcov.info
fail_ci_if_error: false
# Check all possible feature combinations work
feature-checks:
needs: [test]
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev libudev-dev
- uses: dtolnay/rust-toolchain@stable
- uses: taiki-e/install-action@cargo-hack
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: cargo hack
run: cargo hack check --feature-powerset --depth 2
# Generate and test documentation
docs:
needs: [test]
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev libudev-dev
- uses: dtolnay/rust-toolchain@nightly
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- run: cargo doc --workspace --all-features --no-deps --document-private-items
env:
RUSTDOCFLAGS: "--cfg docsrs"
# Build WASM bundle and deploy to GitHub Pages
build-and-deploy:
name: Build and Deploy
needs: [test, coverage, feature-checks, docs]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
permissions:
contents: write
concurrency: ci-${{ github.ref }}
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libasound2-dev libudev-dev binaryen
- name: Install wasm-pack
uses: jetli/[email protected]
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Install Rust dependencies
run: |
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: true
- name: Build and optimize wasm
run: |
cargo build --release --target wasm32-unknown-unknown
mkdir -p dist
wasm-bindgen --out-dir ./dist --target web target/wasm32-unknown-unknown/release/rusty_pong.wasm
find ./dist -name "*.wasm" -exec wasm-opt -Oz --zero-filled-memory --strip-producers -o {}.opt {} \; -exec mv {}.opt {} \;
- name: Prepare deployment
run: |
mkdir -p dist/assets
cp -r assets/* dist/assets/
cp web/index.html dist/
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist
branch: gh-pages
clean: true