perf: cache node_modules to skip npm ci on warm cache #8
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 | |
| concurrency: | |
| cancel-in-progress: true | |
| group: ${{ github.workflow_ref }} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| # if: ${{ !github.event.repository.is_template }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Set up Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version-file: .nvmrc | |
| cache: npm | |
| - name: Cache node_modules | |
| id: node-modules-cache | |
| uses: actions/cache@v5 | |
| with: | |
| path: node_modules | |
| key: ${{ runner.os }}-node-modules-${{ hashFiles('package-lock.json', '.nvmrc') }} | |
| - name: Install dependencies | |
| if: steps.node-modules-cache.outputs.cache-hit != 'true' | |
| run: npm ci | |
| - name: Build client and server | |
| # Test values so the zod-validated config in vite.config.ts passes. | |
| # Real deploys decrypt .env.prod via DOTENV_PRIVATE_KEY_PROD instead. | |
| env: | |
| NODE_ENV: production | |
| PORT: 3000 | |
| APP_URL: http://localhost:8080 | |
| DATABASE_DIALECT: sqlite3 | |
| DATABASE_URL: sqlite3:database.sqlite | |
| JWT_SECRET: secret | |
| EMAIL_FROM: hello@example.com | |
| EMAIL_SMTP_API_KEY: secret | |
| BASE_PATH: / | |
| run: >- | |
| npx concurrently --names client,server --kill-others-on-fail | |
| "npm run build:client" "npm run build:server" | |
| # - name: Configure SSH access | |
| # env: | |
| # HOST: ${{ secrets.HOST }} | |
| # PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} | |
| # run: | | |
| # mkdir -p ~/.ssh | |
| # chmod 700 ~/.ssh | |
| # printf '%s\n' "$PRIVATE_KEY" > ~/.ssh/deploy_key | |
| # chmod 600 ~/.ssh/deploy_key | |
| # ssh-keyscan -H "$HOST" >> ~/.ssh/known_hosts 2>/dev/null | |
| # - name: Rsync artefacts to server | |
| # env: | |
| # HOST: ${{ secrets.HOST }} | |
| # USERNAME: ${{ secrets.USERNAME }} | |
| # DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} | |
| # run: >- | |
| # rsync -avz --delete | |
| # -e "ssh -i ~/.ssh/deploy_key" | |
| # build node_modules package.json ecosystem.config.cjs .nvmrc | |
| # "$USERNAME@$HOST:$DEPLOY_PATH/" | |
| # - name: Reload app with pm2 | |
| # env: | |
| # HOST: ${{ secrets.HOST }} | |
| # USERNAME: ${{ secrets.USERNAME }} | |
| # DEPLOY_PATH: ${{ secrets.DEPLOY_PATH }} | |
| # run: | | |
| # ssh -i ~/.ssh/deploy_key "$USERNAME@$HOST" \ | |
| # "set -e; export NVM_DIR=\"\$HOME/.nvm\"; [ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\"; cd \"$DEPLOY_PATH\"; pm2 startOrReload ecosystem.config.cjs --time --update-env" | |
| - name: Package artefacts | |
| run: >- | |
| tar -czf deploy.tar.gz | |
| build node_modules package.json ecosystem.config.cjs .nvmrc | |
| - name: Upload artefacts | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: deploy | |
| path: deploy.tar.gz | |
| retention-days: 7 |