diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 392f5ece6270..e59727813fc4 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -59,21 +59,33 @@ jobs: steps: - name: Checkout uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 - # Use a fetch-depth of 2 to avoid error `fatal: origin/main...HEAD: no merge base` - # See https://github.com/googleapis/google-cloud-python/issues/12013 - # and https://github.com/actions/checkout#checkout-head. with: - fetch-depth: 2 + # Use fetch-depth of 0 (full history) so Git can find the merge-base with the + # target branch and calculate the exact list of modified packages. + fetch-depth: 0 persist-credentials: false + # We must explicitly fetch and set the target branch reference (main, etc.) + # to perform a relative diff (target_branch...HEAD). Comparing against a generic "HEAD~1" + # is fragile and fails if developers merge main back into their PR, if the PR has + # multiple commits, or if running inside a Merge Queue (merge_group) environment. + - name: Set target branch ref + id: target + env: + TARGET_BRANCH: ${{ github.base_ref || github.event.merge_group.base_ref || 'main' }} + run: | + git fetch origin $TARGET_BRANCH + echo "branch=origin/$TARGET_BRANCH" >> "$GITHUB_OUTPUT" - name: Setup Python uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 with: python-version: "3.10" - name: Set number of files changes in packages and preview-packages directories id: packages + env: + TARGET_BRANCH_REF: ${{ steps.target.outputs.branch }} run: | - git diff HEAD~1 -- packages preview-packages > /dev/null - num_files_changed=$(git diff HEAD~1 -- packages preview-packages | wc -l | tr -d ' ') + git diff "$TARGET_BRANCH_REF"...HEAD -- packages preview-packages > /dev/null + num_files_changed=$(git diff "$TARGET_BRANCH_REF"...HEAD -- packages preview-packages | wc -l | tr -d ' ') echo "num_files_changed=${num_files_changed}" >> "$GITHUB_OUTPUT" - name: Install coverage if: ${{ steps.packages.outputs.num_files_changed > 0 }} @@ -91,9 +103,11 @@ jobs: # TODO: default to 100% coverage after next gapic-generator release # https://github.com/googleapis/google-cloud-python/issues/17459 DEFAULT_FAIL_UNDER: 99 + TARGET_BRANCH_REF: ${{ steps.target.outputs.branch }} run: | + target_ref="$TARGET_BRANCH_REF" # Find all modified packages - modified_packages=$(git diff --name-only HEAD~1 -- packages preview-packages | cut -d/ -f1,2 | sort -u) + modified_packages=$(git diff --name-only ${target_ref}...HEAD -- packages preview-packages | cut -d/ -f1,2 | sort -u) existing_modified_packages=() for pkg in ${modified_packages}; do @@ -122,7 +136,7 @@ jobs: fi # Find all modified packages - modified_packages=$(git diff --name-only HEAD~1 -- packages preview-packages | cut -d/ -f1,2 | sort -u) + modified_packages=$(git diff --name-only ${target_ref}...HEAD -- packages preview-packages | cut -d/ -f1,2 | sort -u) failed_packages=() passed_packages=() diff --git a/packages/bigquery-magics/MANIFEST.in b/packages/bigquery-magics/MANIFEST.in index d6814cd60037..2257d978dbf2 100644 --- a/packages/bigquery-magics/MANIFEST.in +++ b/packages/bigquery-magics/MANIFEST.in @@ -23,3 +23,4 @@ global-exclude __pycache__ # Exclude scripts for samples readmegen prune scripts/readme-gen + diff --git a/packages/db-dtypes/pytest.ini b/packages/db-dtypes/pytest.ini index dbe13ba38624..6c1de90e70e0 100644 --- a/packages/db-dtypes/pytest.ini +++ b/packages/db-dtypes/pytest.ini @@ -5,3 +5,4 @@ filterwarnings = # Remove once https://github.com/googleapis/python-db-dtypes-pandas/issues/227 is fixed ignore:.*any.*with datetime64 dtypes is deprecated and will raise in a future version:FutureWarning ignore:.*all.*with datetime64 dtypes is deprecated and will raise in a future version:FutureWarning +