def build_image_if_needed_steps(verbose: bool, dry_run: bool, shell_params: ShellParams) -> None: """ Check if image build is needed based on what files have been modified since last build. * If build is needed, the user is asked for confirmation * If the branch is not rebased it warns the user to rebase (to make sure latest remote cache is useful) * Builds Image/Skips/Quits depending on the answer :param verbose: print commands when running :param dry_run: do not execute "write" commands - just print what would happen :param shell_params: parameters for the build """ # We import those locally so that click autocomplete works from inputimeout import TimeoutOccurred build_needed = md5sum_check_if_build_is_needed(shell_params.md5sum_cache_dir, shell_params.the_image_type) if not build_needed: return try: answer = user_confirm(message="Do you want to build image?", timeout=5, default_answer=Answer.NO) if answer == answer.YES: if is_repo_rebased(shell_params.github_repository, shell_params.airflow_branch): build_image( verbose, dry_run=dry_run, python=shell_params.python, upgrade_to_newer_dependencies="false", ) else: console.print( "\n[bright_yellow]This might take a lot of time, w" "e think you should rebase first.[/]\n" ) if click.confirm("But if you really, really want - you can do it"): build_image( verbose=verbose, dry_run=dry_run, python=shell_params.python, upgrade_to_newer_dependencies="false", ) else: console.print( "[bright_blue]Please rebase your code before continuing.[/]\n" "Check this link to know more " "https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#id15\n" ) console.print('[red]Exiting the process[/]\n') sys.exit(1) elif answer == Answer.NO: instruct_build_image(shell_params.python) else: # users_status == Answer.QUIT: console.print('\n[bright_yellow]Quitting the process[/]\n') sys.exit() except TimeoutOccurred: console.print('\nTimeout. Considering your response as No\n') instruct_build_image(shell_params.python) except Exception as e: console.print(f'\nTerminating the process on {e}') sys.exit(1)
def should_we_run_the_build(build_ci_params: BuildCiParams) -> bool: """ Check if we should run the build based on what files have been modified since last build and answer from the user. * If build is needed, the user is asked for confirmation * If the branch is not rebased it warns the user to rebase (to make sure latest remote cache is useful) * Builds Image/Skips/Quits depending on the answer :param build_ci_params: parameters for the build """ # We import those locally so that click autocomplete works from inputimeout import TimeoutOccurred if not md5sum_check_if_build_is_needed( md5sum_cache_dir=build_ci_params.md5sum_cache_dir): return False try: answer = user_confirm(message="Do you want to build image?", timeout=5, default_answer=Answer.NO) if answer == answer.YES: if is_repo_rebased(build_ci_params.github_repository, build_ci_params.airflow_branch): return True else: console.print( "\n[bright_yellow]This might take a lot of time, w" "e think you should rebase first.[/]\n") answer = user_confirm( "But if you really, really want - you can do it", timeout=5, default_answer=Answer.NO) if answer == Answer.YES: return True else: console.print( "[bright_blue]Please rebase your code before continuing.[/]\n" "Check this link to know more " "https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#id15\n" ) console.print('[red]Exiting the process[/]\n') sys.exit(1) elif answer == Answer.NO: instruct_build_image(build_ci_params.python) return False else: # users_status == Answer.QUIT: console.print('\n[bright_yellow]Quitting the process[/]\n') sys.exit() except TimeoutOccurred: console.print('\nTimeout. Considering your response as No\n') instruct_build_image(build_ci_params.python) return False except Exception as e: console.print(f'\nTerminating the process on {e}') sys.exit(1)
def build_image_if_needed_steps(verbose: bool, shell_params: ShellBuilder): build_needed = md5sum_check_if_build_is_needed( shell_params.md5sum_cache_dir, shell_params.the_image_type) if build_needed: try: user_status = inputimeout( prompt= '\nDo you want to build image?Press y/n/q in 5 seconds\n', timeout=5, ) if user_status == 'y': latest_sha = get_latest_sha(shell_params.github_repository, shell_params.airflow_branch) if is_repo_rebased(latest_sha): build_image( verbose, python_version=shell_params.python_version, upgrade_to_newer_dependencies="false", ) else: if click.confirm( "\nThis might take a lot of time, we think you should rebase first. \ But if you really, really want - you can do it\n"): build_image( verbose, python_version=shell_params.python_version, upgrade_to_newer_dependencies="false", ) else: console.print( '\nPlease rebase your code before continuing.\ Check this link to know more \ https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#id15\n' ) console.print('Exiting the process') sys.exit() elif user_status == 'n': instruct_build_image(shell_params.the_image_type, shell_params.python_version) elif user_status == 'q': console.print('\nQuitting the process') sys.exit() else: console.print('\nYou have given a wrong choice:', user_status, ' Quitting the process') sys.exit() except TimeoutOccurred: console.print('\nTimeout. Considering your response as No\n') instruct_build_image(shell_params.the_image_type, shell_params.python_version) except Exception: console.print('\nTerminating the process') sys.exit()