nextjs.yml 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Sample workflow for building and deploying a Next.js site to GitHub Pages
  2. #
  3. # To get started with Next.js see: https://nextjs.org/docs/getting-started
  4. #
  5. name: Deploy Next.js site to Pages
  6. on:
  7. # Runs on pushes targeting the default branch
  8. push:
  9. branches: ["gh-pages"]
  10. # Allows you to run this workflow manually from the Actions tab
  11. workflow_dispatch:
  12. # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
  13. permissions:
  14. contents: read
  15. pages: write
  16. id-token: write
  17. # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
  18. # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
  19. concurrency:
  20. group: "pages"
  21. cancel-in-progress: false
  22. jobs:
  23. # Build job
  24. build:
  25. runs-on: ubuntu-latest
  26. steps:
  27. - name: Checkout
  28. uses: actions/checkout@v3
  29. - name: Detect package manager
  30. id: detect-package-manager
  31. run: |
  32. if [ -f "${{ github.workspace }}/yarn.lock" ]; then
  33. echo "manager=yarn" >> $GITHUB_OUTPUT
  34. echo "command=install" >> $GITHUB_OUTPUT
  35. echo "runner=yarn" >> $GITHUB_OUTPUT
  36. exit 0
  37. elif [ -f "${{ github.workspace }}/package.json" ]; then
  38. echo "manager=npm" >> $GITHUB_OUTPUT
  39. echo "command=ci" >> $GITHUB_OUTPUT
  40. echo "runner=npx --no-install" >> $GITHUB_OUTPUT
  41. exit 0
  42. else
  43. echo "Unable to determine package manager"
  44. exit 1
  45. fi
  46. - name: Setup Node
  47. uses: actions/setup-node@v3
  48. with:
  49. node-version: "16"
  50. cache: ${{ steps.detect-package-manager.outputs.manager }}
  51. - name: Setup Pages
  52. uses: actions/configure-pages@v3
  53. with:
  54. # Automatically inject basePath in your Next.js configuration file and disable
  55. # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
  56. #
  57. # You may remove this line if you want to manage the configuration yourself.
  58. static_site_generator: next
  59. - name: Restore cache
  60. uses: actions/cache@v3
  61. with:
  62. path: |
  63. .next/cache
  64. # Generate a new cache whenever packages or source files change.
  65. key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
  66. # If source files changed but packages didn't, rebuild from a prior cache.
  67. restore-keys: |
  68. ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
  69. - name: Install dependencies
  70. run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
  71. - name: Build with Next.js
  72. run: ${{ steps.detect-package-manager.outputs.runner }} next build
  73. - name: Static HTML export with Next.js
  74. run: ${{ steps.detect-package-manager.outputs.runner }} next export
  75. - name: Upload artifact
  76. uses: actions/upload-pages-artifact@v1
  77. with:
  78. path: ./out
  79. # Deployment job
  80. deploy:
  81. environment:
  82. name: github-pages
  83. url: ${{ steps.deployment.outputs.page_url }}
  84. runs-on: ubuntu-latest
  85. needs: build
  86. steps:
  87. - name: Deploy to GitHub Pages
  88. id: deployment
  89. uses: actions/deploy-pages@v2