update comment #18
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
| # Workflow to build and deploy a Next.js site to GitHub Pages | |
| name: Deploy | |
| on: | |
| push: | |
| branches: ["main"] | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| actions: write | |
| contents: write | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| cleanup: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Clean up workspace | |
| run: | | |
| sudo rm -rf $HOME/.npm | |
| sudo rm -rf $HOME/.cache | |
| sudo apt-get clean | |
| sudo rm -rf /tmp/* | |
| - name: Aggressive Clean Up | |
| run: | | |
| echo "Freeing disk space..." | |
| sudo rm -rf $HOME/.npm | |
| sudo rm -rf $HOME/.cache | |
| sudo rm -rf /usr/share/dotnet | |
| sudo rm -rf /opt/hostedtoolcache | |
| sudo rm -rf /usr/local/share/boost | |
| sudo rm -rf /usr/lib/jvm | |
| sudo apt-get clean | |
| sudo rm -rf /tmp/* | |
| sudo journalctl --rotate | |
| sudo journalctl --vacuum-time=1s | |
| echo "Remaining space:" | |
| df -h | |
| - name: Delete All Artifacts | |
| uses: actions/github-script@v6 | |
| with: | |
| script: | | |
| const res = await github.rest.actions.listArtifactsForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| }); | |
| console.log(`Found ${res.data.artifacts.length} artifacts`); | |
| for (const { id, name, size_in_bytes, created_at } of res.data.artifacts) { | |
| console.log(`Deleting ${name} (${(size_in_bytes / 1024 / 1024).toFixed(2)} MB) created at ${created_at}`); | |
| await github.rest.actions.deleteArtifact({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| artifact_id: id, | |
| }); | |
| } | |
| console.log("All deletions attempted."); | |
| build: | |
| needs: cleanup | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "npm" | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: .next/cache | |
| key: ${{ runner.os }}-nextjs-${{ hashFiles('package-lock.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nextjs- | |
| - name: Install dependencies | |
| run: npm install --force | |
| - name: Set deployment environment variable | |
| run: echo "NEXT_PUBLIC_DEPLOYMENT=PRODUCTION" >> $GITHUB_ENV | |
| - name: Set Version Environment Variable | |
| run: echo "NEXT_PUBLIC_VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Set NEXT_PUBLIC_REPO_NAME | |
| run: | | |
| echo "NEXT_PUBLIC_REPO_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV | |
| - name: Build Next.js site | |
| run: npm run build | |
| - name: Upload static site artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./out | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |