From 43e541463290967c11d3c4b319f23cd34ce595b3 Mon Sep 17 00:00:00 2001 From: Bradley Hower <139923955+Bradley-Hower@users.noreply.github.com> Date: Tue, 6 Aug 2024 19:01:27 -0700 Subject: [PATCH] Update deployment.yml --- .github/workflows/deployment.yml | 105 ++++++++++++++++++------------- 1 file changed, 63 insertions(+), 42 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index 082a65316..bdcc25608 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -1,50 +1,71 @@ -# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions -# https://www.youtube.com/watch?v=yRz8D_oJMWQ - -name: Node.js CI +name: Deploy Next.js site to Pages on: push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: + branches: ["main"] + workflow_dispatch: - runs-on: macos-11 +permissions: + contents: read + pages: write + id-token: write - # env: - # Repository name - # https://www.linkedin.com/pulse/deploy-nextjs-app-github-pages-federico-antu%C3%B1a/ - # BASE_PATH: /${{ github.event.repository.name }} +concurrency: + group: "pages" + cancel-in-progress: false - strategy: - matrix: - node-version: [14.x] - # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Detect package manager + id: detect-package-manager + run: | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then + echo "manager=yarn" >> $GITHUB_OUTPUT + echo "command=install" >> $GITHUB_OUTPUT + echo "runner=yarn" >> $GITHUB_OUTPUT + exit 0 + elif [ -f "${{ github.workspace }}/package.json" ]; then + echo "manager=npm" >> $GITHUB_OUTPUT + echo "command=ci" >> $GITHUB_OUTPUT + echo "runner=npx --no-install" >> $GITHUB_OUTPUT + exit 0 + else + echo "Unable to determine package manager" + exit 1 + fi + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: ${{ steps.detect-package-manager.outputs.manager }} + + - name: Install dependencies + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} + + - name: Build with Next.js + run: ${{ steps.detect-package-manager.outputs.runner }} next build + + - name: Export static site + run: ${{ steps.detect-package-manager.outputs.runner }} next export + + - name: Upload 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: - - uses: actions/checkout@v2 - - name: Set Environment Variables - run: echo "BASE_PATH=/${GITHUB_REPOSITORY#*/}" >> $GITHUB_ENV - - name: Test Environment Variables - run: echo ${{ env.BASE_PATH }} - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm ci - # - run: npm run prebuild # build automatically runs prebuild - - run: npm run build - - run: npm run export - - run: touch ./out/.nojekyll - - # https://github.com/marketplace/actions/deploy-to-github-pages - - name: Deploy 🚀 - uses: JamesIves/github-pages-deploy-action@4.1.4 - with: - branch: gh-pages # The branch the action should deploy to. - folder: out # The folder the action should deploy. + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4