Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/changelog-entry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Changelog entry

on:
pull_request_target:
types:
- opened

permissions:
contents: read
issues: write

jobs:
check-changelog-entry:
if: github.repository == 'microsoft/kiota'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7

- name: Check for a new changelog entry
id: changelog
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_REPOSITORY: ${{ github.repository }}
BASE_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_REPOSITORY: ${{ github.event.pull_request.head.repo.full_name }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
shell: pwsh
run: |
$ErrorActionPreference = "Stop"

$baseContent = gh api "repos/$env:BASE_REPOSITORY/contents/CHANGELOG.md?ref=$env:BASE_SHA" --jq .content
$headContent = gh api "repos/$env:HEAD_REPOSITORY/contents/CHANGELOG.md?ref=$env:HEAD_SHA" --jq .content
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(($baseContent -join ""))) | Set-Content -Path base_CHANGELOG.md -NoNewline
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(($headContent -join ""))) | Set-Content -Path head_CHANGELOG.md -NoNewline

$hasEntry = ./scripts/check-changelog-entry.ps1 -baseChangelogPath base_CHANGELOG.md -headChangelogPath head_CHANGELOG.md
"has_entry=$($hasEntry.ToString().ToLowerInvariant())" >> $env:GITHUB_OUTPUT

- name: Comment on missing changelog entry
if: steps.changelog.outputs.has_entry == 'false'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_REPOSITORY: ${{ github.repository }}
PR_NUMBER: ${{ github.event.pull_request.number }}
shell: pwsh
run: |
gh api --method POST "repos/$env:BASE_REPOSITORY/issues/$env:PR_NUMBER/comments" `
-f body='Thanks for opening this pull request! Please add a changelog entry under `## [Unreleased]` in `CHANGELOG.md`, before the first released version section, so users can see what changed. Add bug fixes under `### Changed` and new features under `### Added`.'
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dotnet run -c Release --project src/kiota/kiota.csproj -- <arguments you would p
3. Make your changes and commit them: `git commit -am 'Add some feature'`
- Include tests that cover your changes.
- Update the documentation to reflect your changes, where appropriate.
- Add an entry to the `CHANGELOG.md` file describing your changes if appropriate.
- Add an entry to the `CHANGELOG.md` file under `## [Unreleased]` if appropriate: bug fixes go under `### Changed`, and new features go under `### Added`.
4. Push your changes to your fork: `git push origin my-new-feature`
5. Create a pull request from your fork to the main repository. `gh pr create` (with the GitHub CLI)

Expand Down
46 changes: 46 additions & 0 deletions scripts/check-changelog-entry.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
param (
[string]
[Parameter(Mandatory = $true)]
$baseChangelogPath,
[string]
[Parameter(Mandatory = $true)]
$headChangelogPath
)

function Get-UnreleasedEntries {
param (
[string]
[Parameter(Mandatory = $true)]
$changelogPath
)

$lines = Get-Content -Path $changelogPath
$startIndex = -1
for ($index = 0; $index -lt $lines.Count; $index++) {
if ($lines[$index].Trim() -match "^## \[Unreleased\]\s*$") {
$startIndex = $index
break
}
}

if ($startIndex -lt 0) {
return @()
}

$entries = @()
for ($index = $startIndex + 1; $index -lt $lines.Count; $index++) {
$line = $lines[$index].Trim()
if ($line -match "^## \[[^\]]+\]") {
break
}
if ($line -match "^[-*]\s+\S") {
$entries += ($line -replace "\s+", " ")
}
}
return $entries
}

$baseEntries = @(Get-UnreleasedEntries -changelogPath $baseChangelogPath)
$headEntries = @(Get-UnreleasedEntries -changelogPath $headChangelogPath)

return $headEntries.Count -gt $baseEntries.Count
Loading