Skip to content

fix(tests): add explicit types to integration test queries #41

fix(tests): add explicit types to integration test queries

fix(tests): add explicit types to integration test queries #41

Workflow file for this run

name: CI/CD - Build and Deploy to Dev
on:
push:
branches:
- main
jobs:
build:
name: Build and Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
- name: Run TypeScript type check
run: npm run type-check
- name: Build Next.js application
run: npm run build
- name: Run Unit Tests
run: npm run test:unit
env:
# Database configuration for integration tests (from GitHub Secrets)
DATABASE_URL: ${{ secrets.DEV_DATABASE_URL }}
ALLOWED_EMAILS: test@example.com,ci@example.com
NODE_ENV: test
PORT: 3000
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run E2E Tests
run: npm run test:e2e
env:
BASE_URL: http://localhost:3000
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: |
test-results/
playwright-report/
retention-days: 30
deploy-dev:
name: Deploy to Dev Environment
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
env:
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_REGION: southamerica-east1
SERVICE_NAME: role-directory-dev
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker ${GCP_REGION}-docker.pkg.dev
- name: Extract version from package.json
id: version
run: |
VERSION=$(node -p "require('./package.json').version")
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "📦 Package version: $VERSION"
- name: Build and tag Docker image
id: build
run: |
DEV_TAG="dev-$(date +%Y%m%d-%H%M%S)"
echo "DEV_TAG=$DEV_TAG" >> $GITHUB_OUTPUT
IMAGE_NAME="${GCP_REGION}-docker.pkg.dev/${GCP_PROJECT_ID}/role-directory/app"
DEV_IMAGE="$IMAGE_NAME:$DEV_TAG"
DEV_LATEST="$IMAGE_NAME:dev-latest"
BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "🐳 Building Docker image with version info..."
echo " Version: ${{ steps.version.outputs.VERSION }}"
echo " Build Time: $BUILD_TIME"
echo " Commit SHA: ${{ github.sha }}"
docker build \
--build-arg NEXT_PUBLIC_APP_VERSION=${{ steps.version.outputs.VERSION }} \
--build-arg NEXT_PUBLIC_BUILD_TIME="$BUILD_TIME" \
--build-arg NEXT_PUBLIC_COMMIT_SHA=${{ github.sha }} \
-t $DEV_IMAGE \
-t $DEV_LATEST \
.
echo "✅ Built and tagged as: $DEV_TAG"
echo "✅ Built and tagged as: dev-latest"
echo "📤 Pushing to Artifact Registry..."
docker push $DEV_IMAGE
docker push $DEV_LATEST
echo "✅ Images pushed to registry"
- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.SERVICE_NAME }}
region: ${{ env.GCP_REGION }}
image: ${{ env.GCP_REGION }}-docker.pkg.dev/${{ env.GCP_PROJECT_ID }}/role-directory/app:${{ steps.build.outputs.DEV_TAG }}
flags: |
--set-env-vars=NODE_ENV=development
--min-instances=0
--max-instances=2
--cpu=1
--memory=512Mi
- name: Get Service URL
id: get-url
run: |
# Use deploy action output first, fallback to gcloud describe
if [ -n "${{ steps.deploy.outputs.url }}" ]; then
SERVICE_URL="${{ steps.deploy.outputs.url }}"
echo "Using deploy action output: $SERVICE_URL"
else
SERVICE_URL=$(gcloud run services describe ${SERVICE_NAME} \
--region ${GCP_REGION} \
--format 'value(status.url)')
echo "Using gcloud describe: $SERVICE_URL"
fi
# Debug: Show what we got
echo "Raw URL value: $SERVICE_URL"
echo "URL length: ${#SERVICE_URL}"
echo "SERVICE_URL=$SERVICE_URL" >> $GITHUB_OUTPUT
echo "✅ Deployed to: $SERVICE_URL"
- name: Health Check
run: |
SERVICE_URL="${{ steps.get-url.outputs.SERVICE_URL }}"
echo "🏥 Running health check against: $SERVICE_URL/api/health"
# Wait up to 60 seconds for service to be ready
for i in {1..30}; do
if curl -sf "$SERVICE_URL/api/health" > /dev/null 2>&1; then
echo "✅ Health check passed!"
exit 0
fi
echo "⏳ Waiting for service... ($i/30)"
sleep 2
done
echo "❌ Health check failed after 60 seconds"
echo "Note: Health check endpoint will be implemented in Story 1.6"
echo "Deployment succeeded but health check endpoint not yet available"
exit 1
- name: Setup Node.js for E2E Tests
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'
- name: Install Dependencies for E2E Tests
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium
- name: Run Post-Deployment E2E Tests
run: |
SERVICE_URL="${{ steps.get-url.outputs.SERVICE_URL }}"
echo "🧪 Running E2E tests against deployed service: $SERVICE_URL"
# Run health check tests against deployed service
npx playwright test tests/e2e/health-check.spec.ts --reporter=list
env:
BASE_URL: ${{ steps.get-url.outputs.SERVICE_URL }}
- name: Upload Post-Deployment Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: post-deployment-test-results
path: |
test-results/
playwright-report/
retention-days: 30
- name: Deployment Summary
if: always()
run: |
SERVICE_URL="${{ steps.get-url.outputs.SERVICE_URL }}"
# Generate unique token for stop-commands
STOP_TOKEN=$(date +%s%N)
echo "### 🚀 Deployment Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Parameter | Value |" >> $GITHUB_STEP_SUMMARY
echo "|-----------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| **Environment** | Dev |" >> $GITHUB_STEP_SUMMARY
echo "| **Service** | role-directory-dev |" >> $GITHUB_STEP_SUMMARY
echo "| **Region** | southamerica-east1 |" >> $GITHUB_STEP_SUMMARY
echo "| **Version** | \`${{ steps.version.outputs.VERSION }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Image Tag** | \`${{ steps.build.outputs.DEV_TAG }}\` |" >> $GITHUB_STEP_SUMMARY
echo "| **Commit** | \`${{ github.sha }}\` |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
# Use stop-commands to prevent URL masking
echo "**🌐 Service URL:**" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "::stop-commands::${STOP_TOKEN}"
echo "${SERVICE_URL}" >> $GITHUB_STEP_SUMMARY
echo "::${STOP_TOKEN}::"
echo "" >> $GITHUB_STEP_SUMMARY
# Backup: Code block with URL (in case stop-commands doesn't work)
echo "<details>" >> $GITHUB_STEP_SUMMARY
echo "<summary>📋 Copy URL (if masked above)</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "::stop-commands::${STOP_TOKEN}"
echo "${SERVICE_URL}" >> $GITHUB_STEP_SUMMARY
echo "::${STOP_TOKEN}::"
echo '```' >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ job.status }}" == "success" ]; then
echo "✅ **Status:** Deployment successful" >> $GITHUB_STEP_SUMMARY
echo "✅ **Post-Deployment Tests:** Passed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### 📦 Next Steps" >> $GITHUB_STEP_SUMMARY
echo "To promote this image to staging, run the **Promote Dev to Staging** workflow with tag: \`${{ steps.build.outputs.DEV_TAG }}\`" >> $GITHUB_STEP_SUMMARY
else
echo "❌ **Status:** Deployment failed" >> $GITHUB_STEP_SUMMARY
fi