From a67813ee773ae2b81eda62b431caa775eb4e5f64 Mon Sep 17 00:00:00 2001 From: Alex Johansson Date: Sat, 16 Oct 2021 11:57:21 +0200 Subject: [PATCH] if you touch it you fix it (#967) * wip * add another * check * add ci job * fix ci * fix * maybe * maybs * attempt * test * maybe * another attempt * try v2 * align with normal build * this should break build * Revert "this should break build" This reverts commit 1ba44d18a1d8737aa6232db2d9b9081e892e6ca2. * tweaks * prevent breaking on main Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .github/workflows/build.yml | 25 +++++++++++++++++++++ package.json | 3 ++- scripts/ts-check-changed-files.ts | 37 +++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 scripts/ts-check-changed-files.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5b040de22..e75c52cf70 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 4f1ae066f6..f54af3edb5 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 0000000000..6612bb503d --- /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); +}