Fix charts #369
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: Deploy Frontend | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| paths-ignore: | |
| - "README.md" | |
| - "**/*.md" | |
| - LICENSE | |
| concurrency: | |
| group: deploy-frontend | |
| cancel-in-progress: false | |
| jobs: | |
| build_and_deploy: | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: "24" | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Typecheck | |
| run: npm run typecheck | |
| - name: Lint | |
| run: npm run lint | |
| - name: Test | |
| run: npm test | |
| - name: Build standalone frontend | |
| run: npm run build | |
| - name: Prepare standalone package | |
| run: | | |
| mkdir -p deploy | |
| cp -r .next/standalone/. deploy/ | |
| mkdir -p deploy/.next | |
| cp -r .next/static deploy/.next/static | |
| # standalone already ships a traced public/ (llms.txt), so `cp -r public | |
| # deploy/public` would nest into it. Copy the contents, not the dir. | |
| mkdir -p deploy/public | |
| cp -r public/. deploy/public/ | |
| cp ecosystem.config.js deploy/ecosystem.config.js | |
| - name: Create release directory on server | |
| uses: appleboy/ssh-action@v1.2.5 | |
| with: | |
| host: ${{ secrets.HOSTINGER_HOST }} | |
| username: ${{ secrets.HOSTINGER_USER }} | |
| key: ${{ secrets.HOSTINGER_SSH_KEY }} | |
| port: 22 | |
| script: | | |
| mkdir -p /var/www/sramap/releases/${{ github.sha }} | |
| - name: Upload standalone frontend | |
| uses: appleboy/scp-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.HOSTINGER_HOST }} | |
| username: ${{ secrets.HOSTINGER_USER }} | |
| key: ${{ secrets.HOSTINGER_SSH_KEY }} | |
| port: 22 | |
| source: "deploy/*" | |
| target: /var/www/sramap/releases/${{ github.sha }} | |
| strip_components: 1 | |
| - name: Activate release | |
| uses: appleboy/ssh-action@v1.2.5 | |
| with: | |
| host: ${{ secrets.HOSTINGER_HOST }} | |
| username: ${{ secrets.HOSTINGER_USER }} | |
| key: ${{ secrets.HOSTINGER_SSH_KEY }} | |
| port: 22 | |
| script: | | |
| set -e | |
| export NVM_DIR="$HOME/.nvm" | |
| [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" | |
| BASE=/var/www/sramap | |
| RELEASE="$BASE/releases/${{ github.sha }}" | |
| test -f "$RELEASE/server.js" || { echo "server.js missing in release"; exit 1; } | |
| ln -sfn "$RELEASE" "$BASE/current" | |
| cp "$RELEASE/ecosystem.config.js" "$BASE/ecosystem.config.js" | |
| pm2 startOrReload "$BASE/ecosystem.config.js" --update-env | |
| pm2 save | |
| ls -1dt "$BASE"/releases/*/ | tail -n +4 | xargs -r rm -rf | |
| sleep 3 | |
| curl -f http://127.0.0.1:3002 | |
| # Cluster mode: the :3002 socket belongs to the pm2 daemon (cwd=$HOME). | |
| PIDS=$(pm2 pid sramap-frontend) | |
| test -n "$PIDS" || { echo "::error::no sramap-frontend workers running"; exit 1; } | |
| WANT=$(readlink -f "$RELEASE") | |
| for PID in $PIDS; do | |
| SERVING=$(readlink -f "/proc/$PID/cwd") | |
| test "$SERVING" = "$WANT" || { | |
| echo "::error::pid $PID is serving $SERVING, not $RELEASE" | |
| exit 1 | |
| } | |
| done | |
| echo "Frontend deployment successful" | |
| - name: Purge Cloudflare cache | |
| if: contains(github.event.head_commit.message, '[purge cache]') | |
| run: | | |
| curl -fsS -X POST \ | |
| "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE_ID }}/purge_cache" \ | |
| -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_API_TOKEN }}" \ | |
| -H "Content-Type: application/json" \ | |
| --data '{"purge_everything":true}' | |
| echo "Cloudflare cache purged" |