nextjs.yml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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" >> $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: Setup Pages
  51. uses: actions/configure-pages@v3
  52. with:
  53. # Automatically inject basePath in your Next.js configuration file and disable
  54. # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
  55. #
  56. # You may remove this line if you want to manage the configuration yourself.
  57. static_site_generator: next
  58. - name: Restore cache
  59. uses: actions/cache@v3
  60. with:
  61. path: |
  62. .next/cache
  63. # Generate a new cache whenever packages or source files change.
  64. key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
  65. # If source files changed but packages didn't, rebuild from a prior cache.
  66. restore-keys: |
  67. ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-
  68. - name: Install dependencies
  69. run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
  70. - name: Build with Next.js
  71. run: ${{ steps.detect-package-manager.outputs.runner }} next build
  72. - name: Static HTML export with Next.js
  73. run: ${{ steps.detect-package-manager.outputs.runner }} next export
  74. - name: Upload artifact
  75. uses: actions/upload-pages-artifact@v1
  76. with:
  77. path: ./out
  78. # Deployment job
  79. deploy:
  80. environment:
  81. name: github-pages
  82. url: ${{ steps.deployment.outputs.page_url }}
  83. runs-on: ubuntu-latest
  84. needs: build
  85. steps:
  86. - name: Deploy to GitHub Pages
  87. id: deployment
  88. uses: actions/deploy-pages@v1