{CI} Fix merge-base diff in linter, style, and scan jobs#9725
{CI} Fix merge-base diff in linter, style, and scan jobs#9725naga-nandyala wants to merge 1 commit intoAzure:mainfrom
Conversation
️✔️Azure CLI Extensions Breaking Change Test
|
|
Hi @naga-nandyala, |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
|
There was a problem hiding this comment.
Pull request overview
Updates PR-only CI (linter/style/scan) to compute modified files using a proper merge-base diff against the PR target branch, avoiding false positives from unrelated commits in shallow Azure DevOps checkouts.
Changes:
- Added a shared
find_modified_files_against_master_branch()helper inscripts/ci/util.pythat fetches target branch history and diffs againstgit merge-base. - Updated
azdev_linter_style.pyto reuse the shared helper instead of maintaining a local copy. - Replaced inline bash-based scan logic with a Python
scripts/ci/azdev_scan.py, and updated pipeline scan jobs to call it.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| scripts/ci/util.py | Introduces shared merge-base-based modified-file detection for PR jobs. |
| scripts/ci/azdev_scan.py | New Python wrapper to run azdev scan on PR-modified files using the shared util helper. |
| scripts/ci/azdev_linter_style.py | Removes duplicated diff logic and imports shared util helper. |
| azure-pipelines.yml | Switches scan jobs from bash inline diff/scan to the new Python scan script and passes required env. |
19e0e7d to
d9fe186
Compare
CodeGen Tools Feedback CollectionThank you for using our CodeGen tool. We value your feedback, and we would like to know how we can improve our product. Please take a few minutes to fill our codegen survey |
d9fe186 to
d7aa5a7
Compare
d7aa5a7 to
e7117ce
Compare
Problem
CI jobs (linter, style, scan) use
git diff origin/mainto find modified files in a PR, but without computingmerge-base. In a shallow ADO checkout, this causes the diff to include files from other merged PRs, not just the current PR's changes. This leads to false positives — linter/style/scan running against code the PR author never touched.Reported in #9714.
Root Causes
System.PullRequest.TargetBranchisNoneoutside PR context →TypeError$(System.PullRequest.TargetBranch)string →fatal: bad revisionrefs/heads/main→origin/refs/heads/mainis invalidgit diff origin/mainpicks up all commits between HEAD and tip of main, including other merged PRsdeclare -Amisused as integer counter (exit 1 unreachable), unquoted variables, backtick word-splittingFix
scripts/ci/util.py: Added sharedfind_modified_files_against_master_branch()with:System.PullRequest.TargetBranchrefs/heads/,origin/prefixes)git fetch --deepen=50(safe incremental history, unlike--depth=1which re-shallows)git merge-base HEAD origin/<branch>for accurate PR diff--diff-filter=ACMRTscoped tosrc/scripts/ci/azdev_linter_style.py: Removed local copy of the function, imports fromutilscripts/ci/azdev_scan.py: New file replacing inline bash scan logic with Python, reusing shared util functionazure-pipelines.yml: Scan jobs now callpython scripts/ci/azdev_scan.pyconsistently with linter/styleTesting
Locally proved on a 1-file test PR branch:
git diff origin/main): 6 files (1 ours + 5 from other PRs)git merge-base+ diff): 1 file (only our change)Fixes #9714
Related command
CI pipeline scripts only — no extension commands affected.
General Guidelines
azdev stylelocally? (pip install azdevrequired)python scripts/ci/test_index.py -qlocally? (pip install wheel==0.30.0required)For new extensions:
About Extension Publish
There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update
src/index.jsonautomatically.You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify
src/index.json.