mirror of
https://github.com/docker/build-push-action.git
synced 2025-08-09 18:12:12 +00:00
refactor: only report metrics when using Blacksmith builder
- Rename reportBuildMetrics to reportBuildStart for clarity - Check if builder name contains 'blacksmith' before reporting - Log warning when not using a Blacksmith builder - Skip build start and completion reporting for non-Blacksmith builders - Update tests to reflect function rename 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
99fce0de47
commit
61dd93325b
2
dist/index.js
generated
vendored
2
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -28,7 +28,7 @@ jest.mock('../reporter', () => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('reportBuildMetrics', () => {
|
describe('reportBuildStart', () => {
|
||||||
let mockInputs;
|
let mockInputs;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@ -42,7 +42,7 @@ describe('reportBuildMetrics', () => {
|
|||||||
test('should handle missing dockerfile path', async () => {
|
test('should handle missing dockerfile path', async () => {
|
||||||
(getDockerfilePath as jest.Mock).mockReturnValue(null);
|
(getDockerfilePath as jest.Mock).mockReturnValue(null);
|
||||||
|
|
||||||
const result = await main.reportBuildMetrics(mockInputs);
|
const result = await main.reportBuildStart(mockInputs);
|
||||||
|
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error when reporting build metrics: Failed to resolve dockerfile path');
|
expect(core.warning).toHaveBeenCalledWith('Error when reporting build metrics: Failed to resolve dockerfile path');
|
||||||
@ -54,7 +54,7 @@ describe('reportBuildMetrics', () => {
|
|||||||
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
||||||
(reporter.reportBuild as jest.Mock).mockResolvedValue({docker_build_id: mockBuildId});
|
(reporter.reportBuild as jest.Mock).mockResolvedValue({docker_build_id: mockBuildId});
|
||||||
|
|
||||||
const result = await main.reportBuildMetrics(mockInputs);
|
const result = await main.reportBuildStart(mockInputs);
|
||||||
|
|
||||||
expect(result).toBe(mockBuildId);
|
expect(result).toBe(mockBuildId);
|
||||||
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
|
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
|
||||||
@ -65,7 +65,7 @@ describe('reportBuildMetrics', () => {
|
|||||||
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
||||||
(reporter.reportBuild as jest.Mock).mockResolvedValue(null);
|
(reporter.reportBuild as jest.Mock).mockResolvedValue(null);
|
||||||
|
|
||||||
const result = await main.reportBuildMetrics(mockInputs);
|
const result = await main.reportBuildStart(mockInputs);
|
||||||
|
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
|
expect(reporter.reportBuild).toHaveBeenCalledWith('/path/to/Dockerfile');
|
||||||
@ -76,7 +76,7 @@ describe('reportBuildMetrics', () => {
|
|||||||
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
(getDockerfilePath as jest.Mock).mockReturnValue('/path/to/Dockerfile');
|
||||||
(reporter.reportBuild as jest.Mock).mockRejectedValue(new Error('API error'));
|
(reporter.reportBuild as jest.Mock).mockRejectedValue(new Error('API error'));
|
||||||
|
|
||||||
const result = await main.reportBuildMetrics(mockInputs);
|
const result = await main.reportBuildStart(mockInputs);
|
||||||
|
|
||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error reporting build start: API error');
|
expect(core.warning).toHaveBeenCalledWith('Error reporting build start: API error');
|
||||||
|
27
src/main.ts
27
src/main.ts
@ -34,7 +34,7 @@ async function assertBuildxAvailable(toolkit: Toolkit): Promise<void> {
|
|||||||
* @param inputs - Configuration inputs
|
* @param inputs - Configuration inputs
|
||||||
* @returns {string|null} buildId - ID used to track build progress and report metrics
|
* @returns {string|null} buildId - ID used to track build progress and report metrics
|
||||||
*/
|
*/
|
||||||
export async function reportBuildMetrics(inputs: context.Inputs): Promise<string | null> {
|
export async function reportBuildStart(inputs: context.Inputs): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
// Get the dockerfile path to report the build to our control plane.
|
// Get the dockerfile path to report the build to our control plane.
|
||||||
const dockerfilePath = context.getDockerfilePath(inputs);
|
const dockerfilePath = context.getDockerfilePath(inputs);
|
||||||
@ -91,17 +91,21 @@ actionsToolkit.run(
|
|||||||
let buildError: Error | undefined;
|
let buildError: Error | undefined;
|
||||||
let buildDurationSeconds: string | undefined;
|
let buildDurationSeconds: string | undefined;
|
||||||
let ref: string | undefined;
|
let ref: string | undefined;
|
||||||
try {
|
let isBlacksmithBuilder = false;
|
||||||
await core.group(`Setting up build metrics tracking`, async () => {
|
|
||||||
buildId = await reportBuildMetrics(inputs);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
try {
|
||||||
// Check that a builder is available (either from setup-docker-builder or existing)
|
// Check that a builder is available (either from setup-docker-builder or existing)
|
||||||
|
let builder: BuilderInfo;
|
||||||
await core.group(`Checking for configured builder`, async () => {
|
await core.group(`Checking for configured builder`, async () => {
|
||||||
try {
|
try {
|
||||||
const builder = await toolkit.builder.inspect();
|
builder = await toolkit.builder.inspect();
|
||||||
if (builder) {
|
if (builder) {
|
||||||
core.info(`Found configured builder: ${builder.name}`);
|
core.info(`Found configured builder: ${builder.name}`);
|
||||||
|
// Check if this is a Blacksmith builder
|
||||||
|
isBlacksmithBuilder = builder.name ? builder.name.toLowerCase().includes('blacksmith') : false;
|
||||||
|
if (!isBlacksmithBuilder) {
|
||||||
|
core.warning(`Not using a Blacksmith builder (current builder: ${builder.name || 'unknown'}). Build metrics will not be reported.`);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(`No Docker builder found. Please use setup-docker-builder action or configure a builder before using build-push-action.`);
|
core.setFailed(`No Docker builder found. Please use setup-docker-builder action or configure a builder before using build-push-action.`);
|
||||||
}
|
}
|
||||||
@ -110,9 +114,14 @@ actionsToolkit.run(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let builder: BuilderInfo;
|
// Only report build start if using a Blacksmith builder
|
||||||
|
if (isBlacksmithBuilder) {
|
||||||
|
await core.group(`Setting up build metrics tracking`, async () => {
|
||||||
|
buildId = await reportBuildStart(inputs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await core.group(`Builder info`, async () => {
|
await core.group(`Builder info`, async () => {
|
||||||
builder = await toolkit.builder.inspect();
|
|
||||||
core.info(JSON.stringify(builder, null, 2));
|
core.info(JSON.stringify(builder, null, 2));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -244,7 +253,7 @@ actionsToolkit.run(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buildId) {
|
if (buildId && isBlacksmithBuilder) {
|
||||||
if (!buildError) {
|
if (!buildError) {
|
||||||
await reporter.reportBuildCompleted(exportRes, buildId, ref, buildDurationSeconds);
|
await reporter.reportBuildCompleted(exportRes, buildId, ref, buildDurationSeconds);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user