From b71fd1dbd26c6707e592ce30bfd7ecad87500a30 Mon Sep 17 00:00:00 2001 From: akash1810 Date: Thu, 2 May 2024 11:40:07 +0100 Subject: [PATCH] fix: Compile each project individually The `common` package has a compile error: ``` TS2742: The inferred type of createPullRequest cannot be named without a reference to `octokit-plugin-create-pull-request/node_modules/@octokit/types`. This is likely not portable. A type annotation is necessary. ``` It looks like compiling at the root isn't granular enough, as the error wasn't reported during builds. This change resolves the compilation error, and updates to compiling each project individually. --- package.json | 3 +- packages/best-practices/package.json | 3 +- packages/cdk/package.json | 3 +- packages/cli/package.json | 3 +- packages/cloudbuster/package.json | 3 +- packages/common/package.json | 3 +- packages/common/src/pull-requests.ts | 30 ++++++++++++------- packages/data-audit/package.json | 3 +- .../dependency-graph-integrator/package.json | 3 +- packages/dev-environment/package.json | 3 +- packages/diagrams/package.json | 3 +- packages/github-actions-usage/package.json | 3 +- packages/interactive-monitor/package.json | 3 +- packages/repocop/package.json | 3 +- packages/snyk-integrator/package.json | 3 +- tsconfig.json | 1 - 16 files changed, 47 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 17a664c3b..bdb5b2fca 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "test": "npm run test --workspaces --if-present", "test-update": "jest -u", "synth": "npm run synth --workspace=cdk", - "typecheck": "tsc", + "pretypecheck": "npm -w common run typecheck", + "typecheck": "npm run typecheck --workspaces", "build": "npm run build --workspaces --if-present", "lint": "eslint packages/** --ext .ts --no-error-on-unmatched-pattern" }, diff --git a/packages/best-practices/package.json b/packages/best-practices/package.json index aa3e73955..b10955bb3 100644 --- a/packages/best-practices/package.json +++ b/packages/best-practices/package.json @@ -4,7 +4,8 @@ "description": "A markdown file of best practices generated by a script from a definitions file", "type": "module", "scripts": { - "generate": "tsx src/index.ts" + "generate": "tsx src/index.ts", + "typecheck": "tsc --noEmit" }, "devDependencies": { "markdown-table": "^3.0.3" diff --git a/packages/cdk/package.json b/packages/cdk/package.json index 04f0b9972..62d808cdf 100644 --- a/packages/cdk/package.json +++ b/packages/cdk/package.json @@ -4,7 +4,8 @@ "scripts": { "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects cdk", "synth": "cdk synth --path-metadata false --version-reporting false", - "diff:code": "cdk diff --path-metadata false --version-reporting false --profile deployTools ServiceCatalogue-CODE" + "diff:code": "cdk diff --path-metadata false --version-reporting false --profile deployTools ServiceCatalogue-CODE", + "typecheck": "tsc --noEmit" }, "devDependencies": { "@guardian/cdk": "57.0.0", diff --git a/packages/cli/package.json b/packages/cli/package.json index d79ca6732..94570bce9 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -2,7 +2,8 @@ "name": "cli", "version": "0.0.0", "scripts": { - "start": "tsx src/index.ts" + "start": "tsx src/index.ts", + "typecheck": "tsc --noEmit" }, "type": "module", "devDependencies": { diff --git a/packages/cloudbuster/package.json b/packages/cloudbuster/package.json index 524c39751..fc3753671 100644 --- a/packages/cloudbuster/package.json +++ b/packages/cloudbuster/package.json @@ -2,6 +2,7 @@ "name": "cloudbuster", "version": "1.0.0", "scripts": { - "start": "APP=cloudbuster tsx src/run-locally.ts" + "start": "APP=cloudbuster tsx src/run-locally.ts", + "typecheck": "tsc --noEmit" } } diff --git a/packages/common/package.json b/packages/common/package.json index 0a1dd236a..c4d3231c6 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -4,7 +4,8 @@ "type": "module", "scripts": { "postinstall": "prisma generate", - "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects common" + "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects common", + "typecheck": "tsc" }, "dependencies": { "@aws-sdk/client-secrets-manager": "^3.565.0", diff --git a/packages/common/src/pull-requests.ts b/packages/common/src/pull-requests.ts index b1a755a7b..86623160c 100644 --- a/packages/common/src/pull-requests.ts +++ b/packages/common/src/pull-requests.ts @@ -23,18 +23,24 @@ export function generateBranchName(prefix: string) { return `${prefix}-${randomBytes(8).toString('hex')}`; } +/** + * Creates or updates a pull request, and return its URL. + * On error, an exception is thrown, or undefined is returned. + */ export async function createPullRequest( octokit: Octokit, - { + props: CreatePullRequestOptions, +): Promise { + const { repoName, title, body, branchName, baseBranch = 'main', changes, - }: CreatePullRequestOptions, -) { - return await composeCreatePullRequest(octokit, { + } = props; + + const data = await composeCreatePullRequest(octokit, { owner: 'guardian', repo: repoName, title, @@ -46,6 +52,8 @@ export async function createPullRequest( files, })), }); + + return data?.data.html_url; } type PullRequestParameters = @@ -99,7 +107,7 @@ export async function createPrAndAddToProject( ); if (!existingPullRequest) { - const response = await createPullRequest(octokit, { + const pullRequestUrl = await createPullRequest(octokit, { repoName, title: prTitle, body: prBody, @@ -113,12 +121,12 @@ export async function createPrAndAddToProject( }, ], }); - console.log( - 'Pull request successfully created:', - response?.data.html_url, - ); - await addPrToProject(stage, repoName, boardNumber, author); - console.log('Updated project board'); + + if (pullRequestUrl) { + console.log('Pull request successfully created:', pullRequestUrl); + await addPrToProject(stage, repoName, boardNumber, author); + console.log('Updated project board'); + } } else { console.log( `Existing pull request found. Skipping creating a new one.`, diff --git a/packages/data-audit/package.json b/packages/data-audit/package.json index 365c6752c..42d960ba7 100644 --- a/packages/data-audit/package.json +++ b/packages/data-audit/package.json @@ -6,7 +6,8 @@ "test": "echo \"Error: no test specified\"", "start": "APP=data-audit tsx src/run-locally.ts", "prebuild": "rm -rf dist", - "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@aws-sdk --external:@prisma/client --external:prisma" + "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@aws-sdk --external:@prisma/client --external:prisma", + "typecheck": "tsc --noEmit" }, "dependencies": { "@aws-sdk/client-lambda": "^3.565.0", diff --git a/packages/dependency-graph-integrator/package.json b/packages/dependency-graph-integrator/package.json index 7af0e8833..2bfebd6e4 100644 --- a/packages/dependency-graph-integrator/package.json +++ b/packages/dependency-graph-integrator/package.json @@ -7,7 +7,8 @@ "scripts": { "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@aws-sdk", "start": "tsx src/run-locally.ts", - "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects dependency-graph-integrator" + "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects dependency-graph-integrator", + "typecheck": "tsc --noEmit" }, "dependencies": { "@aws-sdk/client-sns": "^3.565.0", diff --git a/packages/dev-environment/package.json b/packages/dev-environment/package.json index 8452fdcc2..e09b38f5e 100644 --- a/packages/dev-environment/package.json +++ b/packages/dev-environment/package.json @@ -3,7 +3,8 @@ "version": "0.0.0", "scripts": { "start": "./script/start", - "test": "find . | egrep '.yml|.yaml' | xargs yamllint" + "test": "find . | egrep '.yml|.yaml' | xargs yamllint", + "typecheck": "echo 'Nothing to typecheck'" }, "devDependencies": { "yaml-lint": "^1.7.0" diff --git a/packages/diagrams/package.json b/packages/diagrams/package.json index 42ef80e62..76641ea2f 100644 --- a/packages/diagrams/package.json +++ b/packages/diagrams/package.json @@ -4,7 +4,8 @@ "description": "Diagrams as code", "type": "module", "scripts": { - "generate": "mmdc -i diagram.mmd -o output.svg " + "generate": "mmdc -i diagram.mmd -o output.svg ", + "typecheck": "echo 'Nothing to typecheck'" }, "devDependencies": { "@mermaid-js/mermaid-cli": "10.8.0" diff --git a/packages/github-actions-usage/package.json b/packages/github-actions-usage/package.json index 7d66673b6..f8ef2cf56 100644 --- a/packages/github-actions-usage/package.json +++ b/packages/github-actions-usage/package.json @@ -5,7 +5,8 @@ "test": "node --import tsx --test **/*.test.ts", "start": "APP=github-actions-usage tsx src/run-locally.ts", "prebuild": "rm -rf dist", - "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@prisma/client --external:prisma" + "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@prisma/client --external:prisma", + "typecheck": "tsc --noEmit" }, "type": "module", "dependencies": { diff --git a/packages/interactive-monitor/package.json b/packages/interactive-monitor/package.json index 7566e14c9..ee9ea4e18 100644 --- a/packages/interactive-monitor/package.json +++ b/packages/interactive-monitor/package.json @@ -6,7 +6,8 @@ "scripts": { "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@aws-sdk", "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects interactive-monitor", - "start": "tsx src/run-locally.ts" + "start": "tsx src/run-locally.ts", + "typecheck": "tsc --noEmit" }, "author": "guardian", "dependencies": { diff --git a/packages/repocop/package.json b/packages/repocop/package.json index fa9b5c07e..897db9222 100644 --- a/packages/repocop/package.json +++ b/packages/repocop/package.json @@ -8,7 +8,8 @@ "scripts": { "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@aws-sdk --external:@prisma/client --external:prisma", "start": "APP=repocop tsx src/run-locally.ts", - "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects repocop" + "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects repocop", + "typecheck": "tsc --noEmit" }, "dependencies": { "@aws-sdk/client-cloudwatch": "^3.565.0", diff --git a/packages/snyk-integrator/package.json b/packages/snyk-integrator/package.json index 4801a27b6..57b9c4847 100644 --- a/packages/snyk-integrator/package.json +++ b/packages/snyk-integrator/package.json @@ -7,7 +7,8 @@ "scripts": { "build": "esbuild src/index.ts --bundle --platform=node --target=node20 --outdir=dist --external:@aws-sdk", "start": "APP=snyk-integrator tsx src/run-locally.ts", - "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects snyk-integrator" + "test": "jest --detectOpenHandles --config ../../jest.config.js --selectProjects snyk-integrator", + "typecheck": "tsc --noEmit" }, "dependencies": { "@aws-sdk/client-sns": "^3.565.0", diff --git a/tsconfig.json b/tsconfig.json index 044e12101..7ddfa73a6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,6 @@ { "extends": "@guardian/tsconfig/tsconfig.json", "compilerOptions": { - "noEmit": true, "module": "commonjs", "esModuleInterop": true, "baseUrl": ".",