|
| 1 | +name: Deploy to SmartHavenAI.com |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + name: Run Tests |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + |
| 18 | + - name: Setup Node.js |
| 19 | + uses: actions/setup-node@v4 |
| 20 | + with: |
| 21 | + node-version: '20' |
| 22 | + |
| 23 | + - name: Install pnpm |
| 24 | + uses: pnpm/action-setup@v2 |
| 25 | + with: |
| 26 | + version: 8 |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: pnpm install |
| 30 | + |
| 31 | + - name: Run unit tests |
| 32 | + run: pnpm test |
| 33 | + |
| 34 | + - name: Install Playwright |
| 35 | + run: npx playwright install --with-deps |
| 36 | + |
| 37 | + - name: Run E2E tests |
| 38 | + run: pnpm test:e2e --run |
| 39 | + |
| 40 | + - name: Upload test results |
| 41 | + if: failure() |
| 42 | + uses: actions/upload-artifact@v3 |
| 43 | + with: |
| 44 | + name: test-results |
| 45 | + path: test-results/ |
| 46 | + |
| 47 | + build: |
| 48 | + name: Build Application |
| 49 | + needs: test |
| 50 | + runs-on: ubuntu-latest |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Checkout code |
| 54 | + uses: actions/checkout@v4 |
| 55 | + |
| 56 | + - name: Setup Node.js |
| 57 | + uses: actions/setup-node@v4 |
| 58 | + with: |
| 59 | + node-version: '20' |
| 60 | + |
| 61 | + - name: Install pnpm |
| 62 | + uses: pnpm/action-setup@v2 |
| 63 | + with: |
| 64 | + version: 8 |
| 65 | + |
| 66 | + - name: Install dependencies |
| 67 | + run: pnpm install |
| 68 | + |
| 69 | + - name: Build application |
| 70 | + run: pnpm build |
| 71 | + |
| 72 | + - name: Upload build artifacts |
| 73 | + uses: actions/upload-artifact@v3 |
| 74 | + with: |
| 75 | + name: dist |
| 76 | + path: dist/ |
| 77 | + |
| 78 | + deploy: |
| 79 | + name: Deploy to Hostinger |
| 80 | + needs: build |
| 81 | + runs-on: ubuntu-latest |
| 82 | + if: github.ref == 'refs/heads/master' |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: Checkout code |
| 86 | + uses: actions/checkout@v4 |
| 87 | + |
| 88 | + - name: Download build artifacts |
| 89 | + uses: actions/download-artifact@v3 |
| 90 | + with: |
| 91 | + name: dist |
| 92 | + path: dist/ |
| 93 | + |
| 94 | + - name: Install SSH key |
| 95 | + uses: shimataro/ssh-key-action@v2 |
| 96 | + with: |
| 97 | + key: ${{ secrets.HOSTINGER_SSH_KEY }} |
| 98 | + known_hosts: ${{ secrets.HOSTINGER_KNOWN_HOSTS }} |
| 99 | + |
| 100 | + - name: Create deployment package |
| 101 | + run: | |
| 102 | + tar -czf deploy.tar.gz dist/ package.json pnpm-lock.yaml ecosystem.config.js |
| 103 | +
|
| 104 | + - name: Upload to server |
| 105 | + run: | |
| 106 | + scp deploy.tar.gz ${{ secrets.HOSTINGER_USER }}@${{ secrets.HOSTINGER_HOST }}:/var/www/smarthaven/ |
| 107 | +
|
| 108 | + - name: Deploy on server |
| 109 | + run: | |
| 110 | + ssh ${{ secrets.HOSTINGER_USER }}@${{ secrets.HOSTINGER_HOST }} << 'ENDSSH' |
| 111 | + cd /var/www/smarthaven |
| 112 | +
|
| 113 | + # Backup current deployment |
| 114 | + if [ -d "dist" ]; then |
| 115 | + tar -czf backup-$(date +%Y%m%d-%H%M%S).tar.gz dist/ |
| 116 | + ls -t backup-*.tar.gz | tail -n +6 | xargs -r rm |
| 117 | + fi |
| 118 | +
|
| 119 | + # Extract new deployment |
| 120 | + tar -xzf deploy.tar.gz |
| 121 | + rm deploy.tar.gz |
| 122 | +
|
| 123 | + # Restart PM2 if needed |
| 124 | + if pm2 list | grep -q "transcript-parser"; then |
| 125 | + pm2 restart transcript-parser |
| 126 | + else |
| 127 | + pm2 start ecosystem.config.js |
| 128 | + pm2 save |
| 129 | + fi |
| 130 | +
|
| 131 | + echo "Deployment complete!" |
| 132 | + ENDSSH |
| 133 | +
|
| 134 | + - name: Verify deployment |
| 135 | + run: | |
| 136 | + echo "Waiting for application to start..." |
| 137 | + sleep 10 |
| 138 | + curl -f https://smarthaven.ai.com || exit 1 |
| 139 | + echo "✅ Deployment verified!" |
0 commit comments