Skip to content

Commit 655b4ef

Browse files
authored
Create rust.yml
1 parent 80360a5 commit 655b4ef

File tree

1 file changed

+135
-0
lines changed

1 file changed

+135
-0
lines changed

.github/workflows/rust.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Rust CI
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
pull_request:
7+
branches: [ main, master ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: 1
12+
13+
jobs:
14+
test:
15+
name: Test Suite
16+
runs-on: ${{ matrix.os }}
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
os: [ubuntu-latest, windows-latest, macos-latest]
21+
rust: [stable, beta]
22+
include:
23+
- os: ubuntu-latest
24+
rust: nightly
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Install Rust
30+
uses: dtolnay/rust-toolchain@master
31+
with:
32+
toolchain: ${{ matrix.rust }}
33+
components: rustfmt, clippy
34+
35+
- name: Cache dependencies
36+
uses: actions/cache@v3
37+
with:
38+
path: |
39+
~/.cargo/registry
40+
~/.cargo/git
41+
target
42+
key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}
43+
restore-keys: |
44+
${{ runner.os }}-cargo-${{ matrix.rust }}-
45+
${{ runner.os }}-cargo-
46+
47+
- name: Install dependencies (Ubuntu)
48+
if: matrix.os == 'ubuntu-latest'
49+
run: |
50+
sudo apt-get update
51+
sudo apt-get install -y clang libclang-dev
52+
53+
- name: Install dependencies (macOS)
54+
if: matrix.os == 'macos-latest'
55+
run: |
56+
brew install llvm
57+
58+
- name: Create test environment file
59+
run: |
60+
echo "DB_URL=${{ secrets.DB_URL_TEST }}" > .env
61+
echo "DB_NS=test" >> .env
62+
echo "DB_NAME=test_ci_${{ github.run_id }}" >> .env
63+
echo "DB_USER=${{ secrets.DB_USER_TEST }}" >> .env
64+
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD_TEST }}" >> .env
65+
echo "HCAPTCHA_SECRET=${{ secrets.HCAPTCHA_SECRET_TEST }}" >> .env
66+
echo "JWT_SECRET=${{ secrets.JWT_SECRET_TEST }}" >> .env
67+
echo "WEBSITE_URL=http://localhost:3000" >> .env
68+
echo "TOKEN_DURATION_MIN=120" >> .env
69+
70+
- name: Build
71+
run: cargo build --verbose
72+
73+
- name: Run tests
74+
run: cargo test --verbose
75+
76+
- name: Run clippy
77+
if: matrix.rust == 'stable'
78+
run: cargo clippy -- -D warnings
79+
80+
- name: Check formatting
81+
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest'
82+
run: cargo fmt -- --check
83+
84+
release-build:
85+
name: Release Build
86+
runs-on: ubuntu-latest
87+
steps:
88+
- uses: actions/checkout@v4
89+
90+
- name: Install Rust
91+
uses: dtolnay/rust-toolchain@stable
92+
93+
- name: Install dependencies
94+
run: |
95+
sudo apt-get update
96+
sudo apt-get install -y clang libclang-dev
97+
98+
- name: Cache dependencies
99+
uses: actions/cache@v3
100+
with:
101+
path: |
102+
~/.cargo/registry
103+
~/.cargo/git
104+
target
105+
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
106+
107+
- name: Create minimal env for build check
108+
run: |
109+
echo "DB_URL=memory" > .env
110+
echo "DB_NS=test" >> .env
111+
echo "DB_NAME=test" >> .env
112+
echo "DB_USER=test" >> .env
113+
echo "DB_PASSWORD=test" >> .env
114+
echo "HCAPTCHA_SECRET=test" >> .env
115+
echo "JWT_SECRET=test_secret_key" >> .env
116+
echo "WEBSITE_URL=http://localhost" >> .env
117+
echo "TOKEN_DURATION_MIN=120" >> .env
118+
119+
- name: Build release
120+
run: cargo build --release --verbose
121+
122+
security:
123+
name: Security Audit
124+
runs-on: ubuntu-latest
125+
steps:
126+
- uses: actions/checkout@v4
127+
128+
- name: Install Rust
129+
uses: dtolnay/rust-toolchain@stable
130+
131+
- name: Install cargo-audit
132+
run: cargo install cargo-audit
133+
134+
- name: Run security audit
135+
run: cargo audit

0 commit comments

Comments
 (0)