chore: move upload-to-github to TS (#26390)

This commit is contained in:
Samuel Attard 2020-11-09 13:57:53 -08:00 коммит произвёл GitHub
Родитель 40ebdb5c42
Коммит 946802600b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 24 добавлений и 12 удалений

Просмотреть файл

@ -25,11 +25,13 @@ from lib.config import is_verbose_mode
ELECTRON_DIR = os.path.abspath(
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
)
TS_NODE = os.path.join(ELECTRON_DIR, 'node_modules', '.bin', 'ts-node')
SRC_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', '..'))
NPM = 'npm'
if sys.platform in ['win32', 'cygwin']:
NPM += '.cmd'
TS_NODE += '.cmd'
def tempdir(prefix=''):

Просмотреть файл

@ -1,12 +1,12 @@
if (!process.env.CI) require('dotenv-safe').load();
import { Octokit } from '@octokit/rest';
import * as fs from 'fs';
const fs = require('fs');
const { Octokit } = require('@octokit/rest');
const octokit = new Octokit({
auth: process.env.ELECTRON_GITHUB_TOKEN
});
if (!process.env.CI) require('dotenv-safe').load();
if (process.argv.length < 6) {
console.log('Usage: upload-to-github filePath fileName releaseId');
process.exit(1);
@ -14,13 +14,20 @@ if (process.argv.length < 6) {
const filePath = process.argv[2];
const fileName = process.argv[3];
const releaseId = process.argv[4];
const releaseId = parseInt(process.argv[4], 10);
const releaseVersion = process.argv[5];
const getHeaders = (filePath, fileName) => {
if (isNaN(releaseId)) {
throw new Error('Provided release ID was not a valid integer');
}
const getHeaders = (filePath: string, fileName: string) => {
const extension = fileName.split('.').pop();
if (!extension) {
throw new Error(`Failed to get headers for extensionless file: ${fileName}`);
}
const size = fs.statSync(filePath).size;
const options = {
const options: Record<string, string> = {
json: 'text/json',
zip: 'application/zip',
txt: 'text/plain',
@ -41,8 +48,11 @@ function uploadToGitHub () {
octokit.repos.uploadReleaseAsset({
url: uploadUrl,
headers: getHeaders(filePath, fileName),
data: fs.createReadStream(filePath),
name: fileName
data: fs.createReadStream(filePath) as any,
name: fileName,
owner: 'electron',
repo: targetRepo,
release_id: releaseId
}).then(() => {
console.log(`Successfully uploaded ${fileName} to GitHub.`);
process.exit();

Просмотреть файл

@ -20,7 +20,7 @@ from lib.config import PLATFORM, get_target_arch, get_env_var, s3_config, \
get_zip_name, enable_verbose_mode, get_platform_key
from lib.util import get_electron_branding, execute, get_electron_version, \
s3put, get_electron_exec, get_out_dir, \
SRC_DIR, ELECTRON_DIR
SRC_DIR, ELECTRON_DIR, TS_NODE
ELECTRON_REPO = 'electron/electron'
@ -337,8 +337,8 @@ def upload_io_to_github(release, filename, filepath, version):
print('Uploading %s to Github' % \
(filename))
script_path = os.path.join(
ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-to-github.js')
execute(['node', script_path, filepath, filename, str(release['id']),
ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-to-github.ts')
execute([TS_NODE, script_path, filepath, filename, str(release['id']),
version])