test: add frontend and backend unit tests (#20) #50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI-CD | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| - development | |
| pull_request: | |
| branches: | |
| - main | |
| - dev | |
| - development | |
| jobs: | |
| checks: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 30 | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: npm | |
| cache-dependency-path: app/package-lock.json | |
| - name: Build frontend | |
| working-directory: app | |
| run: | | |
| npm ci | |
| npm run build | |
| - name: Setup Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install backend dependencies | |
| working-directory: api | |
| run: | | |
| python -m pip install --no-input --upgrade pip | |
| pip install --no-input -r requirements.txt | |
| - name: Run backend tests | |
| working-directory: api | |
| run: python -m pytest -q | |
| deploy-development: | |
| if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/development' | |
| needs: checks | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| environment: | |
| name: development | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js for Vercel CLI | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Install Vercel CLI | |
| run: npm install -g vercel@25.1.0 | |
| - name: Link Vercel project | |
| working-directory: app | |
| env: | |
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
| VERCEL_SCOPE: ${{ secrets.VERCEL_SCOPE }} | |
| run: | | |
| vercel link \ | |
| --project app \ | |
| --scope "$VERCEL_SCOPE" \ | |
| --confirm \ | |
| --token "$VERCEL_TOKEN" | |
| - name: Write .env.production | |
| working-directory: app | |
| run: echo "NEXT_PUBLIC_API_BASE=${{ secrets.NEXT_PUBLIC_API_BASE_DEV }}" > .env.production | |
| - name: Deploy frontend (Vercel) | |
| working-directory: app | |
| env: | |
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
| VERCEL_SCOPE: ${{ secrets.VERCEL_SCOPE }} | |
| run: | | |
| attempt=1 | |
| max_attempts=3 | |
| while :; do | |
| if vercel deploy --confirm --token "$VERCEL_TOKEN" --scope "$VERCEL_SCOPE"; then | |
| break | |
| fi | |
| if [ "$attempt" -ge "$max_attempts" ]; then | |
| echo "Vercel deploy failed after ${max_attempts} attempt(s)." | |
| exit 1 | |
| fi | |
| sleep_seconds=$((attempt * 10)) | |
| echo "Vercel deploy failed. Retry ${attempt}/${max_attempts} in ${sleep_seconds}s..." | |
| sleep "$sleep_seconds" | |
| attempt=$((attempt + 1)) | |
| done | |
| # Railway: auto-deploys from dev branch via GitHub integration. | |
| # No CLI or deploy hook needed — Railway watches this branch | |
| # and waits for CI checks to pass ("Check Suites" enabled). | |
| deploy-production: | |
| if: github.ref == 'refs/heads/main' | |
| needs: checks | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| environment: | |
| name: production | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js for Vercel CLI | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Install Vercel CLI | |
| run: npm install -g vercel@25.1.0 | |
| - name: Link Vercel project | |
| working-directory: app | |
| env: | |
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
| VERCEL_SCOPE: ${{ secrets.VERCEL_SCOPE }} | |
| run: | | |
| vercel link \ | |
| --project app \ | |
| --scope "$VERCEL_SCOPE" \ | |
| --confirm \ | |
| --token "$VERCEL_TOKEN" | |
| - name: Write .env.production | |
| working-directory: app | |
| run: echo "NEXT_PUBLIC_API_BASE=${{ secrets.NEXT_PUBLIC_API_BASE_PROD }}" > .env.production | |
| - name: Deploy frontend (Vercel) | |
| working-directory: app | |
| env: | |
| VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} | |
| VERCEL_SCOPE: ${{ secrets.VERCEL_SCOPE }} | |
| run: | | |
| attempt=1 | |
| max_attempts=3 | |
| while :; do | |
| if vercel deploy --prod --confirm --token "$VERCEL_TOKEN" --scope "$VERCEL_SCOPE"; then | |
| break | |
| fi | |
| if [ "$attempt" -ge "$max_attempts" ]; then | |
| echo "Vercel deploy failed after ${max_attempts} attempt(s)." | |
| exit 1 | |
| fi | |
| sleep_seconds=$((attempt * 10)) | |
| echo "Vercel deploy failed. Retry ${attempt}/${max_attempts} in ${sleep_seconds}s..." | |
| sleep "$sleep_seconds" | |
| attempt=$((attempt + 1)) | |
| done | |
| # Railway: auto-deploys from main branch via GitHub integration. | |
| # No CLI or deploy hook needed — Railway watches this branch | |
| # and waits for CI checks to pass ("Check Suites" enabled). |