Beispiel #1
0
def main(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-t',
                        '--tag',
                        help='the SapMachine Git tag',
                        metavar='TAG',
                        required=True)
    args = parser.parse_args()

    token = utils.get_github_api_accesstoken()
    org = 'SAP'
    repository = 'SapMachine'
    github_api = str.format('https://api.github.com/repos/{0}/{1}/releases',
                            org, repository)

    request = Request(github_api)

    if token is not None:
        request.add_header('Authorization', str.format('token {0}', token))

    response = json.loads(urlopen(request).read())

    for release in response:
        if release['tag_name'] == args.tag:
            print(str(not release['prerelease']).lower())
def main(argv=None):
    token = utils.get_github_api_accesstoken()
    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    asset_map_jre = {}
    asset_map_jdk = {}

    releases = utils.get_github_releases()

    for release in releases:
        if release['prerelease'] is True:
            continue

        t = SapMachineTag.from_string(release['name'])
        if t is None:
            continue

        assets = release['assets']
        for asset in assets:
            match = asset_pattern.match(asset['name'])
            if match is None:
                continue

            asset_image_type = match.group(1)
            asset_os = match.group(3)

            if asset_os == 'linux-x64':
                sapmachine_version = t.get_version()
                build_number = t.get_build_number()

                buildpack_version = str.format(
                    '{0}.{1}.{2}_{3}.{4}.b{5}', sapmachine_version[0],
                    sapmachine_version[1], sapmachine_version[2],
                    sapmachine_version[3], sapmachine_version[4],
                    build_number if build_number else '0')

                if asset_image_type == 'jre':
                    asset_map_jre[buildpack_version] = asset[
                        'browser_download_url']
                else:
                    asset_map_jdk[buildpack_version] = asset[
                        'browser_download_url']

    local_repo = join(os.getcwd(), 'gh-pages')
    utils.git_clone('github.com/SAP/SapMachine.git', 'gh-pages', local_repo)
    write_index_yaml(
        asset_map_jre,
        join(local_repo, 'assets', 'cf', 'jre', 'linux', 'x86_64'))
    write_index_yaml(
        asset_map_jdk,
        join(local_repo, 'assets', 'cf', 'jdk', 'linux', 'x86_64'))
    utils.git_commit(local_repo, 'Updated index.yml', ['assets'])
    utils.git_push(local_repo)
    utils.remove_if_exists(local_repo)

    return 0
Beispiel #3
0
def main(argv=None):
    token = utils.get_github_api_accesstoken()
    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    asset_map = {}

    releases = utils.github_api_request('releases', per_page=100)

    for release in releases:
        if release['prerelease'] is True:
            continue

        version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(
            release['name'])
        assets = release['assets']

        if version is None or os_ext:
            continue

        for asset in assets:
            match = asset_pattern.match(asset['name'])

            if match is not None:
                asset_image_type = match.group(1)
                asset_os = match.group(3)

                if asset_os == 'linux-x64' and asset_image_type == 'jre':
                    sapmachine_version = [
                        int(e) for e in version_part.split('.')
                    ]
                    sapmachine_version += [
                        0 for sapmachine_version in range(
                            0, 5 - len(sapmachine_version))
                    ]

                    if sap_build_number:
                        sapmachine_version[4] = int(sap_build_number)

                    buildpack_version = str.format(
                        '{0}.{1}.{2}_{3}.{4}.b{5}', sapmachine_version[0],
                        sapmachine_version[1], sapmachine_version[2],
                        sapmachine_version[3], sapmachine_version[4],
                        build_number if build_number else '0')
                    asset_map[buildpack_version] = asset[
                        'browser_download_url']

    local_repo = join(os.getcwd(), 'gh-pages')
    utils.git_clone('github.com/SAP/SapMachine.git', 'gh-pages', local_repo)
    write_index_yaml(
        asset_map, join(local_repo, 'assets', 'cf', 'jre', 'linux', 'x86_64'))
    utils.git_commit(local_repo, 'Updated index.yml', ['assets'])
    utils.git_push(local_repo)
    utils.remove_if_exists(local_repo)
