diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index d84dd24a..9a8b6f01 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -266,8 +266,10 @@ jobs: run: | # Remove any existing .vercel directory to avoid conflicts rm -rf .vercel - # Deploy directly with project ID (no linking required) - vercel --token ${{ secrets.VERCEL_TOKEN }} --yes --project ${{ secrets.VERCEL_PROJECT_ID }} + # Link project using environment variables + vercel link --token ${{ secrets.VERCEL_TOKEN }} --yes + # Deploy to staging + vercel --token ${{ secrets.VERCEL_TOKEN }} --yes env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} @@ -301,8 +303,10 @@ jobs: run: | # Remove any existing .vercel directory to avoid conflicts rm -rf .vercel - # Deploy directly with project ID (no linking required) - vercel --prod --token ${{ secrets.VERCEL_TOKEN }} --yes --project ${{ secrets.VERCEL_PROJECT_ID }} + # Link project using environment variables + vercel link --token ${{ secrets.VERCEL_TOKEN }} --yes + # Deploy to production + vercel --prod --token ${{ secrets.VERCEL_TOKEN }} --yes env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} @@ -332,11 +336,10 @@ jobs: - name: Rollback deployment run: | - # Create .vercel directory and project.json to link the project - mkdir -p .vercel - echo '{"orgId":"${{ secrets.VERCEL_ORG_ID }}","projectId":"${{ secrets.VERCEL_PROJECT_ID }}"}' > .vercel/project.json + # Link project using environment variables + vercel link --token ${{ secrets.VERCEL_TOKEN }} --yes # Perform rollback - npx vercel rollback --token ${{ secrets.VERCEL_TOKEN }} --yes + vercel rollback --token ${{ secrets.VERCEL_TOKEN }} --yes env: VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} diff --git a/.gitignore b/.gitignore index 2e106fa7..28e27913 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,10 @@ yarn-error.log* # vercel .vercel +# local testing +.secrets +.actrc + # typescript *.tsbuildinfo next-env.d.ts diff --git a/package.json b/package.json index 6975ae22..a0336621 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,11 @@ "test:ci": "jest --ci --coverage --watchAll=false", "security:check": "./scripts/security-check.sh", "security:audit": "npm audit --audit-level=moderate", - "security:test": "npm run test -- --testPathPattern=security" + "security:test": "npm run test -- --testPathPattern=security", + "test:local": "./scripts/test-ci-local.sh all", + "test:local:security": "./scripts/test-ci-local.sh security", + "test:local:build": "./scripts/test-ci-local.sh build", + "test:local:vercel": "./scripts/test-ci-local.sh vercel" }, "dependencies": { "@google/generative-ai": "^0.24.1", diff --git a/scripts/test-ci-local.sh b/scripts/test-ci-local.sh new file mode 100755 index 00000000..eaa3a364 --- /dev/null +++ b/scripts/test-ci-local.sh @@ -0,0 +1,182 @@ +#!/bin/bash + +# Local CI/CD Testing Script +# This script allows you to test individual parts of your CI/CD pipeline locally + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Function to run security checks +run_security_checks() { + print_status "Running security checks..." + + # Install dependencies + npm ci + + # Run ESLint + print_status "Running ESLint..." + npm run lint + + # Run TypeScript check + print_status "Running TypeScript check..." + npx tsc --noEmit + + # Security audit + print_status "Running security audit..." + npm audit --audit-level=moderate + + print_success "Security checks completed!" +} + +# Function to run tests +run_tests() { + print_status "Running tests..." + + # Install dependencies + npm ci + + # Run tests + print_status "Running test suite..." + npm run test:ci + + print_success "Tests completed!" +} + +# Function to run build +run_build() { + print_status "Running build..." + + # Install dependencies + npm ci + + # Build application + print_status "Building application..." + NODE_ENV=production npm run build + + # Analyze bundle size + print_status "Analyzing bundle size..." + npm run build:analyze + + print_success "Build completed!" +} + +# Function to test Vercel deployment commands +test_vercel_commands() { + print_status "Testing Vercel CLI commands..." + + # Check if Vercel CLI is installed + if ! command -v vercel &> /dev/null; then + print_status "Installing Vercel CLI..." + npm install -g vercel@latest + fi + + # Test Vercel CLI version + print_status "Vercel CLI version:" + vercel --version + + # Test linking (this will fail with dummy secrets, but we can see the command structure) + print_status "Testing Vercel link command structure..." + echo "vercel link --token \$VERCEL_TOKEN --yes" + + # Test deployment command structure + print_status "Testing Vercel deployment command structure..." + echo "vercel --token \$VERCEL_TOKEN --yes" + echo "vercel --prod --token \$VERCEL_TOKEN --yes" + + print_success "Vercel command testing completed!" +} + +# Function to run with act (GitHub Actions simulation) +run_with_act() { + print_status "Running GitHub Actions simulation with act..." + + # Check if act is installed + if ! command -v act &> /dev/null; then + print_error "act is not installed. Please install it with: brew install act" + exit 1 + fi + + # List available workflows + print_status "Available workflows:" + act --list + + # Run specific job (you can modify this) + print_status "Running security job..." + act -j security --secret-file .secrets --dry-run + + print_success "Act simulation completed!" +} + +# Function to show help +show_help() { + echo "Local CI/CD Testing Script" + echo "" + echo "Usage: $0 [OPTION]" + echo "" + echo "Options:" + echo " security Run security checks (lint, typescript, audit)" + echo " test Run test suite" + echo " build Run build process" + echo " vercel Test Vercel CLI commands" + echo " act Run GitHub Actions simulation with act" + echo " all Run all checks (security, test, build, vercel)" + echo " help Show this help message" + echo "" + echo "Examples:" + echo " $0 security # Run only security checks" + echo " $0 all # Run all checks" + echo " $0 act # Simulate GitHub Actions" +} + +# Main script logic +case "${1:-help}" in + "security") + run_security_checks + ;; + "test") + run_tests + ;; + "build") + run_build + ;; + "vercel") + test_vercel_commands + ;; + "act") + run_with_act + ;; + "all") + print_status "Running all CI/CD checks..." + run_security_checks + run_tests + run_build + test_vercel_commands + print_success "All checks completed!" + ;; + "help"|*) + show_help + ;; +esac