Azure / Azure/azure-cli-extensions

CI: Linter/style checks pick up unrelated files due to missing git fetch and no merge-base

Open
#9,714 2 comments 0 reactions 3 assignees Claimed by @bebound View on GitHub
Azure CLI Team bug
Dominant language
Python
Stars
454
Forks
1.7k
Avg merge
2d 19h
Merged PRs (30d)
64

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**

1. Missing `git fetch` for 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, so `origin/` may be stale or absent. Compare to the `AzdevScanModifiedExtensions` jobs (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.

2. No `merge-base` used. The function diffs directly against `origin/`:
```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.

3. No guard for unset env var. `os.environ.get('ADO_PULL_REQUEST_TARGET_BRANCH')` returns `None` when unset, producing `origin/None`. The sibling script `test_source.py` (line 46) checks for the unexpanded ADO macro `$(System.PullRequest.TargetBranch)` and skips gracefully; this script does not.

**Affected Jobs**

- `AzdevStyleModifiedExtensions`
- `AzdevLinterModifiedExtensions`

### 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
```

https://dev.azure.com/azclitools/public/_build/results?buildId=304376&view=logs&j=506b8f13-8269-5210-246e-a3964e53141e&t=db7247cb-300d-5b59-fd6c-6258fad20b89

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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.