def api_request(url, data=None, method='GET'):
    token = utils.get_github_api_accesstoken()
    request = Request(url, data=data)
    request.get_method = lambda: method

    if token is not None:
        request.add_header('Authorization', str.format('token {0}', token))

    try:
        response = json.loads(urlopen(request).read())
        return response
    except Exception as e:
        print(e)
        return None
def main(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-m',
                        '--major',
                        help='the SapMachine major version',
                        metavar='MAJOR',
                        required=True)
    parser.add_argument('-s',
                        '--separator',
                        help='the separator char',
                        metavar='SEPARATOR',
                        required=False,
                        default=' ')
    parser.add_argument('-p',
                        '--include-prereleases',
                        help='include pre-releases',
                        action='store_true',
                        default=False)
    args = parser.parse_args()

    requested_major = args.major
    separator = args.separator
    include_prereleases = args.include_prereleases
    tag_list = []

    token = utils.get_github_api_accesstoken()
    org = 'SAP'
    repository = 'SapMachine'
    github_api = str.format('https://api.github.com/repos/{0}/{1}/releases',
                            org, repository)
    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    request = Request(github_api)

    if token is not None:
        request.add_header('Authorization', str.format('token {0}', token))

    response = json.loads(urlopen(request).read())
    for release in response:
        if release['prerelease'] is True and not include_prereleases:
            continue

        version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(
            release['name'])

        if major is None or major != requested_major or os_ext:
            continue

        tag_list.append(release['name'])

    print(separator.join([tag for tag in tag_list]))
def create_request(path, data=None, method='GET'):
    org = 'SAP'
    repository = 'SapMachine'
    github_api = str.format('https://api.github.com/repos/{0}/{1}', org,
                            repository)
    request_url = str.format('{0}/{1}', github_api, path)
    token = utils.get_github_api_accesstoken()

    if token is None:
        raise Exception('no GitHub API access token specified')

    request = Request(request_url, data=data)
    request.get_method = lambda: method
    request.add_header('Authorization', str.format('token {0}', token))
    return request
Beispiel #7
0
def main(argv=None):
    token = utils.get_github_api_accesstoken()
    github_api = 'https://api.github.com/repos/SAP/SapMachine/releases'
    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    asset_map = {}

    request = Request(github_api)

    if token is not None:
        request.add_header('Authorization', str.format('token {0}', token))

    response = json.loads(urlopen(request).read())
    for release in response:
        if release['prerelease'] is True:
            continue

        version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(release['name'])
        assets = release['assets']

        if version is None or os_ext:
            continue

        for asset in assets:
            match = asset_pattern.match(asset['name'])

            if match is not None:
                asset_image_type = match.group(1)
                asset_os = match.group(3)

                if asset_os == 'linux-x64' and asset_image_type == 'jdk':
                    sapmachine_version = [int(e) for e in version_part.split('.')]
                    sapmachine_version += [0 for sapmachine_version in range(0, 5 - len(sapmachine_version))]

                    if sap_build_number:
                        sapmachine_version[4] = int(sap_build_number)

                    buildpack_version = '.'.join([str(e) for e in sapmachine_version])
                    buildpack_version += str.format('_b{0}', build_number if build_number else '0')
                    asset_map[buildpack_version] = asset['browser_download_url']

    local_repo = join(os.getcwd(), 'gh-pages')
    utils.git_clone('github.com/SAP/SapMachine.git', 'gh-pages', local_repo)
    write_index_yaml(asset_map, join(local_repo, 'assets', 'cf', 'jre', 'linux', 'x86_64'))
    utils.git_commit(local_repo, 'Updated index.yml', ['assets'])
    utils.git_push(local_repo)
    utils.remove_if_exists(local_repo)
