|
| 1 | +#!/usr/bin/python2.7 |
| 2 | + |
| 3 | +import argparse |
| 4 | +import os |
| 5 | +import shlex |
| 6 | +import subprocess |
| 7 | +import sys |
| 8 | +import yaml |
| 9 | +import mako.template |
| 10 | + |
| 11 | + |
| 12 | +def gen_release_desc(release_yaml): |
| 13 | + templ = """* Lambda Linux VirtualBox ISO [${data['github_tag']}](https://github.com/lambda-linux/lambda-linux-vbox/releases/tag/${data['github_tag']}) |
| 14 | +* Docker [${data['docker']}](https://github.com/docker/docker/releases/tag/${data['docker']}) |
| 15 | +* Kernel [${data['kernel']}](https://cdn.kernel.org/pub/linux/kernel/v4.x/ChangeLog-${data['kernelwov']}) |
| 16 | +* VirtualBox Guest Additions [${data['vbox_guest_additions']}](http://download.virtualbox.org/virtualbox/${data['vbox_guest_additionswov']}/) |
| 17 | +
|
| 18 | +${'#### Checksum'} |
| 19 | +- lambda-linux-vbox.iso |
| 20 | + - sha256 `${data['iso_sha256']}` |
| 21 | + - md5 `${data['iso_md5']}` |
| 22 | +""" |
| 23 | + release_desc_template = mako.template.Template(templ) |
| 24 | + |
| 25 | + # kernelwov = kernel without 'v' |
| 26 | + # vbox_guest_additionswov = vbox_guest_additionswov |
| 27 | + # This is required to point to correct links |
| 28 | + release_yaml1 = release_yaml.copy() |
| 29 | + release_yaml1['kernelwov'] = release_yaml['kernel'][1:] |
| 30 | + release_yaml1['vbox_guest_additionswov'] = release_yaml[ |
| 31 | + 'vbox_guest_additions'][1:] |
| 32 | + |
| 33 | + return release_desc_template.render(data=release_yaml1) |
| 34 | + |
| 35 | + |
| 36 | +def read_release_yaml(): |
| 37 | + with open('release.yaml', 'r') as yaml_file: |
| 38 | + yaml_string = yaml_file.read() |
| 39 | + x = yaml.load_all(yaml_string, Loader=yaml.CLoader) |
| 40 | + return x.next() |
| 41 | + |
| 42 | + |
| 43 | +def iso_checksums(iso): |
| 44 | + checksums = {} |
| 45 | + |
| 46 | + cmd = "sha256sum %s" % iso |
| 47 | + output = subprocess.check_output(shlex.split(cmd)) |
| 48 | + checksums['iso_sha256'] = output.split()[0] |
| 49 | + |
| 50 | + cmd = "md5sum %s" % iso |
| 51 | + output = subprocess.check_output(shlex.split(cmd)) |
| 52 | + checksums['iso_md5'] = output.split()[0] |
| 53 | + |
| 54 | + return checksums |
| 55 | + |
| 56 | + |
| 57 | +def main(): |
| 58 | + release_yaml = read_release_yaml() |
| 59 | + |
| 60 | + parser = argparse.ArgumentParser( |
| 61 | + description='Release lambda-linux-vbox.iso on GitHub', |
| 62 | + usage='''release <args> |
| 63 | +--github_security_token GitHub token |
| 64 | +--iso Path lambda-linux-vbox.iso file |
| 65 | +--pre_release Indicate if pre-release |
| 66 | +''') |
| 67 | + parser.add_argument( |
| 68 | + '--github_security_token', help='GitHub token', required=True) |
| 69 | + parser.add_argument( |
| 70 | + '--iso', help='Path to lambda-linux-vbox.iso file', required=True) |
| 71 | + parser.add_argument( |
| 72 | + '--pre_release', |
| 73 | + type=bool, |
| 74 | + default=False, |
| 75 | + help='Indicate if pre-release') |
| 76 | + args = parser.parse_args(sys.argv[1:]) |
| 77 | + |
| 78 | + if not os.path.exists(args.iso): |
| 79 | + print "%s does not exist!" % args.iso |
| 80 | + sys.exit(1) |
| 81 | + |
| 82 | + release_yaml.update(iso_checksums(args.iso)) |
| 83 | + |
| 84 | + release_desc = gen_release_desc(release_yaml) |
| 85 | + |
| 86 | + print "Checking if release already exists" |
| 87 | + cmd = "github-release info --security-token %s --user %s --repo %s --tag %s" % ( |
| 88 | + args.github_security_token, release_yaml['github_user'], |
| 89 | + release_yaml['github_repo'], release_yaml['github_tag']) |
| 90 | + ret = subprocess.call(shlex.split(cmd)) |
| 91 | + |
| 92 | + if ret != 1: |
| 93 | + print "Release already exists, cleaning it up" |
| 94 | + cmd = "github-release delete --security-token %s --user %s --repo %s --tag %s" % ( |
| 95 | + args.github_security_token, release_yaml['github_user'], |
| 96 | + release_yaml['github_repo'], release_yaml['github_tag']) |
| 97 | + subprocess.check_output(shlex.split(cmd)) |
| 98 | + |
| 99 | + print "Creating release on github" |
| 100 | + if args.pre_release: |
| 101 | + cmd = "github-release release --pre-release --security-token %s --user %s --repo %s --tag %s --name %s --description '%s'" % ( |
| 102 | + args.github_security_token, release_yaml['github_user'], |
| 103 | + release_yaml['github_repo'], release_yaml['github_tag'], |
| 104 | + release_yaml['github_tag'], release_desc) |
| 105 | + else: |
| 106 | + cmd = "github-release release --security-token %s --user %s --repo %s --tag %s --name %s --description '%s'" % ( |
| 107 | + args.github_security_token, release_yaml['github_user'], |
| 108 | + release_yaml['github_repo'], release_yaml['github_tag'], |
| 109 | + release_yaml['github_tag'], release_desc) |
| 110 | + subprocess.check_output(shlex.split(cmd)) |
| 111 | + |
| 112 | + print "Uploading lambda-linux-vbox.iso" |
| 113 | + cmd = "github-release upload --security-token %s --user %s --repo %s --tag %s --name %s --file %s" % ( |
| 114 | + args.github_security_token, release_yaml['github_user'], |
| 115 | + release_yaml['github_repo'], release_yaml['github_tag'], |
| 116 | + 'lambda-linux-vbox.iso', args.iso) |
| 117 | + subprocess.check_output(shlex.split(cmd)) |
| 118 | + |
| 119 | + |
| 120 | +if __name__ == '__main__': |
| 121 | + main() |
0 commit comments