build: convert all release scripts to typescript (#44060)
* build: run gha on tag not branch (#42490) * build: convert all release scripts to typescript (#44035) * build: convert all release scripts to typescript * fix test imports * build: fix version bumper export * refactor: use as const * spec: fix bad type spec * build: use ts-node to spawn the version-bumper (#44057) Missed this in the tsification, we should probably call this via API instead of spawning a sub-proc? * build: still colors
This commit is contained in:
parent
956677b66a
commit
2e84985439
22 changed files with 1173 additions and 779 deletions
46
script/release/get-url-hash.ts
Normal file
46
script/release/get-url-hash.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import got from 'got';
|
||||
import * as url from 'node:url';
|
||||
|
||||
const HASHER_FUNCTION_HOST = 'electron-artifact-hasher.azurewebsites.net';
|
||||
const HASHER_FUNCTION_ROUTE = '/api/HashArtifact';
|
||||
|
||||
export async function getUrlHash (targetUrl: string, algorithm = 'sha256', attempts = 3) {
|
||||
const options = {
|
||||
code: process.env.ELECTRON_ARTIFACT_HASHER_FUNCTION_KEY!,
|
||||
targetUrl,
|
||||
algorithm
|
||||
};
|
||||
const search = new url.URLSearchParams(options);
|
||||
const functionUrl = url.format({
|
||||
protocol: 'https:',
|
||||
hostname: HASHER_FUNCTION_HOST,
|
||||
pathname: HASHER_FUNCTION_ROUTE,
|
||||
search: search.toString()
|
||||
});
|
||||
try {
|
||||
const resp = await got(functionUrl, {
|
||||
throwHttpErrors: false
|
||||
});
|
||||
if (resp.statusCode !== 200) {
|
||||
console.error('bad hasher function response:', resp.body.trim());
|
||||
throw new Error('non-200 status code received from hasher function');
|
||||
}
|
||||
if (!resp.body) throw new Error('Successful lambda call but failed to get valid hash');
|
||||
|
||||
return resp.body.trim();
|
||||
} catch (err) {
|
||||
if (attempts > 1) {
|
||||
const { response } = err as any;
|
||||
if (response?.body) {
|
||||
console.error(`Failed to get URL hash for ${targetUrl} - we will retry`, {
|
||||
statusCode: response.statusCode,
|
||||
body: JSON.parse(response.body)
|
||||
});
|
||||
} else {
|
||||
console.error(`Failed to get URL hash for ${targetUrl} - we will retry`, err);
|
||||
}
|
||||
return getUrlHash(targetUrl, algorithm, attempts - 1);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue