Skip to content

Commit 8aa08e1

Browse files
committed
fix: improve error handling
1 parent debb0e5 commit 8aa08e1

5 files changed

Lines changed: 124 additions & 128 deletions

File tree

dist/index.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/prepare.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
import * as core from "@actions/core";
22
import {exec} from "@actions/exec";
33

4-
const prepare = async (): Promise<void> =>
5-
core.group("Prepare environment", async () => {
4+
const prepare = async (): Promise<void> => {
5+
core.startGroup("Prepare environment");
6+
try {
7+
await exec("sudo apt-get install -y valgrind", [], {
8+
silent: true,
9+
});
610
try {
7-
await exec("sudo apt-get install -y valgrind", [], {
11+
await exec("pip show pytest-codspeed", [], {
12+
silent: true,
13+
});
14+
} catch (e) {
15+
core.warning(
16+
"pytest-codspeed is not installed in your environment. Installing it..."
17+
);
18+
await exec("pip install pytest-codspeed", [], {
819
silent: true,
920
});
10-
try {
11-
await exec("pip show pytest-codspeed", [], {
12-
silent: true,
13-
});
14-
} catch (e) {
15-
core.warning(
16-
"pytest-codspeed is not installed in your environment. Installing it..."
17-
);
18-
await exec("pip install pytest-codspeed", [], {
19-
silent: true,
20-
});
21-
}
22-
} catch (error) {
23-
throw new Error(`Failed to prepare environment: ${error}`);
2421
}
25-
core.info("Environment ready");
26-
});
22+
} catch (error) {
23+
throw new Error(`Failed to prepare environment: ${error}`);
24+
}
25+
core.info("Environment ready");
26+
core.endGroup();
27+
};
2728

2829
export default prepare;

src/run.ts

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,54 +40,49 @@ const outputListener = (line: string): void => {
4040
}
4141
};
4242

43-
const run = async (inputs: ActionInputs): Promise<{profilePath: string}> =>
44-
core.group("Run benchmarks", async () => {
45-
const arch = await getArch();
46-
const profilePath = getTempFile();
47-
const valgrindOptions = [
48-
"-q",
49-
"--tool=callgrind",
50-
"--cache-sim=yes",
51-
"--I1=32768,8,64",
52-
"--D1=32768,8,64",
53-
"--LL=8388608,16,64",
54-
"--instr-atstart=no",
55-
"--compress-strings=no",
56-
"--combine-dumps=yes",
57-
"--dump-line=no",
58-
`--callgrind-out-file=${profilePath}`,
59-
];
60-
try {
61-
await exec(
62-
[
63-
"setarch",
64-
arch,
65-
"-R",
66-
"valgrind",
67-
...valgrindOptions,
68-
inputs.run,
69-
].join(" "),
70-
[],
71-
{
72-
env: {
73-
...process.env,
74-
PYTHONMALLOC: "malloc",
75-
PYTHONHASHSEED: "0",
76-
ARCH: arch,
77-
CODSPEED_ENV: "github",
78-
},
79-
silent: true,
80-
listeners: {
81-
stdline: outputListener,
82-
errline: outputListener,
83-
},
84-
}
85-
);
86-
} catch (error) {
87-
core.debug(`Error: ${error}`);
88-
throw new Error("Failed to run benchmarks");
89-
}
90-
return {profilePath};
91-
});
92-
43+
const run = async (inputs: ActionInputs): Promise<{profilePath: string}> => {
44+
core.startGroup("Run benchmarks");
45+
const arch = await getArch();
46+
const profilePath = getTempFile();
47+
const valgrindOptions = [
48+
"-q",
49+
"--tool=callgrind",
50+
"--cache-sim=yes",
51+
"--I1=32768,8,64",
52+
"--D1=32768,8,64",
53+
"--LL=8388608,16,64",
54+
"--instr-atstart=no",
55+
"--compress-strings=no",
56+
"--combine-dumps=yes",
57+
"--dump-line=no",
58+
`--callgrind-out-file=${profilePath}`,
59+
];
60+
try {
61+
await exec(
62+
["setarch", arch, "-R", "valgrind", ...valgrindOptions, inputs.run].join(
63+
" "
64+
),
65+
[],
66+
{
67+
env: {
68+
...process.env,
69+
PYTHONMALLOC: "malloc",
70+
PYTHONHASHSEED: "0",
71+
ARCH: arch,
72+
CODSPEED_ENV: "github",
73+
},
74+
silent: true,
75+
listeners: {
76+
stdline: outputListener,
77+
errline: outputListener,
78+
},
79+
}
80+
);
81+
} catch (error) {
82+
core.debug(`Error: ${error}`);
83+
throw new Error("Failed to run benchmarks");
84+
}
85+
core.endGroup();
86+
return {profilePath};
87+
};
9388
export default run;

src/upload.ts

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -43,61 +43,61 @@ const upload = async (
4343
inputs: ActionInputs,
4444
profilePath: string
4545
): Promise<void> => {
46-
core.group("Upload Results", async () => {
47-
const uploadMetadata = await getUploadMetadata({profilePath, inputs});
48-
core.debug("Upload metadata:");
49-
core.debug(JSON.stringify(uploadMetadata, null, 2));
50-
const hash = crypto
51-
.createHash("sha256")
52-
.update(JSON.stringify(uploadMetadata))
53-
.digest("hex");
54-
if (inputs.tokenless) {
55-
core.info(`CodSpeed Run Hash: "${hash}"`);
56-
}
46+
core.startGroup("Upload Results");
47+
const uploadMetadata = await getUploadMetadata({profilePath, inputs});
48+
core.debug("Upload metadata:");
49+
core.debug(JSON.stringify(uploadMetadata, null, 2));
50+
const hash = crypto
51+
.createHash("sha256")
52+
.update(JSON.stringify(uploadMetadata))
53+
.digest("hex");
54+
if (inputs.tokenless) {
55+
core.info(`CodSpeed Run Hash: "${hash}"`);
56+
}
5757

58-
core.info("Preparing upload");
59-
let response: TypedResponse<PostResponse>;
60-
try {
61-
const headers = inputs.tokenless
62-
? undefined
63-
: {
64-
Authorization: inputs.token,
65-
};
66-
response = await http.postJson<PostResponse>(
67-
inputs.uploadUrl,
68-
uploadMetadata,
69-
headers
70-
);
71-
} catch (e) {
72-
const err = e as httpm.HttpClientError;
73-
throw new Error(
74-
`Upload preparation failed (${err.statusCode}): ${err.message}`
75-
);
76-
}
77-
if (!response.result) {
78-
throw new Error("Upload preparation failed: no result");
79-
}
80-
core.info("Uploading profile data");
81-
const profile = fs.readFileSync(profilePath);
82-
core.debug(`Uploading ${profile.length} bytes...`);
83-
const uploadResponse = await http.request(
84-
"PUT",
85-
response.result.uploadUrl,
86-
Readable.from(profile),
87-
{
88-
"Content-Type": "application/octet-stream",
89-
"Content-Length": profile.length,
90-
"Content-MD5": uploadMetadata.profileMd5,
91-
}
58+
core.info("Preparing upload");
59+
let response: TypedResponse<PostResponse>;
60+
try {
61+
const headers = inputs.tokenless
62+
? undefined
63+
: {
64+
Authorization: inputs.token,
65+
};
66+
response = await http.postJson<PostResponse>(
67+
inputs.uploadUrl,
68+
uploadMetadata,
69+
headers
9270
);
93-
if (uploadResponse.message.statusCode !== 200) {
94-
throw new Error(
95-
`Upload failed with status ${uploadResponse.message.statusCode}: ${uploadResponse.message.statusMessage}`
96-
);
71+
} catch (e) {
72+
const err = e as httpm.HttpClientError;
73+
throw new Error(
74+
`Upload preparation failed (${err.statusCode}): ${err.message}`
75+
);
76+
}
77+
if (!response.result) {
78+
throw new Error("Upload preparation failed: no result");
79+
}
80+
core.info("Uploading profile data...");
81+
const profile = fs.readFileSync(profilePath);
82+
core.debug(`Uploading ${profile.length} bytes...`);
83+
const uploadResponse = await http.request(
84+
"PUT",
85+
response.result.uploadUrl,
86+
Readable.from(profile),
87+
{
88+
"Content-Type": "application/octet-stream",
89+
"Content-Length": profile.length,
90+
"Content-MD5": uploadMetadata.profileMd5,
9791
}
92+
);
93+
if (uploadResponse.message.statusCode !== 200) {
94+
throw new Error(
95+
`Upload failed with status ${uploadResponse.message.statusCode}: ${uploadResponse.message.statusMessage}`
96+
);
97+
}
9898

99-
core.info("Results uploaded.");
100-
});
99+
core.info("Results uploaded.");
100+
core.endGroup();
101101
};
102102

103103
export default upload;

0 commit comments

Comments
 (0)