Skip to content

Add manifest validation and improve error handling #586

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

Merged
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
25 changes: 24 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93423,10 +93423,33 @@ function extractGoArchive(archivePath) {
});
}
exports.extractGoArchive = extractGoArchive;
function isIToolRelease(obj) {
return (typeof obj === 'object' &&
obj !== null &&
typeof obj.version === 'string' &&
typeof obj.stable === 'boolean' &&
Array.isArray(obj.files) &&
obj.files.every((file) => typeof file.filename === 'string' &&
typeof file.platform === 'string' &&
typeof file.arch === 'string' &&
typeof file.download_url === 'string'));
}
function getManifest(auth) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield getManifestFromRepo(auth);
const manifest = yield getManifestFromRepo(auth);
if (Array.isArray(manifest) &&
manifest.length &&
manifest.every(isIToolRelease)) {
return manifest;
}
let errorMessage = 'An unexpected error occurred while fetching the manifest.';
if (typeof manifest === 'object' &&
manifest !== null &&
'message' in manifest) {
errorMessage = manifest.message;
}
throw new Error(errorMessage);
}
catch (err) {
core.debug('Fetching the manifest via the API failed.');
Expand Down
37 changes: 36 additions & 1 deletion src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,46 @@ export async function extractGoArchive(archivePath: string): Promise<string> {
return extPath;
}

function isIToolRelease(obj: any): obj is tc.IToolRelease {
return (
typeof obj === 'object' &&
obj !== null &&
typeof obj.version === 'string' &&
typeof obj.stable === 'boolean' &&
Array.isArray(obj.files) &&
obj.files.every(
(file: any) =>
typeof file.filename === 'string' &&
typeof file.platform === 'string' &&
typeof file.arch === 'string' &&
typeof file.download_url === 'string'
)
);
}

export async function getManifest(
auth: string | undefined
): Promise<tc.IToolRelease[]> {
try {
return await getManifestFromRepo(auth);
const manifest = await getManifestFromRepo(auth);
if (
Array.isArray(manifest) &&
manifest.length &&
manifest.every(isIToolRelease)
) {
return manifest;
}

let errorMessage =
'An unexpected error occurred while fetching the manifest.';
if (
typeof manifest === 'object' &&
manifest !== null &&
'message' in manifest
) {
errorMessage = (manifest as {message: string}).message;
}
throw new Error(errorMessage);
} catch (err) {
core.debug('Fetching the manifest via the API failed.');
if (err instanceof Error) {
Expand Down
Loading