modify upload script to allow uploading release assets to s3

This commit is contained in:
Vanessa Yuen 2017-11-02 16:06:28 +08:00
parent f937f971c1
commit b23fa34470
2 changed files with 47 additions and 21 deletions

View file

@ -21,7 +21,7 @@ jobs:
esac
if [ -n "${RUN_RELEASE_BUILD}" ]; then
echo 'release build triggered from api'
echo 'export ELECTRON_RELEASE=1' >> $BASH_ENV
echo 'export ELECTRON_RELEASE=1 TRIGGERED_BY_API=1' >> $BASH_ENV
fi
- run:
name: Bootstrap
@ -56,9 +56,12 @@ jobs:
- run:
name: Upload distribution
command: |
if [ "$ELECTRON_RELEASE" == "1" ]; then
echo 'Uploading Electron release distribution'
if [ "$ELECTRON_RELEASE" == "1" ] && [ "$TRIGGERED_BY_API" != "1" ]; then
echo 'Uploading Electron release distribution to github releases'
script/upload.py
elif [ "$ELECTRON_RELEASE" == "1" ] && [ "$TRIGGERED_BY_API" == "1" ]; then
echo 'Uploading Electron release distribution to s3'
script/upload.py --upload_to_s3
else
echo 'Skipping upload distribution because build is not for release'
fi

View file

@ -56,34 +56,36 @@ def main():
tag_exists = True
break
if not args.upload_to_s3:
assert tag_exists == args.overwrite, \
'You have to pass --overwrite to overwrite a published release'
if not args.overwrite:
release = create_or_get_release_draft(github, releases, args.version,
tag_exists)
# Upload Electron with GitHub Releases API.
upload_electron(github, release, os.path.join(DIST_DIR, DIST_NAME))
upload_electron(github, release, os.path.join(DIST_DIR, SYMBOLS_NAME))
upload_electron(github, release, os.path.join(DIST_DIR, DIST_NAME), args.upload_to_s3)
upload_electron(github, release, os.path.join(DIST_DIR, SYMBOLS_NAME), args.upload_to_s3)
if PLATFORM == 'darwin':
upload_electron(github, release, os.path.join(DIST_DIR,
upload_electron(github, release, os.path.join(DIST_DIR, args.upload_to_s3,
'electron-api.json'))
upload_electron(github, release, os.path.join(DIST_DIR, 'electron.d.ts'))
upload_electron(github, release, os.path.join(DIST_DIR, DSYM_NAME))
upload_electron(github, release, os.path.join(DIST_DIR, 'electron.d.ts'), args.upload_to_s3)
upload_electron(github, release, os.path.join(DIST_DIR, DSYM_NAME), args.upload_to_s3)
elif PLATFORM == 'win32':
upload_electron(github, release, os.path.join(DIST_DIR, PDB_NAME))
upload_electron(github, release, os.path.join(DIST_DIR, PDB_NAME), args.upload_to_s3)
# Upload free version of ffmpeg.
ffmpeg = get_zip_name('ffmpeg', ELECTRON_VERSION)
upload_electron(github, release, os.path.join(DIST_DIR, ffmpeg))
upload_electron(github, release, os.path.join(DIST_DIR, ffmpeg), args.upload_to_s3)
# Upload chromedriver and mksnapshot for minor version update.
if parse_version(args.version)[2] == '0':
chromedriver = get_zip_name('chromedriver', ELECTRON_VERSION)
upload_electron(github, release, os.path.join(DIST_DIR, chromedriver))
upload_electron(github, release, os.path.join(DIST_DIR, chromedriver), args.upload_to_s3)
mksnapshot = get_zip_name('mksnapshot', ELECTRON_VERSION)
upload_electron(github, release, os.path.join(DIST_DIR, mksnapshot))
upload_electron(github, release, os.path.join(DIST_DIR, mksnapshot), args.upload_to_s3)
# TODO: make s3 compatible
if PLATFORM == 'win32' and not tag_exists:
# Upload PDBs to Windows symbol server.
@ -187,7 +189,17 @@ def create_release_draft(github, tag):
return r
def upload_electron(github, release, file_path):
def upload_electron(github, release, file_path, upload_to_s3):
# if upload_to_s3 is set, skip github upload.
if upload_to_s3:
bucket, access_key, secret_key = s3_config()
key_prefix = 'electron-artifacts/{0}'.format(release['tag_name'])
s3put(bucket, access_key, secret_key, os.path.dirname(file_path),
key_prefix, [file_path])
upload_sha256_checksum(release['tag_name'], file_path, key_prefix)
return
# Delete the original file before uploading in CI.
filename = os.path.basename(file_path)
if os.environ.has_key('CI'):
@ -220,9 +232,11 @@ def upload_io_to_github(release, filename, filepath):
execute(['node', script_path, filepath, filename, str(release['id'])])
def upload_sha256_checksum(version, file_path):
def upload_sha256_checksum(version, file_path, key_prefix=None):
bucket, access_key, secret_key = s3_config()
checksum_path = '{}.sha256sum'.format(file_path)
if key_prefix is None:
key_prefix = 'atom-shell/tmp/{0}'.format(version)
sha256 = hashlib.sha256()
with open(file_path, 'rb') as f:
sha256.update(f.read())
@ -231,7 +245,7 @@ def upload_sha256_checksum(version, file_path):
with open(checksum_path, 'w') as checksum:
checksum.write('{} *{}'.format(sha256.hexdigest(), filename))
s3put(bucket, access_key, secret_key, os.path.dirname(checksum_path),
'atom-shell/tmp/{0}'.format(version), [checksum_path])
key_prefix, [checksum_path])
def auth_token():
@ -241,6 +255,15 @@ def auth_token():
assert token, message
return token
def parse_args():
parser = argparse.ArgumentParser(description='Upload Electron Assets')
parser.add_argument('-s', '--upload_to_s3',
help='Upload assets to s3 bucket',
dest='upload_to_s3',
action='store_true',
default=False,
required=False)
return parser.parse_args()
if __name__ == '__main__':
import sys