Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(github): add check to validate exported types being correct #3561

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"approveformyorg",
"askar",
"Askar",
"attw",
"Authz",
"authzn",
"AWSSM",
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,12 @@ jobs:
path: ./.yarn/
restore-keys: |
${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }}
- name: Installing AreTheTypesWrong Library
run: npm i -g @arethetypeswrong/cli
- run: ./tools/ci.sh
- run: yarn lerna exec 'npm pack'
- name: Running AreTheTypesWrong scan
run: yarn run are-the-types-wrong
yarn_tools_validate_bundle_names:
continue-on-error: false
env:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"format:prettier": "prettier --write --config .prettierrc.js \"./**/{openapi.json,*.ts,*.js}\"",
"spellcheck": "cspell lint --no-progress \"*/*/src/**/*.{js,ts}\"",
"tsc": "NODE_OPTIONS=\"--max_old_space_size=3072\" tsc --build --verbose",
"are-the-types-wrong": "TS_NODE_PROJECT=./tools/tsconfig.json node --trace-deprecation --experimental-modules --abort-on-uncaught-exception --loader ts-node/esm --experimental-specifier-resolution=node ./tools/custom-checks/run-attw-on-tgz.ts",
"codegen": "run-s 'codegen:warmup-*' codegen:lerna codegen:cleanup",
"codegen:cleanup": "rm --force --verbose ./openapitools.json",
"codegen:lerna": "lerna run codegen",
Expand Down
49 changes: 49 additions & 0 deletions tools/custom-checks/get-all-tgz-path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import path from "path";
outSH marked this conversation as resolved.
Show resolved Hide resolved
import { fileURLToPath } from "url";
import { globby, Options as GlobbyOptions } from "globby";
import lernaCfg from "../../lerna.json" assert { type: "json" };

/**
* Interface for the response of the getAllTgzPath function.
* @property {Array<string>} relativePaths - An array of relative paths to the
* package directories.
*/

export interface IGetAllTgzPathResponse {
readonly relativePaths: Readonly<Array<string>>;
}

/**
* Asynchronous function to get all tgz filepaths in a Lerna monorepo.
* @returns {Promise<IGetAllTgzPathResponse>} A promise that resolves to an
* object containing the arrays of relative paths to the all tgz files.
*/

export async function getAllTgzPath(): Promise<IGetAllTgzPathResponse> {
const TAG = "[tools/get-all-tgz-path.ts]";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const SCRIPT_DIR = __dirname;
const PROJECT_DIR = path.join(SCRIPT_DIR, "../../");

console.log(`${TAG} SCRIPT_DIR=${SCRIPT_DIR}`);
console.log(`${TAG} PROJECT_DIR=${PROJECT_DIR}`);

const globbyOpts: GlobbyOptions = {
cwd: PROJECT_DIR,
onlyFiles: true,
expandDirectories: false,
ignore: ["**/node_modules"],
};

const tgzFilesPattern = lernaCfg.packages.map(
(pkg: string) => `${pkg}/**/hyperledger-*.tgz`,
);

const tgzFilesRelative = await globby(tgzFilesPattern, globbyOpts);
console.log("%s found %s tgz files.", TAG, tgzFilesRelative.length);

return {
relativePaths: tgzFilesRelative,
};
}
47 changes: 47 additions & 0 deletions tools/custom-checks/run-attw-on-tgz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import esMain from "es-main";
import { getAllTgzPath } from "./get-all-tgz-path";
import { exec } from "child_process";
import { exit } from "process";
import { promisify } from "node:util";

const execPromise = promisify(exec);

export async function runAttwOnTgz(): Promise<[boolean, string[]]> {
const TAG = "[tools/custom-checks/run-attw-on-tgz.ts]";
console.log(`${TAG} Fetching .tgz file paths.`);

const { relativePaths: tgzFilesRelative } = await getAllTgzPath();
console.log(`${TAG} Found ${tgzFilesRelative.length} .tgz files.`);

let attwFailedPackages: string[] = [];

for (const filePath of tgzFilesRelative) {
try {
await execCommand("attw", filePath);
} catch {
attwFailedPackages.push(filePath);
}
}

const success = attwFailedPackages.length === 0;
return [success, attwFailedPackages];
}

async function execCommand(
binaryName: string,
filePath: string,
): Promise<void> {
const command = `${binaryName} ./${filePath}`;
const { stdout } = await execPromise(command);
console.log(stdout);
}

if (esMain(import.meta)) {
const attwFailedPackages = await runAttwOnTgz();
if (attwFailedPackages.length > 0) {
outSH marked this conversation as resolved.
Show resolved Hide resolved
console.log("Types are wrong for these packages:");
console.log(attwFailedPackages);
exit(1);
}
exit(0);
}
14 changes: 14 additions & 0 deletions tools/custom-checks/run-custom-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
checkMissingNodeDeps,
} from "./check-missing-node-deps";
import { getAllPkgDirs } from "./get-all-pkg-dirs";
import { getAllTgzPath, IGetAllTgzPathResponse } from "./get-all-tgz-path";
import { runAttwOnTgz } from "./run-attw-on-tgz";

export async function runCustomChecks(
argv: string[],
Expand Down Expand Up @@ -73,6 +75,18 @@
overallSuccess = overallSuccess && success;
}

{
const { relativePaths } = await getAllTgzPath();

const req: IGetAllTgzPathResponse = {

Check failure on line 81 in tools/custom-checks/run-custom-checks.ts

View workflow job for this annotation

GitHub Actions / yarn_lint

'req' is assigned a value but never used
relativePaths,
};

const [success, errors] = await runAttwOnTgz();
overallErrors = overallErrors.concat(errors);
overallSuccess = overallSuccess && success;
}

if (!overallSuccess) {
overallErrors.forEach((it) => console.error(it));
} else {
Expand Down
Loading