Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
pull_request:
branches:
- main
- preview
# Trigger workflow on GitHub merge queue events
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group
merge_group:
Expand Down Expand Up @@ -62,6 +63,7 @@ jobs:
- name: Run docs
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: docs
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand Down Expand Up @@ -91,6 +93,7 @@ jobs:
- name: Run docs
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: docs
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand Down Expand Up @@ -118,6 +121,7 @@ jobs:
- name: Run docfx
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: docfx
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand Down Expand Up @@ -147,6 +151,7 @@ jobs:
- name: Run docfx
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: docfx
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
pull_request:
branches:
- main
- preview
# Trigger workflow on GitHub merge queue events
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group
merge_group:
Expand Down Expand Up @@ -33,6 +34,7 @@ jobs:
- name: Run lint
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: lint
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand All @@ -41,6 +43,7 @@ jobs:
- name: Run lint_setup_py
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: lint_setup_py
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand All @@ -67,6 +70,7 @@ jobs:
- name: Run mypy
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: mypy
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ on:
pull_request:
branches:
- main
- preview
# Trigger workflow on GitHub merge queue events
# See https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#merge_group
merge_group:
Expand Down Expand Up @@ -40,6 +41,7 @@ jobs:
env:
COVERAGE_FILE: .coverage-${{ matrix.python }}
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: unit
PY_VERSION: ${{ matrix.python }}
run: |
Expand Down Expand Up @@ -76,6 +78,7 @@ jobs:
- name: Run ${{ matrix.option }} tests
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: ${{ matrix.option }}
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand Down Expand Up @@ -107,6 +110,7 @@ jobs:
- name: Run ${{ matrix.option }} tests
env:
BUILD_TYPE: presubmit
TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref }}
TEST_TYPE: ${{ matrix.option }}
# TODO(https://github.com/googleapis/google-cloud-python/issues/13775): Specify `PY_VERSION` rather than relying on the default python version of the nox session.
PY_VERSION: "unused"
Expand Down
13 changes: 7 additions & 6 deletions ci/run_conditional_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,26 @@
set -eo pipefail

export PROJECT_ROOT=$(realpath $(dirname "${BASH_SOURCE[0]}")/..)
TARGET_BRANCH="${TARGET_BRANCH:-main}"

# A script file for running the test in a sub project.
test_script="${PROJECT_ROOT}/ci/run_single_test.sh"

if [ ${BUILD_TYPE} == "presubmit" ]; then
if [[ ${BUILD_TYPE} == "presubmit" ]]; then
# For presubmit build, we want to know the difference from the
# common commit in origin/main.
GIT_DIFF_ARG="origin/main..."
# common commit in the target branch.
GIT_DIFF_ARG="origin/$TARGET_BRANCH..."

# Then fetch enough history for finding the common commit.
git fetch origin main --deepen=200
git fetch origin "$TARGET_BRANCH" --deepen=200

elif [ ${BUILD_TYPE} == "continuous" ]; then
elif [[ ${BUILD_TYPE} == "continuous" ]]; then
# For continuous build, we want to know the difference in the last
# commit. This assumes we use squash commit when merging PRs.
GIT_DIFF_ARG="HEAD~.."

# Then fetch one last commit for getting the diff.
git fetch origin main --deepen=1
git fetch origin "$TARGET_BRANCH" --deepen=1
Comment on lines +42 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve maintainability and reduce code duplication, this conditional logic can be refactored. By setting a FETCH_DEPTH variable within the if/elif blocks, you can use a single git fetch command afterwards. This makes the script's intent clearer and easier to modify in the future.

Suggested change
if [[ ${BUILD_TYPE} == "presubmit" ]]; then
# For presubmit build, we want to know the difference from the
# common commit in origin/main.
GIT_DIFF_ARG="origin/main..."
# common commit in the target branch.
GIT_DIFF_ARG="origin/$TARGET_BRANCH..."
# Then fetch enough history for finding the common commit.
git fetch origin main --deepen=200
git fetch origin "$TARGET_BRANCH" --deepen=200
elif [ ${BUILD_TYPE} == "continuous" ]; then
elif [[ ${BUILD_TYPE} == "continuous" ]]; then
# For continuous build, we want to know the difference in the last
# commit. This assumes we use squash commit when merging PRs.
GIT_DIFF_ARG="HEAD~.."
# Then fetch one last commit for getting the diff.
git fetch origin main --deepen=1
git fetch origin "$TARGET_BRANCH" --deepen=1
FETCH_DEPTH=""
if [[ ${BUILD_TYPE} == "presubmit" ]]; then
# For presubmit build, we want to know the difference from the
# common commit in the target branch.
GIT_DIFF_ARG="origin/$TARGET_BRANCH..."
FETCH_DEPTH=200
elif [[ ${BUILD_TYPE} == "continuous" ]]; then
# For continuous build, we want to know the difference in the last
# commit. This assumes we use squash commit when merging PRs.
GIT_DIFF_ARG="HEAD~.."
FETCH_DEPTH=1
fi
if [[ -n "${FETCH_DEPTH}" ]]; then
# Fetch enough history for getting the diff.
git fetch origin "$TARGET_BRANCH" --deepen="${FETCH_DEPTH}"
fi


else
# Run everything.
Expand Down
Loading