refactor: use aws-sdk-js instead of boto (#24863)

* refactor: use js instead of boto for s3put

* replace merge-electron-checksums.py with js, remove boto

* fix auth

* actually pass the env to execute()
This commit is contained in:
Jeremy Rose 2020-08-13 10:25:40 -07:00 committed by GitHub
parent 627467d08a
commit a3581aa992
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 159 additions and 139 deletions

View file

@ -22,6 +22,7 @@ const sumchecker = require('sumchecker');
const temp = require('temp').track();
const { URL } = require('url');
const { Octokit } = require('@octokit/rest');
const AWS = require('aws-sdk');
require('colors');
const pass = '✓'.green;
@ -218,6 +219,41 @@ function uploadIndexJson () {
console.log(`${pass} Done uploading index.json to S3.`);
}
async function mergeShasums (pkgVersion) {
// Download individual checksum files for Electron zip files from S3,
// concatenate them, and upload to GitHub.
const bucket = process.env.ELECTRON_S3_BUCKET;
const accessKeyId = process.env.ELECTRON_S3_ACCESS_KEY;
const secretAccessKey = process.env.ELECTRON_S3_SECRET_KEY;
if (!bucket || !accessKeyId || !secretAccessKey) {
throw new Error('Please set the $ELECTRON_S3_BUCKET, $ELECTRON_S3_ACCESS_KEY, and $ELECTRON_S3_SECRET_KEY environment variables');
}
const s3 = new AWS.S3({
apiVersion: '2006-03-01',
accessKeyId,
secretAccessKey,
region: 'us-west-2'
});
const objects = await s3.listObjectsV2({
Bucket: bucket,
Prefix: `atom-shell/tmp/${pkgVersion}/`,
Delimiter: '/'
}).promise();
const shasums = [];
for (const obj of objects.Contents) {
if (obj.Key.endsWith('.sha256sum')) {
const data = await s3.getObject({
Bucket: bucket,
Key: obj.Key
}).promise();
shasums.push(data.toString('ascii').trim());
}
}
return shasums.join('\n');
}
async function createReleaseShasums (release) {
const fileName = 'SHASUMS256.txt';
const existingAssets = release.assets.filter(asset => asset.name === fileName);
@ -232,8 +268,7 @@ async function createReleaseShasums (release) {
});
}
console.log(`Creating and uploading the release ${fileName}.`);
const scriptPath = path.join(ELECTRON_DIR, 'script', 'release', 'merge-electron-checksums.py');
const checksums = runScript(scriptPath, ['-v', pkgVersion]);
const checksums = await mergeShasums(pkgVersion);
console.log(`${pass} Generated release SHASUMS.`);
const filePath = await saveShaSumFile(checksums, fileName);