feat: add /api/revalidate endpoint for on-demand ISR cache busting #23
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: Build and Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build Next.js application | |
| run: npm run build | |
| - name: Install sshpass | |
| run: sudo apt-get install -y sshpass | |
| - name: Deploy to server | |
| env: | |
| SSHPASS: ${{ secrets.SERVER_PASSWORD }} | |
| run: | | |
| tar -czf deploy.tar.gz .next/ public/ package.json package-lock.json next.config.mjs next.config.js | |
| sshpass -e scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -P ${{ secrets.SERVER_PORT }} deploy.tar.gz ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }}:/home/cosmic-linux-2/osp-frontend/deploy.tar.gz | |
| - name: Extract and restart PM2 | |
| env: | |
| SSHPASS: ${{ secrets.SERVER_PASSWORD }} | |
| run: | | |
| sshpass -e ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p ${{ secrets.SERVER_PORT }} ${{ secrets.SERVER_USERNAME }}@${{ secrets.SERVER_HOST }} << 'EOF' | |
| export PATH="/home/cosmic-linux-2/.nvm/versions/node/v20.20.2/bin:$PATH" | |
| cd /home/cosmic-linux-2/osp-frontend | |
| tar -xzf deploy.tar.gz | |
| rm deploy.tar.gz | |
| npm ci --omit=dev | |
| pm2 restart osp-frontend | |
| EOF |