name: Deploy Frontend on: push: branches: [main] env: REPO_DIR: "/workspace/ruspet_admin_frontend" REPO_URL: "https://72.56.235.246.nip.io/gitea/romanskijdev/admin_ruspet.git" BUILD_DIR: "/var/www/admin.ruspet.tw1.ru" jobs: build-and-deploy: runs-on: self-hosted timeout-minutes: 15 steps: - name: 📋 Deployment Info run: | echo "════════════════════════════════════════" echo "🚀 Starting frontend deployment" echo "════════════════════════════════════════" echo "Branch: ${{ github.ref }}" echo "Commit: ${{ github.sha }}" echo "Author: ${{ github.actor }}" echo "Time: $(date '+%Y-%m-%d %H:%M:%S')" echo "Runner: $(hostname)" echo "════════════════════════════════════════" - name: 📦 Checkout run: | git config --global --add safe.directory "$REPO_DIR" if [ -d "$REPO_DIR/.git" ]; then echo "📦 Updating existing repo..." cd "$REPO_DIR" git fetch origin git reset --hard origin/main else echo "📦 Cloning repo..." git clone "$REPO_URL" "$REPO_DIR" fi - name: 💾 Cache node_modules uses: actions/cache@v3 with: path: | ~/.npm $REPO_DIR/node_modules key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- - name: 📥 Install dependencies run: | cd "$REPO_DIR" npm ci - name: 🔨 Build run: | cd "$REPO_DIR" npm run build echo "✅ Build completed" ls -la dist/ - name: 📤 Deploy to web server run: | echo "📤 Deploying to $BUILD_DIR..." sudo mkdir -p "$BUILD_DIR" sudo rm -rf "$BUILD_DIR"/* sudo cp -r "$REPO_DIR/dist/"* "$BUILD_DIR/" sudo chown -R www-data:www-data "$BUILD_DIR" sudo chmod -R 755 "$BUILD_DIR" echo "✅ Frontend deployed successfully" - name: ✅ Verify deployment run: | echo "🔍 Verifying deployment..." if [ -f "$BUILD_DIR/index.html" ]; then echo "✅ index.html exists" ls -lh "$BUILD_DIR/index.html" echo "✅ Deployment verified successfully" else echo "❌ index.html not found" exit 1 fi - name: 📊 Deployment Summary if: always() run: | echo "════════════════════════════════════════" echo "📊 DEPLOYMENT SUMMARY" echo "════════════════════════════════════════" echo "Status: ${{ job.status }}" echo "Branch: ${{ github.ref }}" echo "Commit: ${{ github.sha }}" echo "Duration: $SECONDS seconds" echo "════════════════════════════════════════" if [ "${{ job.status }}" == "success" ]; then echo "✅ Frontend deployment completed!" echo "🌐 Available at: https://admin.ruspet.tw1.ru" else echo "❌ Frontend deployment failed!" fi