build: use lefthook + add info.xml lint

This commit is contained in:
2026-04-12 23:55:21 +03:00
parent bd940f0262
commit 3a03aad9de
7 changed files with 155 additions and 20 deletions

View File

@@ -1,3 +0,0 @@
#!/usr/bin/env bash
export PHP_CS_FIXER_IGNORE_ENV=1
pnpm lint-staged -- --relative

View File

@@ -1,2 +1,4 @@
templates/
gen/
openapi.json
openapi-*.json

View File

@@ -234,9 +234,13 @@ test: composer
fi; \
echo "\x1b[32mUsing Nextcloud root: $$NC_ROOT\x1b[0m"; \
NEXTCLOUD_ROOT="$$NC_ROOT" $(CURDIR)/vendor/phpunit/phpunit/phpunit -c tests/phpunit.xml; \
UNIT_EXIT=$$?; \
INTEG_EXIT=0; \
if [ -f tests/phpunit.integration.xml ]; then \
NEXTCLOUD_ROOT="$$NC_ROOT" $(CURDIR)/vendor/phpunit/phpunit/phpunit -c tests/phpunit.integration.xml; \
fi
INTEG_EXIT=$$?; \
fi; \
exit $$((UNIT_EXIT + INTEG_EXIT))
# test-docker:
# - Run PHP unit tests inside a Nextcloud Docker container
@@ -270,6 +274,21 @@ test-docker:
echo "\x1b[33mRunning tests in container $$CONTAINER_ID for app $$APP_DIR\x1b[0m"; \
docker exec $$CONTAINER_ID phpunit -c apps-shared/$$APP_DIR/tests/phpunit.docker.xml
info_xsd_url=https://apps.nextcloud.com/schema/apps/info.xsd
info_xsd=$(build_tools_directory)/info.xsd
$(info_xsd):
@mkdir -p $(build_tools_directory)
curl -sS -o $(info_xsd) $(info_xsd_url)
# lint-appinfo:
# - Validate appinfo/info.xml against the Nextcloud App Store XSD schema
.PHONY: lint-appinfo
lint-appinfo: $(info_xsd)
@echo "\x1b[33mValidating appinfo/info.xml against Nextcloud schema...\x1b[0m"
@xmllint --noout --schema $(info_xsd) appinfo/info.xml
@echo "\x1b[32mappinfo/info.xml is valid.\x1b[0m"
# lint:
# - Lint JS via pnpm and PHP via composer script "lint"
.PHONY: lint

View File

