Skip to content

Commit

Permalink
fix: Compile each project individually
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akash1810 committed May 2, 2024
1 parent f8f4c60 commit b71fd1d
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 26 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/best-practices/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion packages/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion packages/cloudbuster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
3 changes: 2 additions & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 19 additions & 11 deletions packages/common/src/pull-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | undefined> {
const {
repoName,
title,
body,
branchName,
baseBranch = 'main',
changes,
}: CreatePullRequestOptions,
) {
return await composeCreatePullRequest(octokit, {
} = props;

const data = await composeCreatePullRequest(octokit, {
owner: 'guardian',
repo: repoName,
title,
Expand All @@ -46,6 +52,8 @@ export async function createPullRequest(
files,
})),
});

return data?.data.html_url;
}

type PullRequestParameters =
Expand Down Expand Up @@ -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,
Expand All @@ -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.`,
Expand Down
3 changes: 2 additions & 1 deletion packages/data-audit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/dependency-graph-integrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/dev-environment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion packages/diagrams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion packages/github-actions-usage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion packages/interactive-monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 2 additions & 1 deletion packages/repocop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/snyk-integrator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "@guardian/tsconfig/tsconfig.json",
"compilerOptions": {
"noEmit": true,
"module": "commonjs",
"esModuleInterop": true,
"baseUrl": ".",
Expand Down

0 comments on commit b71fd1d

Please sign in to comment.