diff --git a/script/lib/util.py b/script/lib/util.py index f80b1f145a..1e5ddecce5 100644 --- a/script/lib/util.py +++ b/script/lib/util.py @@ -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=''): diff --git a/script/release/uploaders/upload-to-github.js b/script/release/uploaders/upload-to-github.ts similarity index 82% rename from script/release/uploaders/upload-to-github.js rename to script/release/uploaders/upload-to-github.ts index 0f08fbc7c2..c998e2f42e 100644 --- a/script/release/uploaders/upload-to-github.js +++ b/script/release/uploaders/upload-to-github.ts @@ -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 = { 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(); diff --git a/script/release/uploaders/upload.py b/script/release/uploaders/upload.py index d03c359391..5fb7af36e6 100755 --- a/script/release/uploaders/upload.py +++ b/script/release/uploaders/upload.py @@ -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])