-
Notifications
You must be signed in to change notification settings - Fork 0
232 lines (205 loc) · 8.12 KB
/
Copy pathci.yml
File metadata and controls
232 lines (205 loc) · 8.12 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# =============================================================================
# SynthStack Community Edition - CI Workflow
# =============================================================================
# This workflow runs tests and linting for the community edition.
#
# For deployment workflows, see docs/DEPLOYMENT_GUIDE.md
# The deployment jobs are commented out below and can be enabled when you have:
# - Your own server infrastructure
# - GitHub secrets configured (REMOTE_HOST, SSH keys, etc.)
# =============================================================================
name: CI
on:
push:
branches: ["main", "master", "develop"]
pull_request:
branches: ["main", "master", "develop"]
env:
NODE_VERSION: "20"
PNPM_VERSION: "9"
jobs:
# =========================================
# Code Quality & Testing
# =========================================
test:
name: Test & Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run Linting
id: lint
run: |
pnpm lint && echo "lint_status=✅ Passed" >> $GITHUB_OUTPUT || echo "lint_status=⚠️ Issues found" >> $GITHUB_OUTPUT
continue-on-error: true
- name: Run Type Checking
id: typecheck
run: |
pnpm typecheck && echo "typecheck_status=✅ Passed" >> $GITHUB_OUTPUT || echo "typecheck_status=⚠️ Issues found" >> $GITHUB_OUTPUT
continue-on-error: true
- name: Run Unit Tests
id: tests
run: |
# Run tests and capture output
pnpm test --reporter=json --outputFile=test-results.json 2>&1 | tee test-output.txt
# Extract test counts from Vitest output
TESTS_PASSED=$(grep -oP '\d+(?= passed)' test-output.txt | head -1 || echo "0")
TESTS_FAILED=$(grep -oP '\d+(?= failed)' test-output.txt | head -1 || echo "0")
TEST_FILES=$(grep -oP '\d+(?= test files)' test-output.txt | head -1 || echo "0")
# Calculate totals
TOTAL_TESTS=$((TESTS_PASSED + TESTS_FAILED))
if [ "$TOTAL_TESTS" -gt 0 ]; then
PASS_RATE=$((TESTS_PASSED * 100 / TOTAL_TESTS))
else
PASS_RATE=0
fi
echo "tests_passed=$TESTS_PASSED" >> $GITHUB_OUTPUT
echo "tests_failed=$TESTS_FAILED" >> $GITHUB_OUTPUT
echo "tests_total=$TOTAL_TESTS" >> $GITHUB_OUTPUT
echo "test_files=$TEST_FILES" >> $GITHUB_OUTPUT
echo "pass_rate=$PASS_RATE" >> $GITHUB_OUTPUT
# Fail if tests failed
if [ "$TESTS_FAILED" -gt 0 ]; then
exit 1
fi
continue-on-error: true
- name: Generate Test Summary
if: always()
run: |
echo "## 🧪 Test Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Metric | Result |" >> $GITHUB_STEP_SUMMARY
echo "|--------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| **Tests Passed** | ${{ steps.tests.outputs.tests_passed || '0' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Tests Failed** | ${{ steps.tests.outputs.tests_failed || '0' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Total Tests** | ${{ steps.tests.outputs.tests_total || '0' }} |" >> $GITHUB_STEP_SUMMARY
echo "| **Pass Rate** | ${{ steps.tests.outputs.pass_rate || '0' }}% |" >> $GITHUB_STEP_SUMMARY
echo "| **Test Files** | ${{ steps.tests.outputs.test_files || '0' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Code Quality" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Linting | ${{ steps.lint.outputs.lint_status || '⚠️ Skipped' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Type Checking | ${{ steps.typecheck.outputs.typecheck_status || '⚠️ Skipped' }} |" >> $GITHUB_STEP_SUMMARY
# =========================================
# Build Frontend
# =========================================
build-web:
name: Build Web App
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: ${{ env.PNPM_VERSION }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build Web Application
run: pnpm --filter @synthstack/web build
env:
# These can be overridden via GitHub repository variables
VITE_API_URL: ${{ vars.VITE_API_URL || 'http://localhost:3003' }}
VITE_SUPABASE_URL: ${{ vars.VITE_SUPABASE_URL || '' }}
VITE_SUPABASE_ANON_KEY: ${{ secrets.VITE_SUPABASE_ANON_KEY || '' }}
- name: Upload Web Build Artifact
uses: actions/upload-artifact@v4
with:
name: web-dist
path: apps/web/dist/spa
retention-days: 7
# =============================================================================
# DEPLOYMENT JOBS (DISABLED)
# =============================================================================
# Uncomment and configure these jobs for production deployment.
# Required secrets:
# - REMOTE_HOST_PRODUCTION: Your server IP
# - REMOTE_USER: SSH username (usually 'root')
# - REMOTE_SSH_KEY: Your SSH private key
# - GH_PAT: GitHub Personal Access Token for pulling images
#
# See docs/DEPLOYMENT_GUIDE.md for full setup instructions.
# =============================================================================
# build-api:
# name: Build API Docker Image
# runs-on: ubuntu-latest
# needs: test
# if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
#
# permissions:
# contents: read
# packages: write
#
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
#
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3
#
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Build and push API image
# uses: docker/build-push-action@v5
# with:
# context: .
# file: ./packages/api-gateway/Dockerfile
# push: true
# tags: ghcr.io/${{ github.repository }}/api:latest
# deploy-production:
# name: Deploy to Production
# runs-on: ubuntu-latest
# needs: [build-web, build-api]
# if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
# environment: production
#
# steps:
# - name: Checkout code
# uses: actions/checkout@v4
#
# - name: Download Web Build
# uses: actions/download-artifact@v4
# with:
# name: web-dist
# path: ./dist
#
# - name: Setup SSH Key
# run: |
# mkdir -p ~/.ssh
# echo "${{ secrets.REMOTE_SSH_KEY }}" > ~/.ssh/deploy_key
# chmod 600 ~/.ssh/deploy_key
# ssh-keyscan -H ${{ secrets.REMOTE_HOST_PRODUCTION }} >> ~/.ssh/known_hosts
#
# - name: Deploy Web to Production
# run: |
# rsync -avz --delete -e "ssh -i ~/.ssh/deploy_key" \
# ./dist/ ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST_PRODUCTION }}:/var/www/synthstack/
#
# - name: Deploy Services
# run: |
# ssh -i ~/.ssh/deploy_key ${{ secrets.REMOTE_USER }}@${{ secrets.REMOTE_HOST_PRODUCTION }} \
# 'cd /opt/synthstack && docker compose pull && docker compose up -d'