Skip to content

Sync eng/common directory with azure-sdk-tools for PR 14661#9766

Open
azure-sdk wants to merge 5 commits intomainfrom
sync-eng/common-djurek/codeowners-block-edit-14661
Open

Sync eng/common directory with azure-sdk-tools for PR 14661#9766
azure-sdk wants to merge 5 commits intomainfrom
sync-eng/common-djurek/codeowners-block-edit-14661

Conversation

@azure-sdk
Copy link
Collaborator

Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#14661 See eng/common workflow

@azure-sdk azure-sdk requested a review from a team as a code owner March 23, 2026 22:24
@azure-sdk azure-sdk added EngSys This issue is impacting the engineering system. Central-EngSys This issue is owned by the Engineering System team. labels Mar 23, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new eng/common pipeline check to prevent unauthorized modifications to protected sections of the .github/CODEOWNERS file by exporting and comparing named sections via the azsdk CLI.

Changes:

  • Add Test-CodeownersSections.ps1 to export/compare specific CODEOWNERS sections and emit diffs on mismatch.
  • Add verify-codeowners-sections.yml pipeline step template to detect CODEOWNERS changes, prepare before/after snapshots, and run the comparison.
  • Extend install-azsdk-cli.yml with a Condition parameter so the CLI install can be skipped when not needed.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
eng/common/scripts/Test-CodeownersSections.ps1 New script that exports and compares protected CODEOWNERS sections using azsdk CLI.
eng/common/pipelines/templates/steps/verify-codeowners-sections.yml New step template that detects CODEOWNERS edits and runs the section comparison in PR builds.
eng/common/pipelines/templates/steps/install-azsdk-cli.yml Adds a Condition parameter to conditionally run the azsdk CLI install task.

Comment on lines +13 to +17
$diffOutput = git diff --name-only HEAD~1 HEAD -- ".github/CODEOWNERS" 2>&1
if ($LASTEXITCODE) {
Write-Host "Unable to compute diff (exit code $LASTEXITCODE). Skipping CODEOWNERS section check."
Write-Host "##vso[task.setvariable variable=CodeownersChanged]false"
exit 0
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The CODEOWNERS change detection is based on git diff HEAD~1 HEAD, and if that diff fails the template sets CodeownersChanged=false and exits 0. In shallow checkouts (or any scenario where HEAD~1 isn't available), this effectively bypasses the protected-section enforcement. Consider using the existing eng/common/scripts/get-changedfiles.ps1 (which diffs PR source vs target) and/or failing the job when the diff can’t be computed so the protection can’t be skipped.

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +57
# Extract parent commit version
git show "HEAD~1:.github/CODEOWNERS" > $beforeFile
Write-Host "Retrieved parent commit CODEOWNERS to $beforeFile"
Get-Content $beforeFile | Select-Object -First 20 | Write-Host
if ($LASTEXITCODE) {
Write-Host "Could not retrieve CODEOWNERS from HEAD~1. The file may be newly added. Skipping."
Write-Host "##vso[task.setvariable variable=CodeownersChanged]false"
exit 0
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The "before" CODEOWNERS file is pulled from HEAD~1 and on failure the step skips the entire check by setting CodeownersChanged=false. This is unreliable for PR builds where the checked-out ref isn’t guaranteed to have HEAD~1 locally (e.g., shallow fetch) and can also compare against the wrong baseline depending on how the PR ref is checked out. Prefer retrieving the base version via the PR target commit/branch (e.g., using the same source/target commitish logic as get-changedfiles.ps1) and avoid treating retrieval failures as a reason to skip enforcement.

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +80
foreach ($section in $Sections) {
$safeName = $section -replace ' ', '_'
$beforeSection = Join-Path $TempDirectory "before.${safeName}.txt"
$afterSection = Join-Path $TempDirectory "after.${safeName}.txt"
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

$TempDirectory is used to build the --output-file paths, but the script never ensures that directory exists. If the caller forgets to create it (or if it was cleaned up), the azsdk export command will fail writing the output files. Consider creating $TempDirectory (e.g., New-Item -ItemType Directory -Force) during input validation.

Copilot uses AI. Check for mistakes.
@azure-sdk azure-sdk force-pushed the sync-eng/common-djurek/codeowners-block-edit-14661 branch 2 times, most recently from 1e808a8 to 2794950 Compare March 24, 2026 04:46
@azure-sdk azure-sdk force-pushed the sync-eng/common-djurek/codeowners-block-edit-14661 branch from 2794950 to 958e9bd Compare March 24, 2026 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Central-EngSys This issue is owned by the Engineering System team. EngSys This issue is impacting the engineering system.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants