1+ name : CI
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ pull_request :
7+ branches : [ main ]
8+ workflow_dispatch : # Allow manual trigger
9+
10+ jobs :
11+ build :
12+ name : Build Flake
13+ runs-on : ubuntu-latest
14+ steps :
15+ - uses : actions/checkout@v3
16+
17+ - uses : cachix/install-nix-action@v23
18+ with :
19+ nix_path : nixpkgs=channel:nixos-unstable
20+ extra_nix_config : |
21+ experimental-features = nix-command flakes
22+
23+ - name : Cache Nix store
24+ uses : actions/cache@v3
25+ with :
26+ path : |
27+ ~/.cache/nix
28+ key : ${{ runner.os }}-nix-${{ hashFiles('flake.lock') }}
29+ restore-keys : |
30+ ${{ runner.os }}-nix-
31+
32+ - name : Build flake
33+ run : |
34+ nix flake check
35+ nix develop -c echo "Flake development environment builds successfully"
36+ lint :
37+ name : Lint
38+ runs-on : ubuntu-latest
39+ needs : [build]
40+ steps :
41+ - uses : actions/checkout@v3
42+
43+ - uses : cachix/install-nix-action@v23
44+ with :
45+ nix_path : nixpkgs=channel:nixos-unstable
46+ extra_nix_config : |
47+ experimental-features = nix-command flakes
48+
49+ - name : Cache Nix store
50+ uses : actions/cache@v3
51+ with :
52+ path : |
53+ ~/.cache/nix
54+ key : ${{ runner.os }}-nix-${{ hashFiles('flake.lock') }}
55+ restore-keys : |
56+ ${{ runner.os }}-nix-
57+
58+ - name : Run lint
59+ run : |
60+ # Use nix develop to run linting tools defined in flake.nix
61+ nix develop --command black --check server.py test_mcp.py
62+ nix develop --command mypy server.py test_mcp.py
63+
64+ test-dry :
65+ name : Test (Dry Run)
66+ runs-on : ubuntu-latest
67+ needs : [build]
68+ steps :
69+ - uses : actions/checkout@v3
70+
71+ - uses : cachix/install-nix-action@v23
72+ with :
73+ nix_path : nixpkgs=channel:nixos-unstable
74+ extra_nix_config : |
75+ experimental-features = nix-command flakes
76+
77+ - name : Cache Nix store
78+ uses : actions/cache@v3
79+ with :
80+ path : |
81+ ~/.cache/nix
82+ key : ${{ runner.os }}-nix-${{ hashFiles('flake.lock') }}
83+ restore-keys : |
84+ ${{ runner.os }}-nix-
85+
86+ - name : Cache Python virtual environment
87+ uses : actions/cache@v3
88+ with :
89+ path : .venv
90+ key : ${{ runner.os }}-venv-${{ hashFiles('requirements.txt') }}
91+ restore-keys : |
92+ ${{ runner.os }}-venv-
93+
94+ - name : Setup and run dry tests
95+ run : |
96+ # Use nix develop to set up environment and run tests
97+ nix develop --command setup
98+ nix develop --command run-tests-dry
99+
100+ test-full :
101+ name : Test (Full)
102+ runs-on : ubuntu-latest
103+ needs : [lint, test-dry]
104+ steps :
105+ - uses : actions/checkout@v3
106+
107+ - uses : cachix/install-nix-action@v23
108+ with :
109+ nix_path : nixpkgs=channel:nixos-unstable
110+ extra_nix_config : |
111+ experimental-features = nix-command flakes
112+
113+ - name : Cache Nix store
114+ uses : actions/cache@v3
115+ with :
116+ path : |
117+ ~/.cache/nix
118+ key : ${{ runner.os }}-nix-${{ hashFiles('flake.lock') }}
119+ restore-keys : |
120+ ${{ runner.os }}-nix-
121+
122+ - name : Cache Python virtual environment
123+ uses : actions/cache@v3
124+ with :
125+ path : .venv
126+ key : ${{ runner.os }}-venv-${{ hashFiles('requirements.txt') }}
127+ restore-keys : |
128+ ${{ runner.os }}-venv-
129+
130+ - name : Install NixOS tools
131+ run : |
132+ # Only needed for full tests that require nixos-option
133+ sudo apt-get update
134+ sudo apt-get install -y curl
135+
136+ - name : Setup and run full tests
137+ run : |
138+ # Setup environment
139+ nix develop --command setup
140+ nix develop --command setup-test
141+
142+ # Start server in background
143+ nix develop --command run --port=9421 &
144+ SERVER_PID=$!
145+
146+ # Wait for server to start
147+ echo "Waiting for server to start..."
148+ for i in {1..30}; do
149+ if curl -s http://localhost:9421/docs &>/dev/null; then
150+ echo "Server started successfully!"
151+ break
152+ fi
153+ if [ $i -eq 30 ]; then
154+ echo "Server failed to start in time"
155+ kill $SERVER_PID
156+ exit 1
157+ fi
158+ sleep 1
159+ done
160+
161+ # Run tests against running server
162+ nix develop --command run-tests-with-server
163+ TEST_EXIT=$?
164+
165+ # Clean up server
166+ kill $SERVER_PID
167+
168+ # Return the test exit code
169+ exit $TEST_EXIT
0 commit comments