Skip to content

Commit

Permalink
Update nextjs.yml for yarn/npm
Browse files Browse the repository at this point in the history
  • Loading branch information
burtonjong authored Jan 22, 2025
1 parent 1e6cdd1 commit 84f4c1e
Showing 1 changed file with 40 additions and 48 deletions.
88 changes: 40 additions & 48 deletions .github/workflows/nextjs.yml
Original file line number Diff line number Diff line change
@@ -1,76 +1,68 @@
# Sample workflow for building and deploying a Next.js site to GitHub Pages
#
# To get started with Next.js see: https://nextjs.org/docs/getting-started
#
name: Test Next.JS build
name: ESLint

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

pull_request:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false
schedule:
- cron: "25 21 * * 4"

jobs:
# Build job
build:
eslint:
name: Run ESLint Scanning
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v3

- 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 "install-command=install" >> $GITHUB_OUTPUT
echo "runner=yarn" >> $GITHUB_OUTPUT
exit 0
elif [ -f "${{ github.workspace }}/package.json" ]; then
elif [ -f "${{ github.workspace }}/package-lock.json" ]; then
echo "manager=npm" >> $GITHUB_OUTPUT
echo "command=ci" >> $GITHUB_OUTPUT
echo "runner=npx --no-install" >> $GITHUB_OUTPUT
echo "install-command=ci" >> $GITHUB_OUTPUT
echo "runner=npx" >> $GITHUB_OUTPUT
exit 0
else
echo "Unable to determine package manager"
exit 1
fi
- name: Setup Node
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: ${{ steps.detect-package-manager.outputs.manager }}
- name: Restore cache
uses: actions/cache@v3
with:
path: |
.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }}-

- name: Install dependencies
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
- name: Create Fake Amplify Config
run: echo "{}" >> amplify_outputs.json
- name: Build with Next.js
run: ${{ steps.detect-package-manager.outputs.runner }} next build
env:
CONTENTFUL_SPACE_ID: ${{ secrets.CONTENTFUL_SPACE_ID }}
CONTENTFUL_DELIVERY_API_TOKEN: ${{ secrets.CONTENTFUL_DELIVERY_API_TOKEN }}
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.install-command }}

- name: Install ESLint dependencies
run: |
${{ steps.detect-package-manager.outputs.manager }} add [email protected]
${{ steps.detect-package-manager.outputs.manager }} add @microsoft/[email protected]
- name: Run ESLint
run: |
${{ steps.detect-package-manager.outputs.runner }} eslint .
--config .eslintrc.cjs
--ext .js,.jsx,.ts,.tsx
# --format @microsoft/eslint-formatter-sarif
# --output-file eslint-results.sarif

# Uncomment the following step to upload SARIF results
# - name: Upload analysis results to GitHub
# uses: github/codeql-action/upload-sarif@v2
# with:
# sarif_file: eslint-results.sarif
# wait-for-processing: true

0 comments on commit 84f4c1e

Please sign in to comment.