fix: restructure workflow with separate build and deploy jobs #21
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 to GitHub Pages | |
| on: | |
| push: | |
| branches: [ main ] | |
| pull_request: | |
| branches: [ main ] | |
| # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| # Build job | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js 20.x | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20.x' | |
| cache: 'npm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Configure npm for better reliability | |
| run: | | |
| npm config set fetch-retries 10 | |
| npm config set fetch-retry-mintimeout 30000 | |
| npm config set fetch-retry-maxtimeout 300000 | |
| npm config set fetch-timeout 600000 | |
| npm config set registry https://registry.npmjs.org/ | |
| npm config set maxsockets 1 | |
| npm config set prefer-offline true | |
| - name: Clear npm cache | |
| run: npm cache clean --force | |
| - name: Install dependencies with retry and fallback | |
| run: | | |
| for i in {1..5}; do | |
| echo "Attempt $i of 5..." | |
| if npm ci --legacy-peer-deps --no-audit --no-fund --verbose; then | |
| echo "Dependencies installed successfully!" | |
| break | |
| else | |
| echo "Attempt $i failed" | |
| if [ $i -lt 5 ]; then | |
| echo "Waiting 60 seconds before retry..." | |
| sleep 60 | |
| echo "Clearing npm cache..." | |
| npm cache clean --force | |
| else | |
| echo "All attempts failed. Trying with npm install as fallback..." | |
| npm install --legacy-peer-deps --no-audit --no-fund | |
| fi | |
| fi | |
| done | |
| - name: Build project | |
| run: npm run build:production | |
| env: | |
| NODE_ENV: production | |
| CI: true | |
| - name: Add .nojekyll file | |
| run: | | |
| mkdir -p out | |
| touch out/.nojekyll | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./out | |
| # Deployment job | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| if: github.ref == 'refs/heads/main' | |
| permissions: | |
| pages: write | |
| id-token: write | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |