diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5b040de..e75c52cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -44,3 +44,28 @@ jobs: - run: yarn prisma migrate deploy - run: yarn test - run: yarn build + + types: + name: Check types + + strategy: + matrix: + node: ["14.x"] + os: [ubuntu-latest] + runs-on: ${{ matrix.os }} + + steps: + - name: Checkout repo + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Use Node ${{ matrix.node }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Install deps + uses: bahmutov/npm-install@v1 + + - run: yarn check-changed-files diff --git a/package.json b/package.json index 4f1ae066..f54af3ed 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "postinstall": "prisma generate", "pre-commit": "lint-staged", "lint": "eslint . --ext .ts,.js,.tsx,.jsx", - "prepare": "husky install" + "prepare": "husky install", + "check-changed-files": "yarn ts-node scripts/ts-check-changed-files.ts" }, "engines": { "node": "14.x", diff --git a/scripts/ts-check-changed-files.ts b/scripts/ts-check-changed-files.ts new file mode 100644 index 00000000..6612bb50 --- /dev/null +++ b/scripts/ts-check-changed-files.ts @@ -0,0 +1,37 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { execSync } from "child_process"; + +const diff = execSync(`git diff --name-only origin/main HEAD`).toString(); + +const files = diff.trim().split("\n"); + +console.log("ℹī¸ Changed files:"); +console.log( + files + .filter(Boolean) + .map((str) => ` - ${str}`) + .join("\n") +); + +try { + console.log("âŗ Checking type errors.."); + execSync("yarn tsc --noEmit", {}); + + console.log("đŸ˜ģ No errors!"); +} catch (_err) { + const err = _err as any; + + const output = err.stdout.toString() as string; + + const filesWithTypeErrors = files.filter((file) => output.includes(file)); + + if (!filesWithTypeErrors.length) { + console.log(`🎉 You haven't introduced any new type errors!`); + process.exit(0); + } + console.log("❌ ❌ ❌ You seem to have touched files that have type errors ❌ ❌ ❌"); + console.log("🙏 Please inspect the following files:"); + console.log(filesWithTypeErrors.map((str) => ` - ${str}`).join("\n")); + + process.exit(1); +}