src: alert if an exception is thrown on cleanup
This commit is contained in:
parent
1cc1561946
commit
f06a558c36
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -21,7 +21,7 @@ jest.mock('../context', () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../reporter', () => ({
|
jest.mock('../reporter', () => ({
|
||||||
reportBuilderCreationFailed: jest.fn().mockResolvedValue(undefined)
|
reportBuildPushActionFailure: jest.fn().mockResolvedValue(undefined)
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock('../setup_builder', () => ({
|
jest.mock('../setup_builder', () => ({
|
||||||
|
@ -46,7 +46,7 @@ describe('startBlacksmithBuilder', () => {
|
||||||
|
|
||||||
expect(result).toEqual({addr: null, buildId: null, exposeId: ''});
|
expect(result).toEqual({addr: null, buildId: null, exposeId: ''});
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to resolve dockerfile path. Falling back to a local build.');
|
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to resolve dockerfile path. Falling back to a local build.');
|
||||||
expect(reporter.reportBuilderCreationFailed).toHaveBeenCalledWith(new Error('Failed to resolve dockerfile path'));
|
expect(reporter.reportBuildPushActionFailure).toHaveBeenCalledWith(new Error('Failed to resolve dockerfile path'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle missing dockerfile path with nofallback=true', async () => {
|
test('should handle missing dockerfile path with nofallback=true', async () => {
|
||||||
|
@ -55,7 +55,7 @@ describe('startBlacksmithBuilder', () => {
|
||||||
|
|
||||||
await expect(main.startBlacksmithBuilder(mockInputs)).rejects.toThrow('Failed to resolve dockerfile path');
|
await expect(main.startBlacksmithBuilder(mockInputs)).rejects.toThrow('Failed to resolve dockerfile path');
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to resolve dockerfile path. Failing the build because nofallback is set.');
|
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to resolve dockerfile path. Failing the build because nofallback is set.');
|
||||||
expect(reporter.reportBuilderCreationFailed).toHaveBeenCalledWith(new Error('Failed to resolve dockerfile path'));
|
expect(reporter.reportBuildPushActionFailure).toHaveBeenCalledWith(new Error('Failed to resolve dockerfile path'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle error in setupStickyDisk with nofallback=false', async () => {
|
test('should handle error in setupStickyDisk with nofallback=false', async () => {
|
||||||
|
@ -67,7 +67,7 @@ describe('startBlacksmithBuilder', () => {
|
||||||
|
|
||||||
expect(result).toEqual({addr: null, buildId: null, exposeId: ''});
|
expect(result).toEqual({addr: null, buildId: null, exposeId: ''});
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to obtain Blacksmith builder. Falling back to a local build.');
|
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to obtain Blacksmith builder. Falling back to a local build.');
|
||||||
expect(reporter.reportBuilderCreationFailed).toHaveBeenCalledWith(new Error('Failed to obtain Blacksmith builder'));
|
expect(reporter.reportBuildPushActionFailure).toHaveBeenCalledWith(new Error('Failed to obtain Blacksmith builder'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle error in setupStickyDisk with nofallback=true', async () => {
|
test('should handle error in setupStickyDisk with nofallback=true', async () => {
|
||||||
|
@ -78,7 +78,7 @@ describe('startBlacksmithBuilder', () => {
|
||||||
|
|
||||||
await expect(main.startBlacksmithBuilder(mockInputs)).rejects.toThrow(error);
|
await expect(main.startBlacksmithBuilder(mockInputs)).rejects.toThrow(error);
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to obtain Blacksmith builder. Failing the build because nofallback is set.');
|
expect(core.warning).toHaveBeenCalledWith('Error during Blacksmith builder setup: Failed to obtain Blacksmith builder. Failing the build because nofallback is set.');
|
||||||
expect(reporter.reportBuilderCreationFailed).toHaveBeenCalledWith(error);
|
expect(reporter.reportBuildPushActionFailure).toHaveBeenCalledWith(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should successfully start buildkitd when setup succeeds', async () => {
|
test('should successfully start buildkitd when setup succeeds', async () => {
|
||||||
|
@ -106,7 +106,7 @@ describe('startBlacksmithBuilder', () => {
|
||||||
});
|
});
|
||||||
expect(setupBuilder.startAndConfigureBuildkitd).toHaveBeenCalledWith(mockParallelism, mockDevice);
|
expect(setupBuilder.startAndConfigureBuildkitd).toHaveBeenCalledWith(mockParallelism, mockDevice);
|
||||||
expect(core.warning).not.toHaveBeenCalled();
|
expect(core.warning).not.toHaveBeenCalled();
|
||||||
expect(reporter.reportBuilderCreationFailed).not.toHaveBeenCalled();
|
expect(reporter.reportBuildPushActionFailure).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle buildkitd startup failure with nofallback=false', async () => {
|
test('should handle buildkitd startup failure with nofallback=false', async () => {
|
||||||
|
@ -126,7 +126,7 @@ describe('startBlacksmithBuilder', () => {
|
||||||
|
|
||||||
expect(result).toEqual({addr: null, buildId: null, exposeId: ''});
|
expect(result).toEqual({addr: null, buildId: null, exposeId: ''});
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error during buildkitd setup: Failed to start buildkitd. Falling back to a local build.');
|
expect(core.warning).toHaveBeenCalledWith('Error during buildkitd setup: Failed to start buildkitd. Falling back to a local build.');
|
||||||
expect(reporter.reportBuilderCreationFailed).toHaveBeenCalled();
|
expect(reporter.reportBuildPushActionFailure).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should throw error when buildkitd fails and nofallback is true', async () => {
|
test('should throw error when buildkitd fails and nofallback is true', async () => {
|
||||||
|
@ -144,6 +144,6 @@ describe('startBlacksmithBuilder', () => {
|
||||||
mockInputs.nofallback = true;
|
mockInputs.nofallback = true;
|
||||||
await expect(main.startBlacksmithBuilder(mockInputs)).rejects.toThrow('Failed to start buildkitd');
|
await expect(main.startBlacksmithBuilder(mockInputs)).rejects.toThrow('Failed to start buildkitd');
|
||||||
expect(core.warning).toHaveBeenCalledWith('Error during buildkitd setup: Failed to start buildkitd. Failing the build because nofallback is set.');
|
expect(core.warning).toHaveBeenCalledWith('Error during buildkitd setup: Failed to start buildkitd. Failing the build because nofallback is set.');
|
||||||
expect(reporter.reportBuilderCreationFailed).toHaveBeenCalled();
|
expect(reporter.reportBuildPushActionFailure).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -81,7 +81,7 @@ export async function startBlacksmithBuilder(inputs: context.Inputs): Promise<{a
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// If the builder setup fails for any reason, we check if we should fallback to a local build.
|
// If the builder setup fails for any reason, we check if we should fallback to a local build.
|
||||||
// If we should not fallback, we rethrow the error and fail the build.
|
// If we should not fallback, we rethrow the error and fail the build.
|
||||||
await reporter.reportBuilderCreationFailed(error);
|
await reporter.reportBuildPushActionFailure(error);
|
||||||
|
|
||||||
let errorMessage = `Error during Blacksmith builder setup: ${error.message}`;
|
let errorMessage = `Error during Blacksmith builder setup: ${error.message}`;
|
||||||
if (error.message.includes('buildkitd')) {
|
if (error.message.includes('buildkitd')) {
|
||||||
|
@ -346,6 +346,7 @@ actionsToolkit.run(
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.warning(`Error during Blacksmith builder shutdown: ${error.message}`);
|
core.warning(`Error during Blacksmith builder shutdown: ${error.message}`);
|
||||||
|
await reporter.reportBuildPushActionFailure(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,14 +3,15 @@ import axios, {AxiosError, AxiosInstance, AxiosResponse} from 'axios';
|
||||||
import {ExportRecordResponse} from '@docker/actions-toolkit/lib/types/buildx/history';
|
import {ExportRecordResponse} from '@docker/actions-toolkit/lib/types/buildx/history';
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
|
||||||
export async function reportBuilderCreationFailed(error?: Error) {
|
export async function reportBuildPushActionFailure(error?: Error) {
|
||||||
const requestOptions = {
|
const requestOptions = {
|
||||||
stickydisk_key: process.env.GITHUB_REPO_NAME || '',
|
stickydisk_key: process.env.GITHUB_REPO_NAME || '',
|
||||||
repo_name: process.env.GITHUB_REPO_NAME || '',
|
repo_name: process.env.GITHUB_REPO_NAME || '',
|
||||||
region: process.env.BLACKSMITH_REGION || 'eu-central',
|
region: process.env.BLACKSMITH_REGION || 'eu-central',
|
||||||
arch: process.env.BLACKSMITH_ENV?.includes('arm') ? 'arm64' : 'amd64',
|
arch: process.env.BLACKSMITH_ENV?.includes('arm') ? 'arm64' : 'amd64',
|
||||||
vm_id: process.env.VM_ID || '',
|
vm_id: process.env.VM_ID || '',
|
||||||
petname: process.env.PETNAME || ''
|
petname: process.env.PETNAME || '',
|
||||||
|
message: error?.message || ''
|
||||||
};
|
};
|
||||||
const retryCondition = (error: AxiosError) => {
|
const retryCondition = (error: AxiosError) => {
|
||||||
return error.response?.status ? error.response.status > 500 : false;
|
return error.response?.status ? error.response.status > 500 : false;
|
||||||
|
|
Loading…
Reference in New Issue