Skip to content

Next.js Project Structure Refactoring #612

Next.js Project Structure Refactoring

Next.js Project Structure Refactoring #612

Workflow file for this run

name: CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
type-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Type check
run: npm run type-check
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Restore Next.js cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-
- name: Build
run: npm run build
- name: Save Next.js cache
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/.next/cache
key: ${{ runner.os }}-nextjs-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# Cypress E2E test job
cypress:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Restore Next.js cache
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/.next/cache
# Modified to use both build and cypress cache keys in restore
key: ${{ runner.os }}-nextjs-build-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
restore-keys: |
${{ runner.os }}-nextjs-build-${{ hashFiles('**/package-lock.json') }}-
- name: Build application for testing
run: npm run build
- name: Test production start (debugging)
run: |
echo "Testing if production server starts correctly..."
timeout 30s npm start &
SERVER_PID=$!
sleep 10
if curl -f http://localhost:3000 > /dev/null 2>&1; then
echo "✅ Server is responding correctly"
kill $SERVER_PID || true
else
echo "❌ Server failed to respond"
kill $SERVER_PID || true
exit 1
fi
- name: Save Next.js cache
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}/.next/cache
# Modified to use a different key than the build job
key: ${{ runner.os }}-nextjs-cypress-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
- name: Cypress run
uses: cypress-io/github-action@v6
with:
start: npm start
wait-on: 'http://localhost:3000'
browser: chrome
config-file: cypress.config.ts
wait-on-timeout: 120
continue-on-error: false
- name: Upload Cypress screenshots
uses: actions/upload-artifact@v4
if: failure() && hashFiles('cypress/screenshots/**') != ''
with:
name: cypress-screenshots
path: cypress/screenshots
retention-days: 7
- name: Upload Cypress videos
uses: actions/upload-artifact@v4
if: always() && hashFiles('cypress/videos/**') != ''
with:
name: cypress-videos
path: cypress/videos
retention-days: 7