-
Notifications
You must be signed in to change notification settings - Fork 2
149 lines (123 loc) · 3.84 KB
/
Copy pathjs-client-test.yml
File metadata and controls
149 lines (123 loc) · 3.84 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
name: JavaScript client tests
env:
RUST_VERSION: 1.97.1
RUST_BACKTRACE: 1
on:
pull_request:
push:
branches:
- master
jobs:
test:
name: test
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-22.04-arm]
node-version: [22]
services:
postgres:
image: postgres:15.4-alpine
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: nittei
ports:
- 5432:5432
env:
# Needed for sqlx
DATABASE_URL: postgresql://postgres:postgres@localhost/nittei
NITTEI__HTTP_PORT: 5000
NITTEI__PG__DATABASE_URL: postgresql://postgres:postgres@localhost/nittei
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
# Setup Rust as we need to run the server
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
- name: Install mold
run: |
sudo apt-get update
sudo apt-get install -y mold
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}--${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Build server and run migrations
run: |
echo "Running migrations"
cargo install sqlx-cli --no-default-features --features postgres || true
(cd crates/infra && sqlx migrate run)
echo "Building server"
cargo build
- name: Install JS modules
run: |
cd clients/javascript
pnpm i
- name: Check if generated types are up-to-date
run: |
# Copy the generated types to a temporary folder for comparison
cd clients/javascript
cp -r ./lib/gen_types ./lib/gen_types_copy
cd ../..
bash ./scripts/generate_ts_types.sh
# Compare the generated types with the copied ones
cd clients/javascript
diff -r ./lib/gen_types ./lib/gen_types_copy
# Get the exit code of the diff command
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "Generated types are not up-to-date"
echo "Generate them with 'just generate-ts-types' and commit the changes"
exit 1
fi
# Remove the temporary folder
rm -rf ./lib/gen_types_copy
- name: Type check and build JS
run: |
cd clients/javascript
pnpm run type-check
pnpm run build
- name: Start server and run tests
run: |
echo "Starting server"
./target/debug/nittei &> output.log &
echo "Started server in background"
IS_READY=false
# Wait for backend server to be ready
RETRIES=20
PORT=${NITTEI__HTTP_PORT}
until [ "$IS_READY" = true ] || [ $((RETRIES--)) -eq 0 ]; do
if curl localhost:$PORT/api/v1/health/live >/dev/null 2>&1; then
IS_READY=true
break
fi
echo "Waiting for server to be ready"
sleep 1
done
if [ "$IS_READY" = false ]; then
echo "Server did not start in time"
exit 1
fi
# Run tests
cd clients/javascript
pnpm run test
- name: Run print output of server
if: always()
run: |
cat output.log
- name: Stop server
if: always()
run: |
kill $(lsof -t -i:${NITTEI__HTTP_PORT}) || true
echo "Stopped server"