nextjs.yml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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: ["main"]
  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 one concurrent deployment
  18. concurrency:
  19. group: "pages"
  20. cancel-in-progress: true
  21. jobs:
  22. # Build job
  23. build:
  24. runs-on: ubuntu-latest
  25. steps:
  26. - name: Checkout
  27. uses: actions/checkout@v3
  28. - name: Detect package manager
  29. id: detect-package-manager
  30. run: |
  31. if [ -f "${{ github.workspace }}/yarn.lock" ]; then
  32. echo "manager=yarn" >> $GITHUB_OUTPUT
  33. echo "command=install --frozen-lockfile" >> $GITHUB_OUTPUT
  34. echo "runner=yarn" >> $GITHUB_OUTPUT
  35. exit 0
  36. elif [ -f "${{ github.workspace }}/package.json" ]; then
  37. echo "manager=npm" >> $GITHUB_OUTPUT
  38. echo "command=ci" >> $GITHUB_OUTPUT
  39. echo "runner=npx --no-install" >> $GITHUB_OUTPUT
  40. exit 0
  41. else
  42. echo "Unable to determine packager manager"
  43. exit 1
  44. fi
  45. - name: Setup Node
  46. uses: actions/setup-node@v3
  47. with:
  48. node-version: "16"
  49. cache: ${{ steps.detect-package-manager.outputs.manager }}
  50. - name: Cache node_modules
  51. uses: actions/cache@v3
  52. with:
  53. path: |
  54. ~/.npm
  55. ~/.cache/yarn
  56. key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}
  57. restore-keys: ${{ runner.os }}-node-
  58. - name: Setup Pages
  59. uses: actions/configure-pages@v3
  60. with:
  61. # Automatically inject basePath in your Next.js configuration file and disable
  62. # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
  63. #
  64. # You may remove this line if you want to manage the configuration yourself.
  65. static_site_generator: next
  66. - name: Restore cache
  67. uses: actions/cache@v3
  68. with:
  69. path: |
  70. .next/cache
  71. # Generate a new cache whenever packages or source files change.
  72. key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
  73. # If source files changed but packages didn't, rebuild from a prior cache.
  74. restore-keys: |
  75. ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
  76. - name: Install dependencies
  77. run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
  78. - name: Build with Next.js
  79. run: ${{ steps.detect-package-manager.outputs.runner }} next build
  80. - name: Static HTML export with Next.js
  81. run: ${{ steps.detect-package-manager.outputs.runner }} next export
  82. - name: Upload artifact
  83. uses: actions/upload-pages-artifact@v1
  84. with:
  85. path: ./out
  86. # Deployment job
  87. deploy:
  88. environment:
  89. name: github-pages
  90. url: ${{ steps.deployment.outputs.page_url }}
  91. runs-on: ubuntu-latest
  92. needs: build
  93. steps:
  94. - name: Deploy to GitHub Pages
  95. id: deployment
  96. uses: actions/deploy-pages@v1