@@ -91,11 +91,10 @@ don't hesitate to open an appropriate issue and I will do my best to reply promp
Most development processes are automated:
- **GitHub Actions** run tests, builds, and validations on each push or pull request.
- **Pre-commit formatting** is handled by [lint-staged](https://github.com/okonet/lint-staged),
which automatically formats code before committing:
- **Pre-commit formatting** is handled by [Lefthook](https://github.com/evilmartians/lefthook),
which automatically formats and lints code before committing.
> 🛠️ The NPM package [husky](https://www.npmjs.com/package/husky) takes care of installing the
> pre-commit hook automatically after `pnpm install`.
> 🛠️ Lefthook is installed automatically via the `prepare` script after `pnpm install`.
---

28
lefthook.yml Normal file
View File

@@ -0,0 +1,28 @@
pre-commit:
parallel: true
commands:
eslint:
glob: "*.{ts,vue}"
run: pnpm eslint --fix {staged_files}
stage_fixed: true
prettier:
glob: "*.{scss,vue,ts,md}"
run: pnpm prettier --write {staged_files}
stage_fixed: true
prettier-json:
glob: "*.json"
exclude: "openapi.json"
run: pnpm prettier --write {staged_files}
stage_fixed: true
php-cs-fixer:
glob: "*.php"
exclude: "/gen/"
env:
PHP_CS_FIXER_IGNORE_ENV: "1"
run: make php-cs-fixer && make test
openapi:
glob: "*Controller.php"
run: make openapi && git add openapi.json openapi-*.json
lint-appinfo:
glob: "appinfo/info.xml"
run: make lint-appinfo

View File

@@ -12,7 +12,7 @@
"build": "vite build",
"lint": "eslint src",
"format": "eslint --fix src && prettier --write {vite.config.ts,src/,README.md}",
"prepare": "husky",
"prepare": "lefthook install",
"gen": "simple-scaffold -c . -k"
},
"browserslist": [
@@ -37,7 +37,7 @@
"@nextcloud/vite-config": "2.5.2",
"@vue/tsconfig": "^0.9.1",
"eslint": "^10.2.0",
"husky": "^9.1.7",
"lefthook": "^2.1.5",
"lint-staged": "^16.4.0",
"prettier": "^3.8.1",
"prettier-plugin-vue": "^1.1.6",

110
pnpm-lock.yaml generated
View File

@@ -57,9 +57,9 @@ importers:
eslint:
specifier: ^10.2.0
version: 10.2.0
husky:
specifier: ^9.1.7
version: 9.1.7
lefthook:
specifier: ^2.1.5
version: 2.1.5
lint-staged:
specifier: ^16.4.0
version: 16.4.0
@@ -2501,11 +2501,6 @@ packages:
https-browserify@1.0.0:
resolution: {integrity: sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg==}
husky@9.1.7:
resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==}
engines: {node: '>=18'}
hasBin: true
ieee754@1.2.1:
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
@@ -2811,6 +2806,60 @@ packages:
layerr@3.0.0:
resolution: {integrity: sha512-tv754Ki2dXpPVApOrjTyRo4/QegVb9eVFq4mjqp4+NM5NaX7syQvN5BBNfV/ZpAHCEHV24XdUVrBAoka4jt3pA==}
lefthook-darwin-arm64@2.1.5:
resolution: {integrity: sha512-VITTaw8PxxyE26gkZ8UcwIa5ZrWnKNRGLeeSrqri40cQdXvLTEoMq2tjjw7eiL9UcB0waRReDdzydevy9GOPUQ==}
cpu: [arm64]
os: [darwin]
lefthook-darwin-x64@2.1.5:
resolution: {integrity: sha512-AvtjYiW0BSGHBGrdvL313seUymrW9FxI+6JJwJ+ZSaa2sH81etrTB0wAwlH1L9VfFwK9+gWvatZBvLfF3L4fPw==}
cpu: [x64]
os: [darwin]
lefthook-freebsd-arm64@2.1.5:
resolution: {integrity: sha512-mXjJwe8jKGWGiBYUxfQY1ab3Nn5NhafqT9q3KJz8m5joGGQj4JD0cbWxF1nVBLBWsDGbWZRZunTCMGcIScT2bQ==}
cpu: [arm64]
os: [freebsd]
lefthook-freebsd-x64@2.1.5:
resolution: {integrity: sha512-exD69dCjc1K45BxatDPGoH4NmEvgLKPm4kJLOWn1fTeHRKZwWiFPwnjknEoG2OemlCDHmCU++5X40kMEG0WBlA==}
cpu: [x64]
os: [freebsd]
lefthook-linux-arm64@2.1.5:
resolution: {integrity: sha512-57TDKC5ewWpsCLZQKIJMHumFEObYKVundmPpiWhX491hINRZYYOL/26yrnVnNcidThRzTiTC+HLcuplLcaXtbA==}
cpu: [arm64]
os: [linux]
lefthook-linux-x64@2.1.5:
resolution: {integrity: sha512-bqK3LrAB5l5YaCaoHk6qRWlITrGWzP4FbwRxA31elbxjd0wgNWZ2Sn3zEfSEcxz442g7/PPkEwqqsTx0kSFzpg==}
cpu: [x64]
os: [linux]
lefthook-openbsd-arm64@2.1.5:
resolution: {integrity: sha512-5aSwK7vV3A6t0w9PnxCMiVjQlcvopBP50BtmnnLnNJyAYHnFbZ0Baq5M0WkE9IsUkWSux0fe6fd0jDkuG711MA==}
cpu: [arm64]
os: [openbsd]
lefthook-openbsd-x64@2.1.5:
resolution: {integrity: sha512-Y+pPdDuENJ8qWnUgL02xxhpjblc0WnwXvWGfqnl3WZrAgHzQpwx3G6469RID/wlNVdHYAlw3a8UkFSMYsTzXvA==}
cpu: [x64]
os: [openbsd]
lefthook-windows-arm64@2.1.5:
resolution: {integrity: sha512-2PlcFBjTzJaMufw0c28kfhB/0zmaRCU0TRPPsil/HU2YNOExod4upPGLk9qjgsOmb2YVWFz6zq6u7+D1yqmzTQ==}
cpu: [arm64]
os: [win32]
lefthook-windows-x64@2.1.5:
resolution: {integrity: sha512-yiAh8qxml6uqy10jDxOdN9fOQpyLxBFY1fgCEAhn7sVJYmJKRhjqSBwZX6LG5MQjzr29KStrIdw7TR3lf3rT7Q==}
cpu: [x64]
os: [win32]
lefthook@2.1.5:
resolution: {integrity: sha512-yB9IFWurFllusbPZqvG0EavTmpNXPya2MuO7Li7YT78xAj3uCQ3AgmW9TVUbTTsSMhsegbiAMRpwfEk2TP1P0A==}
hasBin: true
levn@0.4.1:
resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==}
engines: {node: '>= 0.8.0'}
@@ -7000,8 +7049,6 @@ snapshots:
https-browserify@1.0.0: {}
husky@9.1.7: {}
ieee754@1.2.1: {}
ignore@5.3.2: {}
@@ -7268,6 +7315,49 @@ snapshots:
layerr@3.0.0:
optional: true
lefthook-darwin-arm64@2.1.5:
optional: true
lefthook-darwin-x64@2.1.5:
optional: true
lefthook-freebsd-arm64@2.1.5:
optional: true
lefthook-freebsd-x64@2.1.5:
optional: true
lefthook-linux-arm64@2.1.5:
optional: true
lefthook-linux-x64@2.1.5:
optional: true
lefthook-openbsd-arm64@2.1.5:
optional: true
lefthook-openbsd-x64@2.1.5:
optional: true
lefthook-windows-arm64@2.1.5:
optional: true
lefthook-windows-x64@2.1.5:
optional: true
lefthook@2.1.5:
optionalDependencies:
lefthook-darwin-arm64: 2.1.5
lefthook-darwin-x64: 2.1.5
lefthook-freebsd-arm64: 2.1.5
lefthook-freebsd-x64: 2.1.5
lefthook-linux-arm64: 2.1.5
lefthook-linux-x64: 2.1.5
lefthook-openbsd-arm64: 2.1.5
lefthook-openbsd-x64: 2.1.5
lefthook-windows-arm64: 2.1.5
lefthook-windows-x64: 2.1.5
levn@0.4.1:
dependencies:
prelude-ls: 1.2.1