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
Example #2
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 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]))
Example #4
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)
Example #5
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
def main(argv=None):
    print("Querying GitHub for SapMachine releases...")
    sys.stdout.flush()
    releases = utils.get_github_releases()
    print("Done.")

    asset_pattern = re.compile(utils.sapmachine_asset_pattern())
    release_dict = {}
    for release in releases:
        sapMachineTag = SapMachineTag.from_string(release['name'])

        if sapMachineTag is None:
            print(str.format("{0} is no SapMachine release, dropping", release['name']))
            continue

        major = sapMachineTag.get_major()
        if not major in release_dict:
            sapMachineVersion = SapMachineMajorVersion(major)
            release_dict[major] = sapMachineVersion
        else:
            sapMachineVersion = release_dict[major]

        sapMachineRelease = sapMachineVersion.get_release_object_to_update_if_tag_is_newer(sapMachineTag, release['prerelease'], release['html_url'])

        if sapMachineRelease is None:
            continue

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

            if match is None:
                continue

            image_type = match.group(1)
            os = match.group(3)
            file_type = match.group(4)

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

            if os == 'macos-x64' or os == 'osx-x64':
                if file_type == '.dmg':
                    os = 'macos-x64-installer'
                else:
                    os = 'macos-x64'

            if os == 'macos-aarch64' or os == 'osx-aarch64':
                if file_type == '.dmg':
                    os = 'macos-aarch64-installer'
                else:
                    os = 'macos-aarch64'

            sapMachineRelease.add_asset(image_type, os, asset['browser_download_url'])

    # reduce releases dictionary by removing obsolete versions
    # Keep LTS versions, latest release and the release that is currently in development
    latest_released_version = 0
    for major in list(release_dict.keys()):
        if not release_dict[major].is_released():
            continue
        if major > latest_released_version:
            if latest_released_version > 0 and not release_dict[latest_released_version].is_lts():
                del release_dict[latest_released_version]
            latest_released_version = major
        elif not release_dict[major].is_lts():
            del release_dict[major]

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

    for major in release_dict:
        release_dict[major].add_to_release_json(json_root)

    for image_type in image_type_description:
        json_root['imageTypes'].append({'key': image_type, 'value': image_type_description[image_type]['name'], 'ordinal': image_type_description[image_type]['ordinal']})

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

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

    for major in release_dict:
        if not release_dict[major].is_released():
            continue

        files.append({
            'location': join('latest', str(major), 'index.md'),
            'data': Template(latest_template).substitute(
                major = major,
                url = release_dict[major].release.url
            ),
            'commit_message': str.format('Updated latest link for SapMachine {0}', major)
        })

    push_to_git(files)

    return 0
Example #8
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)