From f0cfdfdd2a70ed40657017103fdd0e9c09f0b5d0 Mon Sep 17 00:00:00 2001 From: c0mrade Date: Tue, 27 Jan 2026 17:37:53 +0300 Subject: [PATCH] feat: add husky pre-commit hooks and reusable CI lint workflow - Add husky with lint-staged for pre-commit checks (eslint --fix, prettier --write) - Add reusable lint.yml workflow (eslint, prettier, tsc) - Gate docker, release, and CI pipelines behind lint job via needs: lint --- .github/workflows/ci.yml | 14 +++++++------- .github/workflows/docker.yml | 4 ++++ .github/workflows/lint.yml | 29 +++++++++++++++++++++++++++++ .github/workflows/release.yml | 4 ++++ .husky/pre-commit | 1 + 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .husky/pre-commit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8414a20..5630838 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,5 @@ +name: CI + on: push: branches: [main, dev] @@ -5,7 +7,11 @@ on: branches: [main, dev] jobs: - lint-and-build: + lint: + uses: ./.github/workflows/lint.yml + + build: + needs: lint runs-on: ubuntu-latest steps: - name: Checkout code @@ -20,12 +26,6 @@ jobs: - name: Install dependencies run: npm ci - - name: Run ESLint - run: npm run lint - - - name: Run TypeScript check - run: npx tsc --noEmit - - name: Build run: npm run build env: diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 57fbd02..10df084 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -13,7 +13,11 @@ env: IMAGE_NAME: ${{ github.repository }} jobs: + lint: + uses: ./.github/workflows/lint.yml + build-and-push: + needs: lint runs-on: ubuntu-latest permissions: contents: read diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..e942159 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,29 @@ +name: Lint & Format + +on: + workflow_call: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run ESLint + run: npm run lint + + - name: Check formatting + run: npm run format:check + + - name: Run TypeScript check + run: npx tsc --noEmit diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fe4ab04..32ccc19 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,11 @@ permissions: contents: write jobs: + lint: + uses: ./.github/workflows/lint.yml + create-release: + needs: lint runs-on: ubuntu-latest steps: diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..2312dc5 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +npx lint-staged