diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index e9e35bcf..951d8593 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -18,25 +18,55 @@ permissions: actions: read jobs: + # Lets docs-only PRs skip e2e. Pushes to main and manual runs always run it. + changes: + name: Detect changes + runs-on: ubuntu-latest + outputs: + code: ${{ steps.filter.outputs.code }} + steps: + - name: Check for changes outside docs + id: filter + if: github.event_name == 'pull_request' + uses: dorny/paths-filter@v4 + with: + predicate-quantifier: every + filters: | + code: + - "**" + - "!**/*.md" + - "!docs/**" + ci: uses: ./.github/workflows/ci.yml secrets: inherit e2e: + needs: [changes] + if: github.event_name != 'pull_request' || needs.changes.outputs.code == 'true' uses: ./.github/workflows/e2e.yml secrets: inherit all-checks: name: All checks passed runs-on: ubuntu-latest - needs: [ci, e2e] + needs: [changes, ci, e2e] if: always() steps: - name: Verify all required jobs succeeded + env: + CHANGES_RESULT: ${{ needs.changes.result }} + CI_RESULT: ${{ needs.ci.result }} + E2E_RESULT: ${{ needs.e2e.result }} + E2E_SKIPPABLE: ${{ github.event_name == 'pull_request' && needs.changes.outputs.code != 'true' }} run: | set -euo pipefail - if [ "${{ needs.ci.result }}" != "success" ] || [ "${{ needs.e2e.result }}" != "success" ]; then - echo "ci=${{ needs.ci.result }} e2e=${{ needs.e2e.result }}" + echo "changes=$CHANGES_RESULT ci=$CI_RESULT e2e=$E2E_RESULT e2e_skippable=$E2E_SKIPPABLE" + if [ "$CHANGES_RESULT" != "success" ] || [ "$CI_RESULT" != "success" ]; then + exit 1 + fi + # e2e may only be skipped when the PR touches docs alone + if [ "$E2E_RESULT" != "success" ] && ! { [ "$E2E_RESULT" = "skipped" ] && [ "$E2E_SKIPPABLE" = "true" ]; }; then exit 1 fi diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 00000000..5ee7abd8 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +pnpm exec lint-staged diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 09f51d31..1636017a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,3 +27,10 @@ and commit your changes. This project is designed to work both with and without Docker. Please don't break this! + +## Pre-commit hook + +`pnpm install` sets up a git pre-commit hook (husky + lint-staged) that runs +`eslint --fix` and `prettier --write` on the files you have staged. Type +checking and tests still run in CI. Skip the hook with `git commit --no-verify` +if you need to. diff --git a/package.json b/package.json index d0a24e6f..84fbdce6 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,8 @@ "lib": "pnpm --filter @app/lib", "server": "pnpm --filter @app/server", "worker": "pnpm --filter @app/worker", - "postinstall": "npx next telemetry disable" + "postinstall": "npx next telemetry disable", + "prepare": "husky || true" }, "packageManager": "pnpm@10.34.5", "author": "Prodeko webbitiimi ", @@ -78,9 +79,11 @@ "globals": "^15.14.0", "graphql": "^16.5.0", "graphql-config": "^4.3.3", + "husky": "^9.1.7", "inquirer": "^9.1.0", "jest": "^29.7.0", "json-sort-cli": "^2.0.15", + "lint-staged": "^17.6.0", "nodemon": "^2.0.19", "npm-check-updates": "^16.0.5", "prettier": "3.4.2", @@ -92,6 +95,13 @@ "type-fest": "^2.18.0", "typescript": "5.7.3" }, + "lint-staged": { + "*.{js,jsx,ts,tsx}": [ + "eslint --fix --no-warn-ignored", + "prettier --write" + ], + "*.{graphql,md}": "prettier --write" + }, "pnpm": { "overrides": { "dayjs": "^1.11.20", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d935534d..3186a3a5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -131,6 +131,9 @@ importers: graphql-config: specifier: ^4.3.3 version: 4.5.0(@types/node@22.19.17)(bufferutil@4.1.0)(encoding@0.1.13)(graphql@15.10.2)(utf-8-validate@5.0.10) + husky: + specifier: ^9.1.7 + version: 9.1.7 inquirer: specifier: ^9.1.0 version: 9.3.8(@types/node@22.19.17) @@ -140,6 +143,9 @@ importers: json-sort-cli: specifier: ^2.0.15 version: 2.1.11 + lint-staged: + specifier: ^17.6.0 + version: 17.6.0 nodemon: specifier: ^2.0.19 version: 2.0.22 @@ -5824,6 +5830,11 @@ packages: humanize-ms@1.2.1: resolution: {integrity: sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==} + husky@9.1.7: + resolution: {integrity: sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==} + engines: {node: '>=18'} + hasBin: true + iconv-lite@0.4.24: resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==} engines: {node: '>=0.10.0'} @@ -6523,6 +6534,11 @@ packages: lines-and-columns@1.2.4: resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==} + lint-staged@17.6.0: + resolution: {integrity: sha512-nOhBfYkZEwkFtNzD5pK9s9LkcWoxJ+whLzEnhqi9nl7zTB5n7tg8+9iYgMGx2Wm3VlLu8cbNj0RACzY+nWi5iQ==} + engines: {node: '>=22.22.1'} + hasBin: true + listr2@3.14.0: resolution: {integrity: sha512-TyWI8G99GX9GjE54cJ+RrNMcIFBfwMPxc3XTFiAYGN4s10hWROGtOg7+O6u6LE3mNkyld7RSLE6nrKBvTfcs3g==} engines: {node: '>=10.0.0'} @@ -7490,6 +7506,10 @@ packages: resolution: {integrity: sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==} engines: {node: '>=12'} + picomatch@4.0.7: + resolution: {integrity: sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==} + engines: {node: '>=12'} + pify@2.3.0: resolution: {integrity: sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==} engines: {node: '>=0.10.0'} @@ -8613,6 +8633,10 @@ packages: streamx@2.25.0: resolution: {integrity: sha512-0nQuG6jf1w+wddNEEXCF4nTg3LtufWINB5eFEN+5TNZW7KWJp6x87+JFL43vaAUPyCfH1wID+mNVyW6OHtFamg==} + string-argv@0.3.2: + resolution: {integrity: sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==} + engines: {node: '>=0.6.19'} + string-convert@0.2.1: resolution: {integrity: sha512-u/1tdPl4yQnPBjnVrmdLo9gtuLvELKsAoRapekWggdiQNvvvum+jYF329d84NAa660KQw7pB2n36KrIKVoXa3A==} @@ -8826,6 +8850,10 @@ packages: tiny-warning@1.0.3: resolution: {integrity: sha512-lBN9zLN/oAf68o3zNXYrdCt1kP8WsiGW8Oo2ka41b2IM5JL/S1CTyX1rW0mb/zSuJun0ZUrDxx4sqvYS2FWzPA==} + tinyexec@1.3.1: + resolution: {integrity: sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==} + engines: {node: '>=18'} + tinyglobby@0.2.16: resolution: {integrity: sha512-pn99VhoACYR8nFHhxqix+uvsbXineAasWm5ojXoN8xEwK5Kd3/TrhNn1wByuD52UxWRLy8pu+kRMniEi6Eq9Zg==} engines: {node: '>=12.0.0'} @@ -9392,6 +9420,11 @@ packages: engines: {node: '>= 14.6'} hasBin: true + yaml@2.9.1: + resolution: {integrity: sha512-3NxN8+78OdzbT7C/WjGsyfPAtJaN3FNDsWxv7Y7mcDsT/oOmgW8BpyQQFFBnvZE3j9Y2Sdz1ULFLezL7Eb2yFw==} + engines: {node: '>= 14.6'} + hasBin: true + yargs-parser@18.1.3: resolution: {integrity: sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==} engines: {node: '>=6'} @@ -12366,7 +12399,7 @@ snapshots: dependencies: '@types/estree': 1.0.8 estree-walker: 2.0.2 - picomatch: 4.0.4 + picomatch: 4.0.7 optionalDependencies: rollup: 4.60.2 @@ -15220,6 +15253,10 @@ snapshots: optionalDependencies: picomatch: 4.0.4 + fdir@6.5.0(picomatch@4.0.7): + optionalDependencies: + picomatch: 4.0.7 + fetch-blob@3.2.0: dependencies: node-domexception: 1.0.0 @@ -15943,6 +15980,8 @@ snapshots: dependencies: ms: 2.1.3 + husky@9.1.7: {} + iconv-lite@0.4.24: dependencies: safer-buffer: 2.1.2 @@ -16949,6 +16988,14 @@ snapshots: lines-and-columns@1.2.4: {} + lint-staged@17.6.0: + dependencies: + picomatch: 4.0.7 + string-argv: 0.3.2 + tinyexec: 1.3.1 + optionalDependencies: + yaml: 2.9.1 + listr2@3.14.0(enquirer@2.4.1): dependencies: cli-truncate: 2.1.0 @@ -18194,6 +18241,8 @@ snapshots: picomatch@4.0.4: {} + picomatch@4.0.7: {} + pify@2.3.0: {} pinkie-promise@2.0.1: @@ -19558,6 +19607,8 @@ snapshots: - bare-abort-controller - react-native-b4a + string-argv@0.3.2: {} + string-convert@0.2.1: {} string-env-interpolation@1.0.1: {} @@ -19793,10 +19844,12 @@ snapshots: tiny-warning@1.0.3: {} + tinyexec@1.3.1: {} + tinyglobby@0.2.16: dependencies: - fdir: 6.5.0(picomatch@4.0.4) - picomatch: 4.0.4 + fdir: 6.5.0(picomatch@4.0.7) + picomatch: 4.0.7 title-case@3.0.3: dependencies: @@ -20382,6 +20435,9 @@ snapshots: yaml@2.8.4: {} + yaml@2.9.1: + optional: true + yargs-parser@18.1.3: dependencies: camelcase: 5.3.1