Skip to content

ci: enhance deploy and lint workflows with modular jobs and caching #31

ci: enhance deploy and lint workflows with modular jobs and caching

ci: enhance deploy and lint workflows with modular jobs and caching #31

Workflow file for this run

name: Lint and Type-checking
on:
push:
branches:
- dev
pull_request:
branches:
- dev
jobs:
lint:
name: ESLint & Prettier
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.4.0
with:
node-version: '22.x'
- name: Cache node modules
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 #v4.2.4
with:
path: node_modules
key: node_modules-${{hashFiles('package-lock.json')}}
restore-keys: |
node_modules-
- name: Install dependencies
run: npm ci
- name: Determine base branch
id: vars
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "BASE_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
else
echo "BASE_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
fi
- name: Fetch base branch
run: |
git fetch origin $BASE_BRANCH
- name: Get list of changed files
id: files
run: |
echo "CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRT origin/$BASE_BRANCH | tr '\n' ' ')" >> $GITHUB_ENV
- name: Lint JS/TS files with ESLint (no auto-fix)
if: ${{ env.CHANGED_FILES != ''}}
run: |
FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n' | grep -E '\.(js|jsx|ts|tsx)$' | xargs)
if [ -n "$FILES" ]; then
echo "Running ESLint on:"
echo "$FILES"
npx next lint --file $FILES
else
echo "No JS/TS files to lint."
fi
- name: Format other files with Prettier (no auto-fix)
if: ${{ env.CHANGED_FILES != ''}}
run: |
FILES=$(echo "$CHANGED_FILES" | tr ' ' '\n' | grep -E '\.(json|md|css|scss|html)$' | xargs)
if [ -n "$FILES" ]; then
echo "Running Prettier on:"
echo "$FILES"
npx prettier --check $FILES
else
echo "No files to format with Prettier."
fi
type-check:
name: Type Checking
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 #v4.2.2
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 #v4.4.0
with:
node-version: '22.x'
- name: Cache node modules
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 #v4.2.4
with:
path: node_modules
key: node_modules-${{hashFiles('package-lock.json')}}
restore-keys: |
node_modules-
- name: Install dependencies
run: npm ci
- name: Type Check
run: |
echo "Running TypeScript type checking..."
npx tsc --noEmit