def main(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-t', '--tag', help='the tag to create the alpine packages from', metavar='TAG', required=True)
    parser.add_argument('-d', '--templates-directory', help='specify the templates directory', metavar='DIR', required=True)
    args = parser.parse_args()

    templates_dir = realpath(args.templates_directory)
    tag = args.tag

    if tag.endswith('-alpine'):
        # the "-alpine" tags do not contain any assets
        tag = tag[:-len('-alpine')]

    cwd = os.getcwd()
    home = expanduser("~")
    work_dir = join(cwd, 'apk_work')
    version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(tag)
    jdk_url, jre_url = utils.fetch_tag(tag, 'linux-x64-musl', utils.get_github_api_accesstoken())
    jdk_name = str.format('sapmachine-{0}-jdk', major)
    jre_name = str.format('sapmachine-{0}-jre', major)
    jdk_dir = join(work_dir, jdk_name)
    jre_dir = join(work_dir, jre_name)

    utils.remove_if_exists(work_dir)

    mkdir(work_dir)
    mkdir(jdk_dir)
    mkdir(jre_dir)

    generate_configuration(templates_dir, jdk_dir, jdk_name, version, '0', 'The SapMachine Java Development Kit', jdk_url)
    generate_configuration(templates_dir, jre_dir, jre_name, version, '0', 'The SapMachine Java Runtime Environment', jre_url)

    utils.run_cmd(['abuild', 'checksum'], cwd=jdk_dir)
    utils.run_cmd(['abuild', 'checksum'], cwd=jre_dir)

    utils.run_cmd(['abuild', '-r', '-K'], cwd=jdk_dir)
    utils.run_cmd(['abuild', '-r', '-K'], cwd=jre_dir)

    rmtree(work_dir)

    apk_files = glob.glob(join(home, 'packages', 'apk_work','*', '*.apk'))

    for apk_file in apk_files:
        copy(apk_file, cwd)
Beispiel #9
0
def main(argv=None):
    token = utils.get_github_api_accesstoken()
    org = 'SAP'
    repository = 'SapMachine'
    github_api = str.format('https://api.github.com/repos/{0}/{1}/releases',
                            org, repository)
    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    major_dict = {}
    releases_dict = {}
    image_type_dict = {}
    latest_link_dict = {}
    request = Request(github_api)

    if token is not None:
        request.add_header('Authorization', str.format('token {0}', token))

    response = json.loads(urlopen(request).read())

    for release in response:
        version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(
            release['name'])

        if version is None or os_ext:
            continue

        if major in major_dict:
            continue

        major_dict[major] = True
        assets = release['assets']

        if release['prerelease'] is not True and major not in latest_link_dict:
            latest_link_dict[major] = Template(latest_template).substitute(
                major=major, url=release['html_url'])

        for asset in assets:
            match = asset_pattern.match(asset['name'])

            if match is not None:
                asset_image_type = match.group(1)
                asset_os = match.group(3)
                tag = release['name']
                image_type = major + '-' + asset_image_type

                if release['prerelease'] is True:
                    image_type += '-ea'

                if image_type not in image_type_dict:
                    image_type_dict[image_type] = str.format(
                        'SapMachine {0} {1}{2}', major, asset_image_type,
                        " (pre-release)" if release['prerelease'] else "")

                if image_type in releases_dict:
                    releases = releases_dict[image_type]
                else:
                    releases = Releases(image_type)
                    releases_dict[image_type] = releases

                releases_dict[image_type].add_asset(
                    asset['browser_download_url'], asset_os, tag)

    json_root = {'imageTypes': [], 'os': [], 'assets': {}}

    for image_type in sorted(image_type_dict):
        json_root['imageTypes'].append({
            'key': image_type,
            'value': image_type_dict[image_type]
        })

    def get_os_key(os):
        print(os)
        return os_description[os]['ordinal']

    for os in sorted(os_description, key=get_os_key):
        json_root['os'].append({
            'key': os,
            'value': os_description[os]['name'],
            'ordinal': os_description[os]['ordinal']
        })

    for release in releases_dict:
        json_root['assets'].update(releases_dict[release].transform())

    files = [{
        'location': join('assets', 'data', 'sapmachine_releases.json'),
        'data': json.dumps(json_root, indent=4),
        'commit_message': 'Updated release data.'
    }]

    for major in latest_link_dict:
        files.append({
            'location':
            join('latest', major, 'index.md'),
            'data':
            latest_link_dict[major],
            'commit_message':
            str.format('Updated latest link for SapMachine {0}', major)
        })

    push_to_git(files)
def main(argv=None):
    token = utils.get_github_api_accesstoken()
    org = 'SAP'
    repository = 'SapMachine'
    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    major_dict = {}
    release_dict = {}
    image_dict = {}
    latest_link_dict = {}

    releases = utils.github_api_request('releases', per_page=100)

    for release in releases:
        version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(
            release['name'])

        is_prerelease = release['prerelease']

        if version is None or os_ext:
            continue

        if major in major_dict:
            if not is_prerelease and major_dict[major]:
                # this is not a pre-release but the release before this was a pre-release
                # remove all assets
                if major in release_dict:
                    release_dict[major].clear_assets()

                # remove entry in the image dictionary
                if major in image_dict:
                    del image_dict[major]
            else:
                if not major_dict[major]:
                    # the release before this was a release
                    # skip, we only keep the latest release version
                    continue

        major_dict[major] = is_prerelease
        assets = release['assets']

        if is_prerelease is not True and major not in latest_link_dict:
            latest_link_dict[major] = Template(latest_template).substitute(
                major=major, url=release['html_url'])

        has_dmg = False

        for asset in assets:
            match = asset_pattern.match(asset['name'])

            if match is not None:
                asset_image_type = match.group(1)

                if asset_image_type == 'jdk':
                    asset_os = match.group(3)
                    file_type = match.group(4)

                    if asset_os == 'windows-x64' and file_type == '.msi':
                        asset_os = 'windows-x64-installer'

                    if asset_os == 'osx-x64':
                        if file_type == '.dmg':
                            has_dmg = True
                        elif has_dmg:
                            continue

                    tag = release['name']
                    image_is_lts = utils.sapmachine_is_lts(
                        major) and not release['prerelease']

                    if major not in image_dict:
                        image_dict[major] = {
                            'label': str.format('SapMachine {0}', major),
                            'lts': image_is_lts,
                            'ea': release['prerelease']
                        }

                    if major in release_dict:
                        releases = release_dict[major]
                    else:
                        releases = Releases(major)
                        release_dict[major] = releases

                    release_dict[major].add_asset(
                        asset['browser_download_url'], asset_os, tag)

    latest_lts_version = 0
    latest_non_lts_version = 0

    for major in image_dict:
        if image_dict[major]['lts'] and int(major) > latest_lts_version:
            latest_lts_version = int(major)
        if not image_dict[major]['lts'] and not image_dict[major][
                'ea'] and int(major) > latest_non_lts_version:
            latest_non_lts_version = int(major)

    json_root = {'imageTypes': [], 'os': [], 'assets': {}}

    for major in sorted(image_dict):
        add = False
        if image_dict[major]['lts']:
            if int(major) >= latest_lts_version:
                add = True
        else:
            if int(major) >= latest_non_lts_version and int(
                    major) >= latest_lts_version:
                add = True

        if add:
            json_root['imageTypes'].append({
                'id': major,
                'label': image_dict[major]['label'],
                'lts': image_dict[major]['lts'],
                'ea': image_dict[major]['ea']
            })
        else:
            del image_dict[major]

    def get_os_key(os):
        return os_description[os]['ordinal']

    for os in sorted(os_description, key=get_os_key):
        json_root['os'].append({
            'key': os,
            'value': os_description[os]['name'],
            'ordinal': os_description[os]['ordinal']
        })

    for major in release_dict:
        if major in image_dict:
            json_root['assets'].update(release_dict[major].transform())

    files = [{
        'location': join('assets', 'data', 'sapmachine_releases.json'),
        'data': json.dumps(json_root, indent=4),
        'commit_message': 'Updated release data.'
    }]

    for major in latest_link_dict:
        files.append({
            'location':
            join('latest', major, 'index.md'),
            'data':
            latest_link_dict[major],
            'commit_message':
            str.format('Updated latest link for SapMachine {0}', major)
        })

    push_to_git(files)
    return 0
Beispiel #11
0
def main(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-t', '--tag', help='the tag to create the debian packages from', metavar='TAG', required=True)
    parser.add_argument('-d', '--templates-directory', help='specify the templates directory', metavar='DIR', required=True)
    args = parser.parse_args()

    templates_dir = realpath(args.templates_directory)
    tag = args.tag

    if tag.endswith('-alpine'):
        # the "-alpine" tags do not contain any assets
        tag = tag[:-len('-alpine')]

    cwd = os.getcwd()
    work_dir = join(cwd, 'deb_work')
    version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(tag)
    version = version.replace('-', '.')
    jdk_name = str.format('sapmachine-{0}-jdk-{1}', major, version)
    jre_name = str.format('sapmachine-{0}-jre-{1}', major, version)

    jdk_url, jre_url = utils.fetch_tag(tag, 'linux-x64', utils.get_github_api_accesstoken())

    utils.remove_if_exists(work_dir)
    mkdir(work_dir)

    jdk_archive = join(work_dir, jdk_url.rsplit('/', 1)[-1])
    jre_archive = join(work_dir, jre_url.rsplit('/', 1)[-1])

    utils.download_artifact(jdk_url, jdk_archive)
    utils.download_artifact(jre_url, jre_archive)

    clone_sapmachine(join(work_dir, 'sapmachine_master'))
    src_dir = join(work_dir, 'sapmachine_master')

    jdk_dir = join(work_dir, jdk_name)
    jre_dir = join(work_dir, jre_name)

    mkdir(jdk_dir)
    mkdir(jre_dir)

    utils.extract_archive(jdk_archive, jdk_dir)
    utils.extract_archive(jre_archive, jre_dir)

    env = os.environ.copy()
    env['DEBFULLNAME'] = 'SapMachine'
    env['DEBEMAIL'] = '*****@*****.**'
    utils.run_cmd(['dh_make', '-n', '-s', '-y'], cwd=jdk_dir, env=env)
    utils.run_cmd(['dh_make', '-n', '-s', '-y'], cwd=jre_dir, env=env)

    jre_exploded_image = glob.glob(join(jre_dir, 'sapmachine-*'))[0]

    generate_configuration(
        templates_dir=join(templates_dir, 'jre'),
        major=major,
        target_dir=join(jre_dir, 'debian'),
        exploded_image=jre_exploded_image,
        src_dir=src_dir,
        download_url=jre_url)

    jdk_exploded_image = glob.glob(join(jdk_dir, 'sapmachine-*'))[0]

    generate_configuration(
        templates_dir=join(templates_dir, 'jdk'),
        major=major,
        target_dir=join(jdk_dir, 'debian'),
        exploded_image=jdk_exploded_image,
        src_dir=src_dir,
        download_url=jdk_url)

    utils.run_cmd(['debuild', '-b', '-uc', '-us'], cwd=jre_dir, env=env)
    utils.run_cmd(['debuild', '-b', '-uc', '-us'], cwd=jdk_dir, env=env)

    deb_files = glob.glob(join(work_dir, '*.deb'))

    for deb_file in deb_files:
        copy(deb_file, cwd)
        remove(deb_file)
Beispiel #12
0
def main(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-m',
                        '--major',
                        help='the SapMachine major version',
                        metavar='MAJOR',
                        required=True)
    args = parser.parse_args()

    token = utils.get_github_api_accesstoken()
    github_api = 'https://api.github.com/repos/SAP/SapMachine/releases'
    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    asset_map = {}

    request = Request(github_api)

    if token is not None:
        request.add_header('Authorization', str.format('token {0}', token))

    response = json.loads(urlopen(request).read())
    for release in response:
        if release['prerelease'] is True:
            continue

        version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components(
            release['name'])
        assets = release['assets']

        if version is None or os_ext:
            continue

        if args.major == major:
            for asset in assets:
                match = asset_pattern.match(asset['name'])

                if match is not None:
                    asset_image_type = match.group(1)
                    asset_os = match.group(3)

                    if asset_os == 'linux-x64' and asset_image_type == 'jre':
                        buildpack_version = ''
                        parts = version_part.split('.')
                        num_parts = len(parts)
                        if num_parts == 3:
                            buildpack_version = str.format(
                                '{0}_', version_part)
                        elif num_parts < 3:
                            buildpack_version = str.format(
                                '{0}{1}_', version_part,
                                '.0' * (3 - num_parts))
                        elif num_parts > 3:
                            buildpack_version = str.format(
                                '{0}.{1}.{2}_{3}', parts[0], parts[1],
                                parts[2], parts[3])

                        buildpack_version += str.format('b{0}', build_number)

                        if sap_build_number:
                            buildpack_version += str.format(
                                's{0}', sap_build_number)

                        asset_map[buildpack_version] = asset[
                            'browser_download_url']

    local_repo = join(os.getcwd(), 'gh-pages')
    utils.git_clone('github.com/SAP/SapMachine.git', 'gh-pages', local_repo)
    write_index_yaml(
        asset_map,
        join(local_repo, 'assets', 'cf', 'jre', args.major, 'linux', 'x86_64'))
    utils.git_commit(local_repo, 'Updated index.yml', ['assets'])
    utils.git_push(local_repo)
    utils.remove_if_exists(local_repo)
def main(argv=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('-t',
                        '--tag',
                        help='the SapMachine tag',
                        metavar='MAJOR',
                        required=True)
    parser.add_argument('-d',
                        '--description',
                        help='the description of the release',
                        required=False)
    parser.add_argument('-p',
                        '--prerelease',
                        help='this is a pre-release',
                        action='store_true',
                        default=False)
    parser.add_argument('-a',
                        '--asset',
                        help='the asset to upload',
                        metavar='ASSET',
                        required=False)
    args = parser.parse_args()

    tag = args.tag
    prerelease = args.prerelease
    asset_file = args.asset
    description = '' if args.description is None else args.description

    if asset_file is not None:
        asset_file = os.path.realpath(asset_file)
        asset_name = os.path.basename(asset_file)
        asset_mime_type = mimetypes.guess_type(asset_file)

        if asset_mime_type is None:
            asset_mime_type = 'application/octet-stream'
            print(
                str.format('could not detect mime-type: falling back to "{0}"',
                           asset_mime_type))
        else:
            asset_mime_type = asset_mime_type[0]
            print(str.format('detected mime-type "{0}"', asset_mime_type))

    request = create_request('releases')
    response = json.loads(urlopen(request).read())

    release_id = None
    upload_url = None

    for release in response:
        if release['tag_name'] == tag:
            release_id = release['id']
            upload_url = release['upload_url']
            break

    if release_id is None:
        '''
        release does not exist yet -> create it
        '''
        data = json.dumps({
            "tag_name": tag,
            "name": tag,
            "body": description,
            "draft": False,
            "prerelease": prerelease
        })
        request = create_request('releases', data=data, method='POST')
        request.add_header('Content-Type', 'application/json')
        response = json.loads(urlopen(request).read())
        release_id = response['id']
        upload_url = response['upload_url']
        print(str.format('created release "{0}"', tag))

    if asset_file is not None:
        '''
        asset file is specified (-a)
        first check wether the asset already exists
        '''
        request = create_request(str.format('releases/{0}/assets', release_id))
        response = json.loads(urlopen(request).read())

        for asset in response:
            if asset['name'] == asset_name:
                '''
                asset already exists -> delete it
                '''
                print(
                    str.format('deleting already existing asset "{0}" ...',
                               asset_name))
                asset_id = asset['id']
                request = create_request(str.format('releases/assets/{0}',
                                                    asset_id),
                                         method='DELETE')
                urlopen(request).read()
                break

        upload_url = str(
            upload_url.split('{', 1)[0] + '?name=' + quote(asset_name))
        '''
        read the contents of the asset file
        '''
        with open(asset_file, 'rb') as asset_file:
            asset_data = asset_file.read()
            asset_length = len(asset_data)

        retry = 2

        while retry > 0:
            try:
                '''
                upload the asset file
                '''
                request = Request(upload_url, data=asset_data)
                request.add_header(
                    'Authorization',
                    str.format('token {0}',
                               utils.get_github_api_accesstoken()))
                request.add_header('Content-Type', asset_mime_type)
                request.add_header('Content-Length', str(asset_length))
                print(
                    str.format(
                        'uploading asset "{0}" with a length of {1} bytes ...',
                        asset_name, str(asset_length)))
                response = json.loads(urlopen(request).read())
                break
            except IOError:
                _type, value, _traceback = sys.exc_info()
                print(
                    str.format('Error uploading asset "{0}": {1}', asset_name,
                               value.strerror))
                retry -= 1