1
0

deploy.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 to GH Pages
  6. on:
  7. # Runs on pushes targeting the default branch
  8. push:
  9. branches: ["docs"]
  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@v4
  29. with:
  30. fetch-depth: 0 # To preserve the full git history for accurate timestamps
  31. - name: Setup pnpm
  32. uses: pnpm/action-setup@v3
  33. with:
  34. version: 9
  35. - name: Detect package manager
  36. id: detect-package-manager
  37. run: |
  38. if [ -f "${{ github.workspace }}/yarn.lock" ]; then
  39. echo "manager=yarn" >> $GITHUB_OUTPUT
  40. echo "command=install" >> $GITHUB_OUTPUT
  41. echo "runner=yarn" >> $GITHUB_OUTPUT
  42. exit 0
  43. elif [ -f "${{ github.workspace }}/pnpm-lock.yaml" ]; then
  44. echo "manager=pnpm" >> $GITHUB_OUTPUT
  45. echo "command=install --frozen-lockfile" >> $GITHUB_OUTPUT
  46. echo "runner=npx --no-install" >> $GITHUB_OUTPUT
  47. exit 0
  48. elif [ -f "${{ github.workspace }}/package.json" ]; then
  49. echo "manager=npm" >> $GITHUB_OUTPUT
  50. echo "command=ci" >> $GITHUB_OUTPUT
  51. echo "runner=npx --no-install" >> $GITHUB_OUTPUT
  52. exit 0
  53. else
  54. echo "Unable to determine package manager"
  55. exit 1
  56. fi
  57. - name: Setup Node
  58. uses: actions/setup-node@v4
  59. with:
  60. node-version: "22"
  61. cache: ${{ steps.detect-package-manager.outputs.manager }}
  62. - name: Setup Pages
  63. uses: actions/configure-pages@v5
  64. # with:
  65. # Automatically inject basePath in your Next.js configuration file and disable
  66. # server side image optimization (https://nextjs.org/docs/api-reference/next/image#unoptimized).
  67. #
  68. # You may remove this line if you want to manage the configuration yourself.
  69. # static_site_generator: next
  70. - name: Restore cache
  71. uses: actions/cache@v4
  72. with:
  73. path: |
  74. .next/cache
  75. # Generate a new cache whenever packages or source files change.
  76. key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
  77. # If source files changed but packages didn't, rebuild from a prior cache.
  78. restore-keys: |
  79. ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}-
  80. - name: Install dependencies
  81. run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
  82. - name: Build with Next.js
  83. run: ${{ steps.detect-package-manager.outputs.runner }} next build
  84. - name: Upload artifact
  85. uses: actions/upload-pages-artifact@v3
  86. with:
  87. path: ./out
  88. # Deployment job
  89. deploy:
  90. permissions:
  91. pages: write # to deploy to Pages
  92. id-token: write # to verify the deployment originates from an appropriate source
  93. environment:
  94. name: github-pages
  95. url: ${{ steps.deployment.outputs.page_url }}
  96. runs-on: ubuntu-latest
  97. needs: build
  98. steps:
  99. - name: Deploy to GitHub Pages
  100. id: deployment
  101. uses: actions/deploy-pages@v4