Skip to content

Commit

Permalink
Only use buildRef if it exists (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushshah15 authored Nov 25, 2024
1 parent 6587504 commit bdd6696
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

30 changes: 18 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ async function reportBuildCompleted(exportRes?: ExportRecordResponse) {
return;
}

core.warning(`reportBuildCompleted: exportRes: ${JSON.stringify(exportRes, null, 2)}`);

try {
const client = await getBlacksmithAgentClient();
const formData = new FormData();
Expand All @@ -64,15 +62,25 @@ async function reportBuildCompleted(exportRes?: ExportRecordResponse) {
runtime_seconds: stateHelper.dockerBuildDurationSeconds
};

core.debug(`exportRes: ${JSON.stringify(exportRes, null, 2)}`);
core.debug(`stateHelper.buildRef: ${stateHelper.buildRef}`);

if (exportRes && stateHelper.buildRef) {
const buildRefSummary = exportRes.summaries[stateHelper.buildRef];
const cachedRatio = buildRefSummary.numCachedSteps / buildRefSummary.numTotalSteps;
if (exportRes) {
let buildRefSummary;
// Extract just the ref ID from the full buildRef path
const refId = stateHelper.buildRef?.split('/').pop();
core.info(`Using buildRef ID: ${refId}`);
if (refId && exportRes.summaries[refId]) {
buildRefSummary = exportRes.summaries[refId];
} else {
// Take first summary if buildRef not found
const summaryKeys = Object.keys(exportRes.summaries);
if (summaryKeys.length > 0) {
buildRefSummary = exportRes.summaries[summaryKeys[0]];
}
}

requestOptions['docker_build_size'] = exportRes.dockerbuildSize;
requestOptions['cached_steps_ratio'] = cachedRatio;
if (buildRefSummary) {
const cachedRatio = buildRefSummary.numCachedSteps / buildRefSummary.numTotalSteps;
requestOptions['cached_steps_ratio'] = cachedRatio;
}
}

await postWithRetryToBlacksmithAPI(`/stickydisks/dockerbuilds/${stateHelper.blacksmithDockerBuildId}`, requestOptions, retryCondition);
Expand Down Expand Up @@ -752,8 +760,6 @@ actionsToolkit.run(
await new Promise(resolve => setTimeout(resolve, 100));
}
}
core.warning(`stateHelper.dockerBuildStatus: ${stateHelper.dockerBuildStatus}`);
core.warning(`exportRes: ${JSON.stringify(exportRes, null, 2)}`);
if (stateHelper.dockerBuildStatus == 'success') {
await reportBuildCompleted(exportRes);
} else {
Expand Down

0 comments on commit bdd6696

Please sign in to comment.