updated list of removing dist files #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI/CD Pipeline to VPS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: # Allows triggering the workflow manually from the GitHub Actions tab | |
| jobs: | |
| deploy-frontend: | |
| name: Build & Deploy Frontend (Angular) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js (v20) | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22.22.3' | |
| cache: 'npm' | |
| cache-dependency-path: frontend/package-lock.json | |
| - name: Install Frontend Dependencies | |
| working-directory: ./frontend | |
| run: npm ci | |
| - name: Build Production Bundle | |
| working-directory: ./frontend | |
| run: npm run build -- --configuration production | |
| - name: Clean Old Frontend Bundles on VPS (Keeping /api directory intact) | |
| uses: appleboy/ssh-action@v1.1.0 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT || '22' }} | |
| script: | | |
| TARGET_DIR="${{ secrets.APACHE_WEB_DIR || '/var/www/share-it.site' }}" | |
| mkdir -p "$TARGET_DIR" | |
| cd "$TARGET_DIR" | |
| # Delete old compiled frontend files directly inside web root | |
| find . -maxdepth 1 -type f \( -name "*.js" -o -name "*.css" -o -name "*.html" -o -name "*.txt" -o -name "*.json" -o -name "*.ico" -o -name "*.svg" -o -name "*.png" -o -name "*.jpg" -o -name "*.webp" -o -name "*.map" \) -delete | |
| # Remove old Angular static asset directories if they exist (never touches 'api' folder) | |
| rm -rf assets media || true | |
| - name: Deploy Frontend Build to Apache Web Root | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT || '22' }} | |
| source: "frontend/dist/frontend/browser/*" | |
| strip_components: 4 | |
| target: "${{ secrets.APACHE_WEB_DIR || '/var/www/share-it.site' }}" | |
| overwrite: true | |
| deploy-backend: | |
| name: Deploy Backend & Restart Service (FastAPI) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| - name: Copy Backend Files to VPS API Folder | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT || '22' }} | |
| source: "backend/*.py,backend/requirements.txt,backend/*.yaml,backend/*.sh" | |
| strip_components: 1 | |
| target: "${{ secrets.BACKEND_APP_DIR || '/opt/shareit-backend' }}" | |
| overwrite: true | |
| - name: Update Python Dependencies & Restart Systemd Service | |
| uses: appleboy/ssh-action@v1.1.0 | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USER }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT || '22' }} | |
| script: | | |
| # Navigate to target directory | |
| cd ${{ secrets.BACKEND_APP_DIR || '/opt/shareit-backend' }} | |
| # Setup/Update virtual environment & install dependencies | |
| if [ -d "venv" ]; then | |
| ./venv/bin/pip install --upgrade pip | |
| ./venv/bin/pip install -r requirements.txt | |
| else | |
| python3 -m venv venv | |
| ./venv/bin/pip install --upgrade pip | |
| ./venv/bin/pip install -r requirements.txt | |
| fi | |
| # Restart systemd backend service | |
| SERVICE_NAME="${{ secrets.BACKEND_SERVICE_NAME || 'shareit-backend.service' }}" | |
| if command -v sudo >/dev/null 2>&1; then | |
| sudo systemctl restart "$SERVICE_NAME" | |
| else | |
| systemctl restart "$SERVICE_NAME" | |
| fi | |
| # Check status of the service | |
| echo "--- Service Status ---" | |
| if command -v sudo >/dev/null 2>&1; then | |
| sudo systemctl status "$SERVICE_NAME" --no-pager -l || true | |
| else | |
| systemctl status "$SERVICE_NAME" --no-pager -l || true | |
| fi |