name: Deploy to DigitalOcean on: push: branches: [ main ] pull_request: branches: [ main ] jobs: # Test job to run before deployment test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '18' cache: 'npm' - name: Install dependencies run: npm ci - name: Run linter run: npm run lint - name: Build frontend run: npm run build env: VITE_APP_NAME: ScriptShare VITE_APP_URL: https://scriptshare.example.com VITE_ANALYTICS_ENABLED: true # Deploy job (only on main branch) deploy: needs: test runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' && github.event_name == 'push' steps: - uses: actions/checkout@v4 - name: Install doctl uses: digitalocean/action-doctl@v2 with: token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} - name: Get app info id: app-info run: | APP_ID=$(doctl apps list --format ID,Spec.Name --no-header | grep scriptshare | cut -d' ' -f1) echo "app-id=$APP_ID" >> $GITHUB_OUTPUT - name: Trigger deployment run: | doctl apps create-deployment ${{ steps.app-info.outputs.app-id }} --wait - name: Run database migrations run: | # Wait for deployment to complete sleep 60 # Run migrations via the app console (if needed) echo "Deployment completed. Please run database migrations manually if this is the first deployment." echo "Command: npm run db:setup:prod" # Database migration job (manual trigger) migrate: runs-on: ubuntu-latest if: github.event_name == 'workflow_dispatch' steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '18' cache: 'npm' - name: Install dependencies run: npm ci - name: Run migrations run: npm run db:migrate:prod env: DATABASE_URL: ${{ secrets.DATABASE_URL }} # Manual workflow dispatch for running migrations on: workflow_dispatch: inputs: action: description: 'Action to perform' required: true default: 'migrate' type: choice options: - migrate - setup