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
51
script/release/get-asset.ts
Normal file
51
script/release/get-asset.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import { Octokit } from '@octokit/rest';
|
||||
import got from 'got';
|
||||
import { createGitHubTokenStrategy } from './github-token';
|
||||
import { ElectronReleaseRepo } from './types';
|
||||
|
||||
export async function getAssetContents (repo: ElectronReleaseRepo, assetId: number) {
|
||||
const octokit = new Octokit({
|
||||
userAgent: 'electron-asset-fetcher',
|
||||
authStrategy: createGitHubTokenStrategy(repo)
|
||||
});
|
||||
|
||||
const requestOptions = octokit.repos.getReleaseAsset.endpoint({
|
||||
owner: 'electron',
|
||||
repo,
|
||||
asset_id: assetId,
|
||||
headers: {
|
||||
Accept: 'application/octet-stream'
|
||||
}
|
||||
});
|
||||
|
||||
const { url, headers } = requestOptions;
|
||||
headers.authorization = `token ${(await octokit.auth() as { token: string }).token}`;
|
||||
|
||||
const response = await got(url, {
|
||||
followRedirect: false,
|
||||
method: 'HEAD',
|
||||
headers: headers as Record<string, string>,
|
||||
throwHttpErrors: false
|
||||
});
|
||||
|
||||
if (response.statusCode !== 302 && response.statusCode !== 301) {
|
||||
console.error('Failed to HEAD github asset contents for redirect: ' + url);
|
||||
throw new Error('Unexpected status HEAD\'ing github asset for redirect: ' + response.statusCode);
|
||||
}
|
||||
|
||||
if (!response.headers.location) {
|
||||
console.error(response.headers, `${response.body}`.slice(0, 300));
|
||||
throw new Error(`cannot find asset[${assetId}], asset download did not redirect`);
|
||||
}
|
||||
|
||||
const fileResponse = await got(response.headers.location, {
|
||||
throwHttpErrors: false
|
||||
});
|
||||
|
||||
if (fileResponse.statusCode !== 200) {
|
||||
console.error(fileResponse.headers, `${fileResponse.body}`.slice(0, 300));
|
||||
throw new Error(`cannot download asset[${assetId}] from ${response.headers.location}, got status: ${fileResponse.statusCode}`);
|
||||
}
|
||||
|
||||
return fileResponse.body;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue