diff --git a/confirm b/confirm index 06efbe6cf444b..0580e406b72ea 100755 --- a/confirm +++ b/confirm @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information @@ -15,6 +15,12 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +set -euo pipefail + +if [[ "${ASSUME_YES:=false}" == "true" ]]; then + exit 0 +fi + read -r -p "${1}. Are you sure? [y/N] " response case "$response" in [yY][eE][sS]|[yY]) diff --git a/scripts/ci/_utils.sh b/scripts/ci/_utils.sh index ca8768e15ad36..43dab54874f2a 100644 --- a/scripts/ci/_utils.sh +++ b/scripts/ci/_utils.sh @@ -18,7 +18,7 @@ # Assume all the scripts are sourcing the _utils.sh from the scripts/ci directory # and MY_DIR variable is set to this directory -AIRFLOW_SOURCES=$(cd ${MY_DIR}/../../ && pwd) +AIRFLOW_SOURCES=$(cd "${MY_DIR}/../../" && pwd) export AIRFLOW_SOURCES BUILD_CACHE_DIR="${AIRFLOW_SOURCES}/.build" @@ -32,16 +32,17 @@ Dockerfile \ airflow/version.py " -mkdir -p ${AIRFLOW_SOURCES}/.mypy_cache -mkdir -p ${AIRFLOW_SOURCES}/logs -mkdir -p ${AIRFLOW_SOURCES}/tmp +mkdir -p "${AIRFLOW_SOURCES}/.mypy_cache" +mkdir -p "${AIRFLOW_SOURCES}/logs" +mkdir -p "${AIRFLOW_SOURCES}/tmp" # Disable writing .pyc files - slightly slower imports but not messing around when switching # Python version and avoids problems with root-owned .pyc files in host export PYTHONDONTWRITEBYTECODE="true" # Read default branch name -. ${AIRFLOW_SOURCES}/hooks/_default_branch.sh +# shellcheck source=../../hooks/_default_branch.sh +. "${AIRFLOW_SOURCES}/hooks/_default_branch.sh" # Default branch name for triggered builds is the one configured in hooks/_default_branch.sh export AIRFLOW_CONTAINER_BRANCH_NAME=${AIRFLOW_CONTAINER_BRANCH_NAME:=${DEFAULT_BRANCH}} @@ -328,11 +329,10 @@ EOF check_if_docker_build_is_needed if [[ "${AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED}" == "true" ]]; then - SKIP_REBUILD="false" + local SKIP_REBUILD="false" if [[ ${CI:=} != "true" ]]; then set +e - ${MY_DIR}/../../confirm "The image might need to be rebuild. This will take short time" - if [[ $? != "0" ]]; then + if ! "${MY_DIR}/../../confirm" "The image might need to be rebuild."; then SKIP_REBUILD="true" fi set -e @@ -400,15 +400,25 @@ EOF check_if_docker_build_is_needed if [[ "${AIRFLOW_CONTAINER_DOCKER_BUILD_NEEDED}" == "true" ]]; then - echo - echo "Rebuilding image" - echo - # shellcheck source=../../hooks/build - ./hooks/build | tee -a "${OUTPUT_LOG}" - update_all_md5_files - echo - echo "Image rebuilt" - echo + local SKIP_REBUILD="false" + if [[ ${CI:=} != "true" ]]; then + set +e + if ! "${MY_DIR}/../../confirm" "The image might need to be rebuild."; then + SKIP_REBUILD="true" + fi + set -e + fi + if [[ ${SKIP_REBUILD} != "true" ]]; then + echo + echo "Rebuilding image" + echo + # shellcheck source=../../hooks/build + ./hooks/build | tee -a "${OUTPUT_LOG}" + update_all_md5_files + echo + echo "Image rebuilt" + echo + fi else echo echo "No need to rebuild the image as none of the sensitive files changed: ${FILES_FOR_REBUILD_CHECK}" diff --git a/scripts/ci/local_ci_build.sh b/scripts/ci/local_ci_build.sh index 20d526f7beea5..7c3d56c4786ff 100755 --- a/scripts/ci/local_ci_build.sh +++ b/scripts/ci/local_ci_build.sh @@ -31,6 +31,8 @@ basic_sanity_checks script_start +export ASSUME_YES="true" + rebuild_image_if_needed_for_tests rebuild_image_if_needed_for_static_checks diff --git a/scripts/ci/local_ci_pull_and_build.sh b/scripts/ci/local_ci_pull_and_build.sh index a05afbbfc0680..1e9a5c9579ef7 100755 --- a/scripts/ci/local_ci_pull_and_build.sh +++ b/scripts/ci/local_ci_pull_and_build.sh @@ -33,6 +33,7 @@ script_start export AIRFLOW_CONTAINER_FORCE_PULL_IMAGES="true" export AIRFLOW_CONTAINER_SKIP_LATEST_PYTHON_PULL="true" +export ASSUME_YES="true" rebuild_image_if_needed_for_tests