chore: move upload-to-github to TS (#26390)
This commit is contained in:
parent
40ebdb5c42
commit
946802600b
3 changed files with 24 additions and 12 deletions
|
@ -25,11 +25,13 @@ from lib.config import is_verbose_mode
|
||||||
ELECTRON_DIR = os.path.abspath(
|
ELECTRON_DIR = os.path.abspath(
|
||||||
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
|
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__, '..', '..', '..', '..'))
|
SRC_DIR = os.path.abspath(os.path.join(__file__, '..', '..', '..', '..'))
|
||||||
|
|
||||||
NPM = 'npm'
|
NPM = 'npm'
|
||||||
if sys.platform in ['win32', 'cygwin']:
|
if sys.platform in ['win32', 'cygwin']:
|
||||||
NPM += '.cmd'
|
NPM += '.cmd'
|
||||||
|
TS_NODE += '.cmd'
|
||||||
|
|
||||||
|
|
||||||
def tempdir(prefix=''):
|
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({
|
const octokit = new Octokit({
|
||||||
auth: process.env.ELECTRON_GITHUB_TOKEN
|
auth: process.env.ELECTRON_GITHUB_TOKEN
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!process.env.CI) require('dotenv-safe').load();
|
||||||
|
|
||||||
if (process.argv.length < 6) {
|
if (process.argv.length < 6) {
|
||||||
console.log('Usage: upload-to-github filePath fileName releaseId');
|
console.log('Usage: upload-to-github filePath fileName releaseId');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
@ -14,13 +14,20 @@ if (process.argv.length < 6) {
|
||||||
|
|
||||||
const filePath = process.argv[2];
|
const filePath = process.argv[2];
|
||||||
const fileName = process.argv[3];
|
const fileName = process.argv[3];
|
||||||
const releaseId = process.argv[4];
|
const releaseId = parseInt(process.argv[4], 10);
|
||||||
const releaseVersion = process.argv[5];
|
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();
|
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 size = fs.statSync(filePath).size;
|
||||||
const options = {
|
const options: Record<string, string> = {
|
||||||
json: 'text/json',
|
json: 'text/json',
|
||||||
zip: 'application/zip',
|
zip: 'application/zip',
|
||||||
txt: 'text/plain',
|
txt: 'text/plain',
|
||||||
|
@ -41,8 +48,11 @@ function uploadToGitHub () {
|
||||||
octokit.repos.uploadReleaseAsset({
|
octokit.repos.uploadReleaseAsset({
|
||||||
url: uploadUrl,
|
url: uploadUrl,
|
||||||
headers: getHeaders(filePath, fileName),
|
headers: getHeaders(filePath, fileName),
|
||||||
data: fs.createReadStream(filePath),
|
data: fs.createReadStream(filePath) as any,
|
||||||
name: fileName
|
name: fileName,
|
||||||
|
owner: 'electron',
|
||||||
|
repo: targetRepo,
|
||||||
|
release_id: releaseId
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
console.log(`Successfully uploaded ${fileName} to GitHub.`);
|
console.log(`Successfully uploaded ${fileName} to GitHub.`);
|
||||||
process.exit();
|
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
|
get_zip_name, enable_verbose_mode, get_platform_key
|
||||||
from lib.util import get_electron_branding, execute, get_electron_version, \
|
from lib.util import get_electron_branding, execute, get_electron_version, \
|
||||||
s3put, get_electron_exec, get_out_dir, \
|
s3put, get_electron_exec, get_out_dir, \
|
||||||
SRC_DIR, ELECTRON_DIR
|
SRC_DIR, ELECTRON_DIR, TS_NODE
|
||||||
|
|
||||||
|
|
||||||
ELECTRON_REPO = 'electron/electron'
|
ELECTRON_REPO = 'electron/electron'
|
||||||
|
@ -337,8 +337,8 @@ def upload_io_to_github(release, filename, filepath, version):
|
||||||
print('Uploading %s to Github' % \
|
print('Uploading %s to Github' % \
|
||||||
(filename))
|
(filename))
|
||||||
script_path = os.path.join(
|
script_path = os.path.join(
|
||||||
ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-to-github.js')
|
ELECTRON_DIR, 'script', 'release', 'uploaders', 'upload-to-github.ts')
|
||||||
execute(['node', script_path, filepath, filename, str(release['id']),
|
execute([TS_NODE, script_path, filepath, filename, str(release['id']),
|
||||||
version])
|
version])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue