Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use buildRef if it exists #42

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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