Skip to content

test: Add comprehensive tests for QuestionEngine #399

test: Add comprehensive tests for QuestionEngine

test: Add comprehensive tests for QuestionEngine #399

Workflow file for this run

# =============================================================================
# PyExplorer - GitHub Actions CI/CD Pipeline
# =============================================================================
# Este workflow realiza:
# - CI: Build, Lint, Type-check em PRs e pushes
# - CD: Deploy automático para Firebase Hosting na branch main
# =============================================================================
name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
# Permite cancelar runs anteriores do mesmo workflow na mesma branch
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
NODE_VERSION: '20'
FIREBASE_PROJECT_ID: pyexplorer-cd32d
permissions:
checks: write
contents: read
pull-requests: write
jobs:
# ===========================================================================
# JOB: Build & Lint
# ===========================================================================
build:
name: 🔨 Build & Lint
runs-on: ubuntu-latest
# Firebase credentials are now in .env file (committed to repo)
# Security is enforced via Firestore Rules, not secret API keys
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 📦 Setup Node.js ${{ env.NODE_VERSION }}
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: 📥 Install dependencies
run: npm ci
- name: 🔍 Type check (TypeScript)
run: npx tsc --noEmit
- name: 🧹 Lint check
run: npm run lint || true # Não falha por lint warnings
- name: 🔨 Build production
run: npm run build
env:
VITE_FIREBASE_API_KEY: ${{ secrets.VITE_FIREBASE_API_KEY }}
VITE_FIREBASE_AUTH_DOMAIN: ${{ secrets.VITE_FIREBASE_AUTH_DOMAIN }}
VITE_FIREBASE_PROJECT_ID: ${{ secrets.VITE_FIREBASE_PROJECT_ID }}
VITE_FIREBASE_STORAGE_BUCKET: ${{ secrets.VITE_FIREBASE_STORAGE_BUCKET }}
VITE_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.VITE_FIREBASE_MESSAGING_SENDER_ID }}
VITE_FIREBASE_APP_ID: ${{ secrets.VITE_FIREBASE_APP_ID }}
VITE_FIREBASE_MEASUREMENT_ID: ${{ secrets.VITE_FIREBASE_MEASUREMENT_ID }}
VITE_RECAPTCHA_SITE_KEY: ${{ secrets.VITE_RECAPTCHA_SITE_KEY }}
- name: 📊 Report bundle size
run: |
echo "## 📦 Bundle Size Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| File | Size |" >> $GITHUB_STEP_SUMMARY
echo "|------|------|" >> $GITHUB_STEP_SUMMARY
for file in dist/assets/*.js dist/assets/*.css; do
if [ -f "$file" ]; then
size=$(du -h "$file" | cut -f1)
echo "| $(basename $file) | $size |" >> $GITHUB_STEP_SUMMARY
fi
done
- name: 📤 Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
retention-days: 7
# ===========================================================================
# JOB: Deploy to Firebase (Production)
# ===========================================================================
deploy-production:
name: 🚀 Deploy to Production
runs-on: ubuntu-latest
needs: build
# Só faz deploy em push para main (não em PRs)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
environment:
name: production
url: https://pyexplorer.com.br
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 📥 Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: 🔥 Deploy to Firebase Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_PYEXPLORER_CD32D }}
projectId: ${{ env.FIREBASE_PROJECT_ID }}
channelId: live
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
- name: ✅ Deploy Summary
run: |
echo "## 🚀 Deployment Successful!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Environment:** Production" >> $GITHUB_STEP_SUMMARY
echo "**URL:** https://pyexplorer.com.br" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Deployed at:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
# ===========================================================================
# JOB: Preview Deploy (Pull Requests)
# ===========================================================================
deploy-preview:
name: 👀 Deploy Preview
runs-on: ubuntu-latest
needs: build
# Só faz preview em PRs (exceto Dependabot que não tem acesso aos secrets)
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 📥 Download build artifacts
uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- name: 🔥 Deploy Preview to Firebase Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
with:
repoToken: ${{ secrets.GITHUB_TOKEN }}
firebaseServiceAccount: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_PYEXPLORER_CD32D }}
projectId: ${{ env.FIREBASE_PROJECT_ID }}
env:
FIREBASE_CLI_EXPERIMENTS: webframeworks
# ===========================================================================
# JOB: Lighthouse Audit (Performance)
# ===========================================================================
lighthouse:
name: 🔦 Lighthouse Audit
runs-on: ubuntu-latest
needs: deploy-production
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🔦 Run Lighthouse
uses: treosh/lighthouse-ci-action@v12
with:
urls: |
https://pyexplorer.com.br/
https://pyexplorer.com.br/game
uploadArtifacts: true
temporaryPublicStorage: true
- name: 📊 Lighthouse Score Summary
if: always()
run: |
echo "## 🔦 Lighthouse Audit Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Check the artifacts for detailed reports." >> $GITHUB_STEP_SUMMARY