-
Notifications
You must be signed in to change notification settings - Fork 1.5k
CI: Linter/style checks pick up unrelated files due to missing git fetch and no merge-base #9714
Description
Describe the bug
The AzdevStyleModifiedExtensions and AzdevLinterModifiedExtensions pipeline jobs report files unrelated to the current PR. This is caused by two issues in how find_modified_files_against_master_branch() in azdev_linter_style.py computes the diff.
Root Cause
-
Missing
git fetchfor the target branch. The linter and style jobs in azure-pipelines.yml never fetch the target branch before running the diff. ADO uses a shallow clone, soorigin/<target_branch>may be stale or absent. Compare to theAzdevScanModifiedExtensionsjobs (lines 193, 224) which correctly do:
- bash: git fetch origin --depth=1 $(System.PullRequest.TargetBranch)
The linter job (line ~157) and style job (line ~131) skip this step entirely. -
No
merge-baseused. The function diffs directly againstorigin/<target_branch>:
cmd = 'git --no-pager diff --name-only --diff-filter=ACMRT {} -- src/'.format(ado_pr_target_branch)
If the target branch has advanced since the PR branch was created, this diff includes changes made on the target branch itself (not part of the PR). The correct approach is to diff against the merge-base of HEAD and the target branch. -
No guard for unset env var.
os.environ.get('ADO_PULL_REQUEST_TARGET_BRANCH')returnsNonewhen unset, producingorigin/None. The sibling scripttest_source.py(line 46) checks for the unexpanded ADO macro$(System.PullRequest.TargetBranch)and skips gracefully; this script does not.
Affected Jobs
AzdevStyleModifiedExtensionsAzdevLinterModifiedExtensions
Related command
N/A
Errors
AZURE_EXTENSION_DIR=~/.azure/cliextensions python scripts/ci/azdev_linter_style.py --type style
azdev type: style
----------------------------------------------------------------------------------------------------
pull request target branch: origin/main
modified files:
----------------------------------------------------------------------------------------------------
src/aks-preview/HISTORY.rst
src/aks-preview/azcli_aks_live_test/configs/ext_matrix_default.json
src/aks-preview/azext_aks_preview/_consts.py
src/aks-preview/azext_aks_preview/_help.py
src/aks-preview/azext_aks_preview/_params.py
src/aks-preview/azext_aks_preview/agentpool_decorator.py
src/aks-preview/azext_aks_preview/custom.py
src/aks-preview/azext_aks_preview/tests/latest/test_agentpool_decorator.py
src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py
src/aks-preview/azext_aks_preview/tests/latest/test_update_agentpool_profile_preview.py
src/index.json
src/oracle-database/HISTORY.rst
src/oracle-database/azext_oracle_database/aaz/latest/oracle_database/autonomous_database/_list.py
src/oracle-database/azext_oracle_database/tests/latest/test_oracle_database_adbs.py
src/oracle-database/setup.py
where the origin branch of PR #9704 does not touch the index.json or oracle-database related files
Issue script & Debug output
N/A
Expected behavior
Changes should not be included if the modified files are unrelated to the PR.
Environment Summary
N/A
Additional context
No response