99env :
1010 CARGO_TERM_COLOR : always
1111 RUST_BACKTRACE : 1
12- DATABASE_URL : postgres://oppskrift:oppskrift@localhost:5432/oppskrift
12+ SQLX_OFFLINE : true
13+ # Test-only encryption key for 2FA (64 hex chars = 32 bytes)
14+ TOTP_ENCRYPTION_KEY : " 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
1315
1416jobs :
15- # Build first - all other jobs depend on this
16- build :
17- name : Build
18- runs-on : ubuntu-latest
19- services :
20- postgres :
21- image : postgres:15-alpine
22- env :
23- POSTGRES_USER : oppskrift
24- POSTGRES_PASSWORD : oppskrift
25- POSTGRES_DB : oppskrift
26- ports :
27- - 5432:5432
28- options : >-
29- --health-cmd pg_isready
30- --health-interval 10s
31- --health-timeout 5s
32- --health-retries 5
33- steps :
34- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
35- - uses : dtolnay/rust-toolchain@f7ccc83f9ed1e5b9c81d8a67d7ad1a747e22a561 # master
36- with :
37- toolchain : stable
38- - uses : Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
39- with :
40- cache-all-crates : " true"
41- shared-key : " build"
42- - name : Install sqlx-cli
43- run : cargo install sqlx-cli --no-default-features --features postgres
44- - name : Run migrations
45- run : sqlx migrate run
46- - name : Build
47- run : cargo build --all-features
48- # Cache build artifacts for other jobs
49- - name : Save build artifacts
50- uses : actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
51- with :
52- path : |
53- target/
54- ~/.cargo/registry/
55- ~/.cargo/git/
56- key : build-${{ github.sha }}
57-
58- # Format check - no dependencies, fast
17+ # Fast checks - no dependencies, run in parallel
5918 fmt :
6019 name : Format
6120 runs-on : ubuntu-latest
@@ -67,51 +26,38 @@ jobs:
6726 components : rustfmt
6827 - run : cargo fmt --all -- --check
6928
70- # Clippy - depends on build, reuses build cache
71- clippy :
72- name : Clippy
73- needs : build
29+ # Build and lint - uses SQLX_OFFLINE, no database needed
30+ check :
31+ name : Check & Clippy
7432 runs-on : ubuntu-latest
75- services :
76- postgres :
77- image : postgres:15-alpine
78- env :
79- POSTGRES_USER : oppskrift
80- POSTGRES_PASSWORD : oppskrift
81- POSTGRES_DB : oppskrift
82- ports :
83- - 5432:5432
84- options : >-
85- --health-cmd pg_isready
86- --health-interval 10s
87- --health-timeout 5s
88- --health-retries 5
8933 steps :
9034 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
9135 - uses : dtolnay/rust-toolchain@f7ccc83f9ed1e5b9c81d8a67d7ad1a747e22a561 # master
9236 with :
9337 toolchain : stable
9438 components : clippy
95- # Restore build artifacts from build job
96- - name : Restore build artifacts
97- uses : actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
39+ - uses : Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
40+ - name : Build
41+ run : cargo build --all-features
42+ - name : Clippy
43+ run : cargo clippy --all-features -- -D warnings
44+ # Save artifacts for test job
45+ - uses : actions/cache/save@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
9846 with :
9947 path : |
10048 target/
10149 ~/.cargo/registry/
10250 ~/.cargo/git/
10351 key : build-${{ github.sha }}
104- - name : Install sqlx-cli
105- run : cargo install sqlx-cli --no-default-features --features postgres
106- - name : Run migrations
107- run : sqlx migrate run
108- - run : cargo clippy --all-features -- -D warnings
10952
110- # Tests - depends on build, reuses build cache
53+ # Tests need real database
11154 test :
11255 name : Test
113- needs : build
56+ needs : check
11457 runs-on : ubuntu-latest
58+ env :
59+ DATABASE_URL : postgres://oppskrift:oppskrift@localhost:5432/oppskrift
60+ SQLX_OFFLINE : false
11561 services :
11662 postgres :
11763 image : postgres:15-alpine
@@ -131,27 +77,23 @@ jobs:
13177 - uses : dtolnay/rust-toolchain@f7ccc83f9ed1e5b9c81d8a67d7ad1a747e22a561 # master
13278 with :
13379 toolchain : stable
134- # Restore build artifacts from build job
135- - name : Restore build artifacts
136- uses : actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
80+ - uses : actions/cache/restore@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
13781 with :
13882 path : |
13983 target/
14084 ~/.cargo/registry/
14185 ~/.cargo/git/
14286 key : build-${{ github.sha }}
87+ - name : Cache sqlx-cli
88+ id : cache-sqlx
89+ uses : actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
90+ with :
91+ path : ~/.cargo/bin/sqlx
92+ key : sqlx-cli-0.8
14393 - name : Install sqlx-cli
144- run : cargo install sqlx-cli --no-default-features --features postgres
94+ if : steps.cache-sqlx.outputs.cache-hit != 'true'
95+ run : cargo install sqlx-cli --no-default-features --features postgres --locked
14596 - name : Run migrations
14697 run : sqlx migrate run
147- - run : cargo test --all-features
148-
149- # Security audit - no dependencies, can run in parallel
150- audit :
151- name : Security Audit
152- runs-on : ubuntu-latest
153- steps :
154- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
155- - uses : rustsec/audit-check@69366f33c96575abad1ee0dba8212993eecbe998 # v2.0.0
156- with :
157- token : ${{ secrets.GITHUB_TOKEN }}
98+ - name : Run tests
99+ run : cargo test --all-features
0 commit comments