Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 63 additions & 42 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -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