def process_release(release, prefix, tags, git_dir): version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components( release['name']) tag_name = str.format('{0}-{1}', prefix, version_part) skip_tag = False dockerfile_dir = join(git_dir, 'dockerfiles', 'official', prefix) for tag in tags: if tag['name'] == tag_name: print( str.format('tag "{0}" already exists for release "{1}"', tag_name, release['name'])) skip_tag = True break if not skip_tag: dockerfile_path = join(dockerfile_dir, 'Dockerfile') with open(dockerfile_path, 'w+') as dockerfile: dockerfile.write( Template(dockerfile_template).substitute(version=str.format( 'sapmachine-{0}-jdk={1}', major, version_part))) utils.git_commit(git_dir, 'updated Dockerfile', [dockerfile_path]) utils.git_tag(git_dir, tag_name) utils.git_push(git_dir) utils.git_push_tag(git_dir, tag_name)
def test_git_push_no_changes(self): # Create a directory for this test test_dir = os.path.join(self.temp_root_dir, 'test_git_push_no_changes') if not os.path.exists(test_dir): os.makedirs(test_dir) # Create a shared_directory for files inside this test_dir shared_directory = os.path.join(test_dir, 'source_files/en') if not os.path.exists(shared_directory): os.makedirs(shared_directory) # Set up a git repository to use during testing temp_repo = Repo.init(test_dir) # Create a dummy file and commit it to start the repo history f = os.path.join(test_dir, "DUMMY") open(f, 'wb').close() temp_repo.index.add([f]) temp_repo.index.commit("FOO") # Call git_push using the test_dir and have it write to the log log = io.StringIO() utils.git_push(test_dir, log=log, enable_push=False) # Close the repo temp_repo.close() # TEST: When no uncommited changes have been made to the repo, # it logs the NO_CHANGES_MESSAGE self.assertEqual(log.getvalue(), utils.NO_CHANGES_MESSAGE)
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
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 push_to_git(files): local_repo = join(os.getcwd(), 'gh-pages') utils.git_clone('github.com/SAP/SapMachine.git', 'gh-pages', local_repo) for _file in files: location = join(local_repo, _file['location']) if not os.path.exists(os.path.dirname(location)): os.makedirs(os.path.dirname(location)) with open(location, 'w+') as out: out.write(_file['data']) utils.git_commit(local_repo, _file['commit_message'], [location]) utils.git_push(local_repo) utils.remove_if_exists(local_repo)
def main(): translation_mapping = None with open(os.environ.get('GOOGLE_DRIVE_CONFIG')) as f: translation_mapping = yaml.load(f) # Generate secrets, if not already generated service_drive = generate_secrets('drive') service_docs = generate_secrets('docs') # Find ids of all Google docs in the raw Serge folder print("Finding documents") file_ids = [] page_token = None while True: response = service_drive.files().list( spaces='drive', fields='nextPageToken, files(id, name, parents)', pageToken=page_token).execute() for file_content in response.get('files', []): # Process change file_parents = file_content.get('parents') if file_parents and translation_mapping['language_folders'][ 'en'] in file_parents: print( f"Found file {file_content.get('name')} with id {file_content.get('id')} and parents {file_content.get('parents')}" ) file_id = file_content.get('id') file_ids.append(file_id) page_token = response.get('nextPageToken', None) if page_token is None: break print("Obtaining document contents") # For each file, get contents for file_id in file_ids: result = service_docs.documents().get(documentId=file_id).execute() # Remove newline and non-ASCII apostrophe characters # For Google doc transcribing to look correct result = json.loads( json.dumps(result).replace('\\n', '').replace('\\u2019', "'")) filename = f"{ROOT_PATH}/{SOURCE_PATH}/{result.get('title')}.json" with open(filename, 'w') as outfile: json.dump(result, outfile) # Push shared repository to Git if any files changed utils.git_push(utils.PROJECT_ROOT_GIT_PATH, commit_message="Update shared repository: Google docs", enable_push=True)
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 process_release(release, tags, git_dir): version, version_part, major, update, version_sap, build_number, os_ext = utils.sapmachine_tag_components( release['name']) tag_name = version_part skip_tag = False dockerfile_dir = join(git_dir, 'dockerfiles', 'official', major) for tag in tags: if tag['name'] == tag_name: print( str.format('tag "{0}" already exists for release "{1}"', tag_name, release['name'])) skip_tag = True break if not skip_tag: utils.remove_if_exists(dockerfile_dir) os.makedirs(dockerfile_dir) dockerfile_path = join(dockerfile_dir, 'Dockerfile') with open(dockerfile_path, 'w+') as dockerfile: dockerfile.write( Template(dockerfile_template).substitute(version=str.format( 'sapmachine-{0}-jdk={1}', major, version_part), major=major)) if utils.sapmachine_is_lts(major): what = 'long term support' docker_tag = major else: what = 'stable' docker_tag = 'stable' readme_path = join(dockerfile_dir, 'README.md') with open(readme_path, 'w+') as readmefile: readmefile.write( Template(readmefile_template).substitute(docker_tag=docker_tag, what=what, major=major, version=version_part)) utils.git_commit(git_dir, 'updated Dockerfile', [dockerfile_path, readme_path]) utils.git_tag(git_dir, tag_name) utils.git_push(git_dir) utils.git_push_tag(git_dir, tag_name)
def do_work(): for post in get_posts(): """ Example wp link: 'https://ctoassetsstg.wpengine.com/es/2020/10/09/aditya-another-test-post/' If there is a locale specified like `es` in the above link, then we do not want to import it as it is an already translated post. Note: This logic does not support a non-english source language. """ split_link = post['link'].split('/') if len(split_link[3]) == 2: print( f"Will not import translated post - ID: {post['id']} Title: {post['title']} Link: {post['link']}" ) continue write_post(post) utils.git_push(utils.PROJECT_ROOT_GIT_PATH, commit_message="Update shared repository: wordpress", enable_push=True, origin='import-wp')
def main(args): print("Updating data ...") if args.source == 'csse': print(" from csse github repo...") df = get_historic_data_from_CSSE_gh_repo() df.to_csv(DATA_CSV_PATH, index=False) elif args.source == 'anss': print(" from anss website") df = pd.read_csv(DATA_CSV_PATH) new_line_of_data = scraping_anss() df = update_data(df, new_line_of_data) df.to_csv(DATA_CSV_PATH, index=False) else: raise ('This parameter can only take "anss", or "csse"') print(" file saved to ".format(DATA_CSV_PATH)) evol_bars_fig = evolution_bars_plot(df) print("Creating Cumulated evolution bars plot...") cumul_fig = cumul_plot(df) print("Creating Daily evolution bars plot") daily_fig = daily_plot(df) figs = [evol_bars_fig] print("Creating index.html, cumul.html, daily.html files... ") create_index_html(figs) create_html(cumul_fig, CUMUL_HTML_PATH) create_html(daily_fig, DAILY_HTML_PATH) print("Pushing updates to github...") git_push() print("Done.")
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('-a', '--asset', help='the SapMachine asset file', metavar='ASSET', required=True) parser.add_argument('-j', '--jre', help='Build SapMachine JRE installer', action='store_true', default=False) parser.add_argument('-s', '--sapmachine-directory', help='specify the SapMachine GIT directory', metavar='DIR', required=True) args = parser.parse_args() cwd = os.getcwd() work_dir = join(cwd, 'msi_work') asset = os.path.realpath(args.asset) is_jre = args.jre sapmachine_git_dir = args.sapmachine_directory products = None product_id = None upgrade_code = None utils.remove_if_exists(work_dir) os.makedirs(work_dir) utils.extract_archive(asset, work_dir, remove_archive=False) sapmachine_folder = glob.glob(join(work_dir, 'sapmachine*')) os.rename(sapmachine_folder[0], join(work_dir, 'SourceDir')) _, _, version_output = utils.run_cmd( [join(work_dir, 'SourceDir', 'bin', 'java.exe'), '-version'], std=True) version, version_part, major, version_sap, build_number = utils.sapmachine_version_components( version_output, multiline=True) sapmachine_version = [e for e in version_part.split('.')] if len(sapmachine_version) < 3: sapmachine_version += [ '0' for sapmachine_version in range(0, 3 - len(sapmachine_version)) ] if len(sapmachine_version) == 4: sapmachine_version[3] = str((int(sapmachine_version[3]) << 8) & 0xFF00) if len(sapmachine_version) == 5: merged_version = str((int(sapmachine_version[3]) << 8) | (int(sapmachine_version[4]) & 0xFF)) del sapmachine_version[4] sapmachine_version[3] = merged_version sapmachine_version = '.'.join(sapmachine_version) shutil.copyfile( join(sapmachine_git_dir, 'src', 'java.base', 'windows', 'native', 'launcher', 'icons', 'awt.ico'), join(work_dir, 'sapmachine.ico')) write_as_rtf(join(sapmachine_git_dir, 'LICENSE'), join(work_dir, 'license.rtf')) infrastructure_dir = join(work_dir, 'sapmachine_infrastructure') templates_dir = join(infrastructure_dir, 'wix-templates') utils.git_clone('github.com/SAP/SapMachine-infrastructure', 'master', infrastructure_dir) with open(join(templates_dir, 'products.yml'), 'r') as products_yml: products = yaml.safe_load(products_yml.read()) image_type = 'jre' if is_jre else 'jdk' if products[image_type] is None or major not in products[image_type]: product_id = str(uuid.uuid4()) upgrade_code = str(uuid.uuid4()) if products[image_type] is None: products[image_type] = {} products[image_type][major] = { 'product_id': product_id, 'upgrade_code': upgrade_code } with open(join(templates_dir, 'products.yml'), 'w') as products_yml: products_yml.write(yaml.dump(products, default_flow_style=False)) utils.git_commit(infrastructure_dir, 'Updated product codes.', [join('wix-templates', 'products.yml')]) utils.git_push(infrastructure_dir) else: product_id = products[image_type][major]['product_id'] upgrade_code = products[image_type][major]['upgrade_code'] create_sapmachine_wxs( join( templates_dir, 'SapMachine.jre.wxs.template' if is_jre else 'SapMachine.jdk.wxs.template'), join(work_dir, 'SapMachine.wxs'), product_id, upgrade_code, sapmachine_version, major) shutil.copyfile(join(work_dir, 'SourceDir', 'release'), join(work_dir, 'release')) utils.remove_if_exists(join(work_dir, 'SourceDir', 'release')) utils.run_cmd( 'heat dir SourceDir -swall -srd -gg -platform x64 -template:module -cg SapMachineGroup -out SapMachineModule.wxs' .split(' '), cwd=work_dir) with open(join(work_dir, 'SapMachineModule.wxs'), 'r+') as sapmachine_module: sapmachine_module_content = sapmachine_module.read() sapmachine_module_content = sapmachine_module_content.replace( 'PUT-MODULE-NAME-HERE', 'SapMachineModule') sapmachine_module_content = sapmachine_module_content.replace( 'PUT-COMPANY-NAME-HERE', 'SapMachine Team') sapmachine_module.seek(0) sapmachine_module.truncate() sapmachine_module.write(sapmachine_module_content) utils.run_cmd('candle -arch x64 SapMachineModule.wxs'.split(' '), cwd=work_dir) utils.run_cmd('light SapMachineModule.wixobj'.split(' '), cwd=work_dir) utils.run_cmd('candle -arch x64 SapMachine.wxs'.split(' '), cwd=work_dir) utils.run_cmd('light -ext WixUIExtension SapMachine.wixobj'.split(' '), cwd=work_dir) msi_name = os.path.basename(asset) msi_name = os.path.splitext(msi_name)[0] os.rename(join(work_dir, 'SapMachine.msi'), join(cwd, str.format('{0}.msi', msi_name))) return 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='TAG', required=True) parser.add_argument('--sha256sum', help='the sha256 sum', metavar='SHA256', required=True) parser.add_argument('-i', '--imagetype', help='The image type', metavar='IMAGETYPE', choices=['jdk', 'jre']) parser.add_argument('-p', '--prerelease', help='this is a pre-release', action='store_true', default=False) args = parser.parse_args() cwd = os.getcwd() work_dir = join(cwd, 'cask_work') tag = args.tag sha256sum = args.sha256sum image_type = args.imagetype is_prerelease = args.prerelease cask_version_pattern = re.compile('version \'((\d+\.?)+)(,(\d+))?\'') utils.remove_if_exists(work_dir) os.makedirs(work_dir) version, version_part, major, build_number, sap_build_number, os_ext = utils.sapmachine_tag_components( tag) if is_prerelease: if build_number is None: print('No build number given. Aborting ...') sys.exit() cask_content = Template(pre_release_cask_template).substitute( MAJOR=major, VERSION=version_part, BUILD_NUMBER=build_number, IMAGE_TYPE=image_type, SHA256=sha256sum) cask_file_name = str.format('sapmachine{0}-ea-{1}.rb', major, image_type) else: cask_content = Template(release_cask_template).substitute( MAJOR=major, VERSION=version_part, IMAGE_TYPE=image_type, SHA256=sha256sum) cask_file_name = str.format('sapmachine{0}-{1}.rb', major, image_type) homebrew_dir = join(work_dir, 'homebrew') cask_dir = join(homebrew_dir, 'Casks') utils.git_clone('github.com/SAP/homebrew-SapMachine', 'master', homebrew_dir) current_cask_version = None current_cask_build_number = None if os.path.exists(join(cask_dir, cask_file_name)): with open(join(cask_dir, cask_file_name), 'r') as cask_file: cask_version_match = cask_version_pattern.search(cask_file.read()) if cask_version_match is not None: if len(cask_version_match.groups()) >= 1: current_cask_version = cask_version_match.group(1) if len(cask_version_match.groups()) >= 4: current_cask_build_number = cask_version_match.group(4) current_cask_version = version_to_tuple(current_cask_version, current_cask_build_number) new_cask_version = version_to_tuple(version_part, build_number) if new_cask_version >= current_cask_version: with open(join(cask_dir, cask_file_name), 'w') as cask_file: cask_file.write(cask_content) utils.git_commit(homebrew_dir, str.format('Updated {0}.', cask_file_name), [join('Casks', cask_file_name)]) utils.git_push(homebrew_dir) return 0
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('-t', '--tag', help='the SapMachine tag', metavar='TAG', required=True) parser.add_argument('--sha256sum', help='the sha256 sum', metavar='SHA256', required=True) parser.add_argument('-i', '--imagetype', help='The image type', metavar='IMAGETYPE', choices=['jdk', 'jre']) parser.add_argument('-p', '--prerelease', help='this is a pre-release', action='store_true', default=False) args = parser.parse_args() work_dir = join(os.getcwd(), 'cask_work') utils.remove_if_exists(work_dir) os.makedirs(work_dir) cask_version_pattern = re.compile('version \'((\d+\.?)+)(,(\d+))?\'') sapMachineTag = SapMachineTag.from_string(args.tag) if sapMachineTag is None: print(str.format("Tag {0} seems to be invalid. Aborting...", args.tag)) sys.exit() if args.prerelease: if sapMachineTag.get_build_number() is None: print('No build number given for pre-release. Aborting ...') sys.exit() cask_content = Template(pre_release_cask_template).substitute( MAJOR=sapMachineTag.get_major(), VERSION=sapMachineTag.get_version_string_without_build(), BUILD_NUMBER=sapMachineTag.get_build_number(), IMAGE_TYPE=args.imagetype, SHA256=args.sha256sum) cask_file_name = str.format('sapmachine{0}-ea-{1}.rb', sapMachineTag.get_major(), args.imagetype) else: cask_content = Template(release_cask_template).substitute( MAJOR=sapMachineTag.get_major(), VERSION=sapMachineTag.get_version_string_without_build(), IMAGE_TYPE=args.imagetype, SHA256=args.sha256sum) cask_file_name = str.format('sapmachine{0}-{1}.rb', sapMachineTag.get_major(), args.imagetype) homebrew_dir = join(work_dir, 'homebrew') cask_dir = join(homebrew_dir, 'Casks') cask_file_path = join(cask_dir, cask_file_name) utils.git_clone('github.com/SAP/homebrew-SapMachine', 'master', homebrew_dir) current_cask_version = None current_cask_build_number = None if os.path.exists(cask_file_path): with open(cask_file_path, 'r') as cask_file: cask_version_match = cask_version_pattern.search(cask_file.read()) if cask_version_match is not None: if len(cask_version_match.groups()) >= 1: current_cask_version = cask_version_match.group(1) if len(cask_version_match.groups()) >= 4: current_cask_build_number = cask_version_match.group(4) current_cask_version = versions.version_to_tuple( current_cask_version, current_cask_build_number) if current_cask_version is None or sapMachineTag.get_version_tuple( ) >= current_cask_version: print( str.format("Creating/updating cask for version {0}...", sapMachineTag.get_version_tuple())) with open(cask_file_path, 'w') as cask_file: cask_file.write(cask_content) utils.git_commit( homebrew_dir, str.format('Update {0} ({1}).', cask_file_name, sapMachineTag.get_version_string()), [join('Casks', cask_file_name)]) utils.git_push(homebrew_dir) else: print( str.format( "Current cask has version {0} which is higher than {1}, no update.", current_cask_version, sapMachineTag.get_version_tuple())) return 0
def main(argv=None): parser = argparse.ArgumentParser() parser.add_argument('-t', '--tag', help='the SapMachine tag', metavar='TAG', required=True) parser.add_argument( '-d', '--dual', help='this is going to be a dual architecture cask (x64 and aarch64)', action='store_true', default=False) args = parser.parse_args() work_dir = join(os.getcwd(), 'cask_work') utils.remove_if_exists(work_dir) os.makedirs(work_dir) raw_tag = args.tag sapMachineTag = SapMachineTag.from_string(raw_tag) if sapMachineTag is None: print(str.format("Tag {0} seems to be invalid. Aborting...", args.tag)) sys.exit(1) os_name = 'osx' if sapMachineTag.get_major() < 17 or ( sapMachineTag.get_major() == 17 and sapMachineTag.get_update() is None and sapMachineTag.get_build_number() < 21) else 'macos' prerelease = not sapMachineTag.is_ga() if prerelease: jdk_cask_file_name = str.format('sapmachine{0}-ea-jdk.rb', sapMachineTag.get_major()) jre_cask_file_name = str.format('sapmachine{0}-ea-jre.rb', sapMachineTag.get_major()) cask_tag = str.format('{0}-ea', sapMachineTag.get_major()) cask_version = str.format( '{0},{1}', sapMachineTag.get_version_string_without_build(), sapMachineTag.get_build_number()) ruby_version = 'version.before_comma' ea_ext = '-ea.' url_version1 = '#{version.before_comma}%2B#{version.after_comma}' url_version2 = '#{version.before_comma}-ea.#{version.after_comma}' else: jdk_cask_file_name = str.format('sapmachine{0}-jdk.rb', sapMachineTag.get_major()) jre_cask_file_name = str.format('sapmachine{0}-jre.rb', sapMachineTag.get_major()) cask_tag = str.format('{0}', sapMachineTag.get_major()) cask_version = str.format( '{0}', sapMachineTag.get_version_string_without_build()) ruby_version = 'version' ea_ext = '.' url_version1 = '#{version}' url_version2 = '#{version}' if args.dual: try: aarch_jdk_sha_url, aarch_jre_sha_url = utils.get_asset_url( raw_tag, os_name + '-aarch64', '.sha256.dmg.txt') intel_jdk_sha_url, intel_jre_sha_url = utils.get_asset_url( raw_tag, os_name + '-x64', '.sha256.dmg.txt') except Exception as e: print('Not both platforms ready yet') sys.exit(0) aarch_jdk_sha, code1 = utils.download_asset(aarch_jdk_sha_url) aarch_jre_sha, code2 = utils.download_asset(aarch_jre_sha_url) intel_jdk_sha, code3 = utils.download_asset(intel_jdk_sha_url) intel_jre_sha, code4 = utils.download_asset(intel_jre_sha_url) if code1 != 200 or code2 != 200 or code3 != 200 or code4 != 200: print('Download failed') sys.exit(1) aarch_jdk_sha = aarch_jdk_sha.split(' ')[0] aarch_jre_sha = aarch_jre_sha.split(' ')[0] intel_jdk_sha = intel_jdk_sha.split(' ')[0] intel_jre_sha = intel_jre_sha.split(' ')[0] jdk_cask_content = Template(duplex_cask_template).substitute( CASK_TAG=cask_tag, IMAGE_TYPE='jdk', CASK_VERSION=cask_version, URL_VERSION1=url_version1, URL_VERSION2=url_version2, OS_NAME=os_name, INTELSHA256=intel_jdk_sha, AARCHSHA256=aarch_jdk_sha, RUBY_VERSION=ruby_version, EA_EXT=ea_ext) jre_cask_content = Template(duplex_cask_template).substitute( CASK_TAG=cask_tag, IMAGE_TYPE='jre', CASK_VERSION=cask_version, URL_VERSION1=url_version1, URL_VERSION2=url_version2, OS_NAME=os_name, INTELSHA256=intel_jre_sha, AARCHSHA256=aarch_jre_sha, RUBY_VERSION=ruby_version, EA_EXT=ea_ext) else: try: intel_jdk_sha_url, intel_jre_sha_url = utils.get_asset_url( raw_tag, os_name + '-x64', '.sha256.dmg.txt') except Exception as e: print('Asset not found') sys.exit(1) intel_jdk_sha, code1 = utils.download_asset(intel_jdk_sha_url) intel_jre_sha, code2 = utils.download_asset(intel_jre_sha_url) if code1 != 200 or code2 != 200: print('Download failed') sys.exit(1) intel_jdk_sha = intel_jdk_sha.split(' ')[0] intel_jre_sha = intel_jre_sha.split(' ')[0] try: intel_jdk_url, intel_jre_url = utils.get_asset_url( raw_tag, os_name + '-x64', '.dmg') except Exception as e: print('Asset not found') sys.exit(1) jdk_cask_content = Template(cask_template).substitute( CASK_TAG=cask_tag, IMAGE_TYPE='jdk', CASK_VERSION=cask_version, SHA256=intel_jdk_sha, URL_VERSION1=url_version1, URL_VERSION2=url_version2, OS_NAME=os_name, RUBY_VERSION=ruby_version, EA_EXT=ea_ext) jre_cask_content = Template(cask_template).substitute( CASK_TAG=cask_tag, IMAGE_TYPE='jre', CASK_VERSION=cask_version, SHA256=intel_jre_sha, URL_VERSION1=url_version1, URL_VERSION2=url_version2, OS_NAME=os_name, RUBY_VERSION=ruby_version, EA_EXT=ea_ext) homebrew_dir = join(work_dir, 'homebrew') utils.git_clone('github.com/SAP/homebrew-SapMachine', 'master', homebrew_dir) jdk_replaced = replace_cask(jdk_cask_file_name, jdk_cask_content, sapMachineTag, homebrew_dir) jre_replaced = replace_cask(jre_cask_file_name, jre_cask_content, sapMachineTag, homebrew_dir) if jdk_replaced or jre_replaced: utils.git_push(homebrew_dir) utils.remove_if_exists(work_dir) return 0