ashb commented on a change in pull request #6500: [AIRFLOW-5828] Vastly 
simplify build scripts. Depends on [AIRFLOW-5704] [AIRFLOW-5842]
URL: https://github.com/apache/airflow/pull/6500#discussion_r378382540
 
 

 ##########
 File path: scripts/ci/utils/_run.sh
 ##########
 @@ -0,0 +1,150 @@
+#!/usr/bin/env 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
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Assume AIRFLOW_SOURCES are set to point to sources of Airflow
+
+function _run_ci_script_with_docker() {
+    local SCRIPT="$1"
+    shift
+    FILES=("$@")
+
+    if [[ "${#FILES[@]}" == "0" ]]; then
+        verbose_docker run "${EXTRA_DOCKER_FLAGS[@]}" \
+            --entrypoint "/root/.local/bin/dumb-init"  \
+            --env PYTHONDONTWRITEBYTECODE \
+            --env AIRFLOW_CI_VERBOSE="${VERBOSE}" \
+            --env AIRFLOW_CI_SILENT \
+            --env HOST_USER_ID="$(id -ur)" \
+            --env HOST_GROUP_ID="$(id -gr)" \
+            --rm \
+            "${AIRFLOW_CI_IMAGE}" \
+            "--" "${SCRIPT}" \
+            | tee -a "${OUTPUT_LOG}"
+    else
+        verbose_docker run "${EXTRA_DOCKER_FLAGS[@]}" \
+            --entrypoint "/root/.local/bin/dumb-init"  \
+            --env PYTHONDONTWRITEBYTECODE \
+            --env AIRFLOW_CI_VERBOSE="${VERBOSE}" \
+            --env AIRFLOW_CI_SILENT \
+            --env HOST_USER_ID="$(id -ur)" \
+            --env HOST_GROUP_ID="$(id -gr)" \
+            --rm \
+            "${AIRFLOW_CI_IMAGE}" \
+            "--" "${SCRIPT}" "${FILES[@]}" \
+            | tee -a "${OUTPUT_LOG}"
+    fi
+}
+
+function run_flake8() {
+    _run_ci_script_with_docker 
"/opt/airflow/scripts/ci/in_container/run_flake8.sh" "$@"
+}
+
+function run_isort() {
+    _run_ci_script_with_docker 
"/opt/airflow/scripts/ci/in_container/run_isort.sh" "$@"
+}
+
+
+function run_docs() {
+    _run_ci_script_with_docker "/opt/airflow/docs/build.sh"
+}
+
+function run_check_license() {
+    _run_ci_script_with_docker 
"/opt/airflow/scripts/ci/in_container/run_check_licence.sh"
+}
+
+function run_mypy() {
+    FILES=("$@")
+    if [[ "${#FILES[@]}" == "0" ]]; then
+        _run_ci_script_with_docker 
"/opt/airflow/scripts/ci/in_container/run_mypy.sh" "airflow" "tests" "docs"
+    else
+        _run_ci_script_with_docker 
"/opt/airflow/scripts/ci/in_container/run_mypy.sh" "$@"
+    fi
 
 Review comment:
   A trick you can do to remove the similar-almost identical if/else here:
   
   ```bash
       if [[ $# -eg 0 ]]; then
           set -- airflow" "tests" "docs"
       fi
       _run_ci_script_with_docker 
"/opt/airflow/scripts/ci/in_container/run_mypy.sh" "$@"
   ```
   
   Or if the `set --` is a bit obscure (it sets "$@"/argv), then how about:
   
   ```
       FILES=("$@")
       if [[ "${#FILES[@]}" == "0" ]]; then
           FILES=(airflow tests docs)
       fi
       _run_ci_script_with_docker 
"/opt/airflow/scripts/ci/in_container/run_mypy.sh" "${FILES[@]}"
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to