-
Notifications
You must be signed in to change notification settings - Fork 556
Changelog verification #2580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changelog verification #2580
Changes from all commits
50e0fc5
d831e20
52c58d2
e6ef2c7
be10dba
2f9b4f4
25f28c5
9141365
42a4caf
c1f093f
b147800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||
| #!/usr/bin/env pwsh | ||||||||||||||
| #Requires -Version 7 | ||||||||||||||
|
|
||||||||||||||
| # Validates that a PR includes a changelog entry or has the 'skip-changelog' label. | ||||||||||||||
|
|
||||||||||||||
| . "$PSScriptRoot/../common/scripts/common.ps1" | ||||||||||||||
|
|
||||||||||||||
| # Fetch PR labels once at the start via GitHub REST API | ||||||||||||||
| $prNumber = $env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER | ||||||||||||||
| $prLabels = @() | ||||||||||||||
| if ($prNumber) { | ||||||||||||||
| $repo = $env:BUILD_REPOSITORY_NAME | ||||||||||||||
| if (-not $repo) { | ||||||||||||||
| $repo = "microsoft/mcp" | ||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If Consider stripping the suffix:
Suggested change
|
||||||||||||||
| } | ||||||||||||||
| $apiUrl = "https://api.github.com/repos/$repo/pulls/$prNumber" | ||||||||||||||
| $headers = @{ "Accept" = "application/vnd.github+json"; "User-Agent" = "mcp-changelog-check" } | ||||||||||||||
| if ($env:GH_TOKEN) { | ||||||||||||||
| $headers["Authorization"] = "Bearer $($env:GH_TOKEN)" | ||||||||||||||
| } | ||||||||||||||
| try { | ||||||||||||||
| $response = Invoke-RestMethod -Uri $apiUrl -Headers $headers -Method Get -ErrorAction Stop | ||||||||||||||
| $prLabels = @($response.labels | ForEach-Object { $_.name }) | ||||||||||||||
| Write-Host "PR #$prNumber labels: $($prLabels -join ', ')" | ||||||||||||||
| } | ||||||||||||||
| catch { | ||||||||||||||
| Write-Error "Failed to fetch PR labels from GitHub API for PR #$prNumber. Unable to validate whether the 'skip-changelog' label is present. Ensure the GitHub authentication step ran and GH_TOKEN is available, then retry. Underlying error: $_" | ||||||||||||||
| exit 1 | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Push-Location $RepoRoot | ||||||||||||||
| try { | ||||||||||||||
| $diffRange = "origin/main...HEAD" | ||||||||||||||
| $changedFiles = git diff --name-only --diff-filter=AM $diffRange 2>&1 | ||||||||||||||
| if ($LASTEXITCODE -ne 0) { | ||||||||||||||
| $gitError = ($changedFiles | Out-String).Trim() | ||||||||||||||
| Write-Error "Failed to determine changed files with 'git diff --name-only --diff-filter=AM $diffRange'. $gitError" | ||||||||||||||
| exit 1 | ||||||||||||||
| } | ||||||||||||||
| $hasChangelog = $changedFiles | Where-Object { $_ -match 'changelog-entries/.*\.ya?ml$' -or $_ -match 'CHANGELOG\.md'} | ||||||||||||||
|
|
||||||||||||||
| if ($hasChangelog) { | ||||||||||||||
| Write-Host "Found changelog entry: $($hasChangelog -join ', ')" | ||||||||||||||
| exit 0 | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if (-not $prNumber) { | ||||||||||||||
| Write-Host "Not a PR build - skipping skip-changelog label check." | ||||||||||||||
| exit 0 | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| if ($prLabels -contains 'skip-changelog') { | ||||||||||||||
| Write-Host "'skip-changelog' label found — skipping." | ||||||||||||||
| exit 0 | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| Write-Error "Add a changelog entry to the PR or apply the 'skip-changelog' label." | ||||||||||||||
| exit 1 | ||||||||||||||
| } | ||||||||||||||
| finally { | ||||||||||||||
| Pop-Location | ||||||||||||||
| } | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider checking for changelog files before fetching labels. Most PRs that include a changelog entry don't need the label check at all, and this way the build won't break if the API call fails for any reason (auth issue, rate limit, wrong repo name):