Add pre-commit checks and cache lint workflow

This commit is contained in:
Kari Lintulaakso
2025-11-20 15:36:46 +02:00
parent fa6c32ef0a
commit 04ba84faef
5 changed files with 50 additions and 17 deletions
+8 -16
View File
@@ -15,22 +15,14 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: |
package-lock.json
backend/package-lock.json
frontend/package-lock.json
- name: 'Install root dependencies'
run: npm run setup
- name: 'Run cypress linter'
run: npm run lint:cypress
- name: 'Run backend linter'
working-directory: 'backend'
- name: 'Run lint (root, backend, frontend, cypress)'
run: npm run lint
- name: 'Run backend tsc'
working-directory: 'backend'
run: npx tsc --noEmit
- name: 'Install frontend dependencies'
working-directory: 'frontend'
run: npm ci
- name: 'Run frontend linter'
working-directory: 'frontend'
run: npm run lint
- name: 'Run frontend tsc'
working-directory: 'frontend'
run: npx tsc --noEmit
- name: 'Run tsc (backend & frontend)'
run: npm run tsc
+9
View File
@@ -0,0 +1,9 @@
# Husky hooks
## Pre-commit
- Runs `npm run lint` and `npm run tsc` to align with CI.
- Requires dependencies installed via `npm run setup`.
## Skipping in emergencies
- Temporarily bypass by prefixing commands with `HUSKY_SKIP_CHECKS=1` or `HUSKY=0`, e.g. `HUSKY=0 git commit -m "message"`.
- Re-enable hooks after resolving issues.
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env sh
if [ "$HUSKY_SKIP_CHECKS" = "1" ]; then
echo "Husky pre-commit checks skipped via HUSKY_SKIP_CHECKS."
exit 0
fi
command -v npm >/dev/null 2>&1 || {
echo "npm not found. Install dependencies before committing." >&2
exit 1
}
npm run lint && npm run tsc
+17
View File
@@ -18,6 +18,7 @@
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.12.0",
"husky": "^9.1.7",
"prettier": "^3.3.3",
"supertest": "^7.0.0",
"typescript": "^5.9.3"
@@ -5139,6 +5140,22 @@
"node": ">=8.12.0"
}
},
"node_modules/husky": {
"version": "9.1.7",
"resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz",
"integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==",
"dev": true,
"license": "MIT",
"bin": {
"husky": "bin.js"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/typicode"
}
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
+3 -1
View File
@@ -60,7 +60,8 @@
"config:anon:host": "sed -i -e \"s|nowdb-db-dev|nowdb-db-anon|g\" .anon.env",
"config:anon:coordinator": "sed -i -e \"s|IZ|TEST-SU|g\" .anon.env",
"config:dev": "cp -n .template.env .dev.env && npm run config:geonames -- .dev.env",
"config:geonames": "sed -i -e \"s|GEONAMES_USERNAME: \\\"\\\"|GEONAMES_USERNAME: $GEONAMES_USERNAME|g\""
"config:geonames": "sed -i -e \"s|GEONAMES_USERNAME: \\\"\\\"|GEONAMES_USERNAME: $GEONAMES_USERNAME|g\"",
"prepare": "husky"
},
"author": "",
"devDependencies": {
@@ -74,6 +75,7 @@
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.12.0",
"husky": "^9.1.7",
"prettier": "^3.3.3",
"supertest": "^7.0.0",
"typescript": "^5.9.3"