Repository navigation
185 lines (167 loc) · 6.39 KB
/
Copy pathci.yaml
File metadata and controls
185 lines (167 loc) · 6.39 KB
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
name: CI
on:
push:
branches: [ "v2" ]
pull_request:
branches: [ "v2" ]
concurrency:
# Groups runs by workflow name and the branch/PR number.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
rust: ${{ steps.filter.outputs.rust }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v4
id: filter
with:
filters: |
rust:
- 'rust/**'
- '.github/workflows/ci.yaml'
# Fast quality gate: fmt + clippy only. Blocks both rust-test and android-test
# so a broken Rust change doesn't waste NDK cross-compilation time.
rust-lint:
needs: detect-changes
if: needs.detect-changes.outputs.rust == 'true'
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./rust
steps:
- uses: actions/checkout@v6
- uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${{ runner.os }}-cargo-host-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-host-
- name: Check formatting
run: cargo fmt --check --all
- name: Clippy
run: cargo clippy --workspace --all-targets -- -D warnings
# A workspace build unifies features, so only a build of its own shows this crate without them.
- name: keygo-core holds no crypto without its feature
run: |
cargo clippy -p keygo-core --all-targets -- -D warnings
deps=$(cargo tree -p keygo-core -e normal --depth 1 --prefix none | tail -n +2 | cut -d' ' -f1 | sort | xargs)
[ "$deps" = "base64 serde thiserror uuid" ] || { echo "unexpected keygo-core deps: $deps" >&2; exit 1; }
- name: keygo-server holds no crypto or client code
run: |
# Proves the pattern below still matches, so renaming the feature can't silently disable it.
client=$(cargo tree -p keygo-client -e features)
grep -q 'keygo-core feature "crypto"' <<<"$client"
server=$(cargo tree -p keygo-server -e features)
if grep -E 'keygo-client|keygo-core feature "crypto"' <<<"$server"; then exit 1; fi
- name: keygo-client cannot mint server ids or tokens
run: |
server=$(cargo tree -p keygo-server -e features)
grep -q 'keygo-api feature "server"' <<<"$server"
client=$(cargo tree -p keygo-client -e features)
if grep 'keygo-api feature "server"' <<<"$client"; then exit 1; fi
# Rust-native tests (no NDK). Runs in parallel with android-test once lint passes.
rust-test:
needs: [ detect-changes, rust-lint ]
if: needs.detect-changes.outputs.rust == 'true'
runs-on: ubuntu-latest
# keygo-server's #[sqlx::test]s create a throwaway database per test through DATABASE_URL.
# SQLX_OFFLINE keeps the query! macros on the committed .sqlx data instead of this empty server.
services:
postgres:
image: postgres:18-trixie
env:
POSTGRES_USER: keygo
POSTGRES_PASSWORD: keygo
POSTGRES_DB: keygo
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U keygo -d keygo"
--health-interval 2s
--health-timeout 5s
--health-retries 15
env:
DATABASE_URL: postgres://keygo:keygo@localhost:5432/keygo
SQLX_OFFLINE: "true"
defaults:
run:
working-directory: ./rust
steps:
- uses: actions/checkout@v6
# Own key: sharing rust-lint's would never save this job's build or the installed sqlx-cli.
- uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin/sqlx
~/.cargo/bin/cargo-sqlx
~/.cargo/.crates.toml
~/.cargo/.crates2.json
rust/target
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-test-
- name: Build
run: cargo build --workspace --all-targets --verbose
# A workspace build unifies features, so keygo-client's "crypto" reaches every crate in it.
# keygo-core and keygo-server are also tested alone, in the form the server ships them.
- name: Run tests
run: cargo test --workspace --exclude keygo-server --verbose
- name: Run keygo-core tests without crypto
run: cargo test -p keygo-core --verbose
- name: Run keygo-server tests
run: cargo test -p keygo-server --verbose
# Offline builds never see the schema, so a migration that changes a queried column would
# still compile against stale .sqlx data. Recompute it against the migrated database instead.
- name: Install sqlx-cli
run: cargo install [email protected] --locked --no-default-features --features postgres
- name: Check committed sqlx query data
working-directory: ./rust/crates/keygo-server
run: |
sqlx migrate run
cargo sqlx prepare --check
# Android unit tests. Waits for rust-lint when rust changed, so NDK cross-compilation isn't
# triggered on code that already fails fmt/clippy.
# buildRust (make all) runs internally via the preBuild Gradle hook and generates
# the UniFFI Kotlin interfaces that the tests compile against.
android-test:
needs: [ detect-changes, rust-lint ]
if: |
always() &&
(
needs.detect-changes.outputs.rust != 'true' ||
needs.rust-lint.result == 'success'
)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up JDK 21
uses: actions/setup-java@v5
with:
java-version: '21'
distribution: 'temurin'
cache: gradle
- uses: gradle/actions/setup-gradle@v6
- uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
rust/target
key: ${{ runner.os }}-cargo-android-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-android-
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
- name: Run unit tests
run: ./gradlew test --continue
- name: Assemble debug APK
run: ./gradlew assembleDebug --stacktrace