Skip to content

Commit

Permalink
Fix azure-sdk, consider stderr when processing errors (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey authored Mar 18, 2024
1 parent 3b3b4da commit 21609ac
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type RepoStatus =
| "Language service disabled in new TS"
| "Detected interesting changes"
| "Detected no interesting changes"
| "Timeout"
;

interface TSServerResult {
Expand Down Expand Up @@ -680,6 +681,9 @@ export async function getTscRepoResult(
}
catch (err) {
reportError(err, `Error building ${repo.url ?? repo.name}`);
if (err instanceof ge.TimeoutError) {
return { status: "Timeout" };
}
return { status: "Unknown failure" };
}
finally {
Expand Down
18 changes: 15 additions & 3 deletions src/utils/getTscErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ export async function buildAndGetErrors(repoDir: string, monorepoPackages: reado
const buildScriptPath = path.join(repoDir, "build.sh");
if (fs.existsSync(buildScriptPath)) {

const before = performance.now();
const spawnResult = await spawnWithTimeoutAsync(repoDir, path.resolve(buildScriptPath), [], timeoutMs, { ...process.env, TS: tsRepoPath });
if (!spawnResult) {
throw new Error(`build.sh timed out after ${timeoutMs} ms`);
throw new TimeoutError(`build.sh timed out after ${timeoutMs} ms`);
}
console.log(`${buildScriptPath} took ${Math.round(performance.now() - before)} ms`);

const { isEmpty, stdout, hasBuildFailure } = getBuildSummary(spawnResult);
const { isEmpty, stdout, hasBuildFailure } = getBuildSummary(spawnResult, /*mergeOutputs*/ true);

if (!isEmpty) {
projectErrors.push(await getProjectErrors(buildScriptPath, tsRepoPath, stdout, hasBuildFailure, /*isComposite*/ false, /*reportGithubLinks*/ false));
Expand Down Expand Up @@ -209,10 +211,20 @@ function getLocalErrorFromLine(line: string, projectUrl: string): LocalError | u
return undefined;
}

function getBuildSummary({ code, signal, stderr, stdout }: SpawnResult) {
function getBuildSummary({ code, signal, stderr, stdout }: SpawnResult, mergeOutputs?: boolean) {
if (mergeOutputs) {
stdout = stdout + "\n" + stderr;
}

return {
stdout,
hasBuildFailure: !!(code || signal || (stderr && stderr.length && !stderr.match(/debugger/i))), // --inspect prints the debug port to stderr
isEmpty: !!stdout.match(/TS18003/)
};
}

export class TimeoutError extends Error {
constructor(message: string) {
super(message);
}
}
32 changes: 28 additions & 4 deletions userTests/azure-sdk/build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
set -x
npm install -g @microsoft/rush
rm -rf azure-sdk
git clone --depth 1 https://github.com/Azure/azure-sdk-for-js.git azure-sdk
cd azure-sdk
START=$(pwd)
rush update
cd sdk/core/core-http
cd sdk/core/core-util
# Sync up all TS versions used internally so they're all linked from a known location
rush add -p "typescript@3.5.1" --dev -m
LOCAL_TS=$(node -e 'console.log(JSON.parse(fs.readFileSync("node_modules/typescript/package.json", "utf8")).version)')
rush add -p "typescript@$LOCAL_TS" --dev -m
# -nervous laugh-
# Relink installed TSes to built TS
cd $START/common/temp/node_modules/.pnpm/typescript@3.5.1/node_modules
cd $START/common/temp/node_modules/.pnpm/typescript@$LOCAL_TS/node_modules
rm -rf typescript
ln -s $TS ./typescript
cd $START
rush rebuild --parallelism 1

# Running everything takes a long time; just build the top 20 client packages by downloads.
rush rebuild \
--to @azure/identity \
--to @azure/storage-blob \
--to @azure/keyvault-keys \
--to @azure/opentelemetry-instrumentation-azure-sdk \
--to @azure/cosmos \
--to @azure/keyvault-secrets \
--to @azure/service-bus \
--to @azure/openai \
--to @azure/app-configuration \
--to @azure/storage-queue \
--to @azure/storage-file-share \
--to @azure/event-hubs \
--to @azure/communication-common \
--to @azure/data-tables \
--to @azure/storage-file-datalake \
--to @azure/search-documents \
--to @azure/web-pubsub-client \
--to @azure/maps-common \
--to @azure/ai-form-recognizer \
--to @azure/communication-email
2 changes: 1 addition & 1 deletion userTests/typescript-eslint/build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set -x

command -v yarn &> /dev/null || npm i -g yarn
npm i -g yarn
rm -rf typescript-eslint
git clone --depth 1 https://github.com/typescript-eslint/typescript-eslint.git typescript-eslint
cd typescript-eslint
Expand Down

0 comments on commit 21609ac

Please sign in to comment.