name: Build & Deploy on: pull_request: branches: [main] types: [opened, synchronize, reopened] workflow_dispatch: jobs: build-and-deploy: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: "22" # match the version your project targets - name: Build (verify it compiles) run: | npm ci --no-audit --no-fund npm run build - name: Setup SSH client run: | which rsync ssh || (apt-get update && apt-get install -y rsync openssh-client) mkdir -p ~/.ssh echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key chmod 600 ~/.ssh/deploy_key ssh-keyscan -H 82.165.141.176 >> ~/.ssh/known_hosts - name: Copy source to server run: | rsync -avz --delete \ --exclude node_modules --exclude .next --exclude out --exclude .git \ ./ "${{ secrets.DEPLOY_USER }}@82.165.141.176":/var/www/vhosts/dev.karlderheinz.tv/nodejs// - name: Install, build and restart on server run: | ssh -i ~/.ssh/deploy_key ${{ secrets.DEPLOY_USER }}@82.165.141.176 <<'EOF' set -e cd /dev.karlderheinz.tv npm ci --no-audit --no-fund npm run build if [ -d public ]; then cp -r public .next/standalone/public # standalone needs your static assets copied in fi systemctl restart # or: monit restart EOF