From dd49436f7ddfd6ee65cc0bf4f49b8af5d8f3784a Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Thu, 5 Nov 2026 18:14:35 +0200 Subject: [PATCH 1/2] Add changelog-path input to updater --- CHANGELOG.md | 4 +++ updater/README.md | 5 ++++ updater/action.yml | 12 ++++++-- updater/scripts/get-changelog.ps1 | 12 ++++++-- updater/scripts/update-changelog.ps1 | 7 +++-- updater/tests/get-changelog.Tests.ps1 | 35 ++++++++++++++++++++++++ updater/tests/update-changelog.Tests.ps1 | 18 ++++++++++++ 7 files changed, 86 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daa5eaeb..589333af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Updater - Add `changelog-path` input for dependencies whose changelog isn't in the repository root, e.g. a package in a monorepo. The commit-based fallback then only lists commits in that directory. ([#TBD](https://github.com/getsentry/github-workflows/pull/TBD)) + ### Fixes - Validate PR - Skip PRs opened by bots of GitHub Apps owned by Sentry (the `getsentry` organization or the `sentry` enterprise), such as `sentry-junior[bot]`. App bot users are never repo collaborators, so the write-access check couldn't recognize them. ([#179](https://github.com/getsentry/github-workflows/pull/179)) diff --git a/updater/README.md b/updater/README.md index 7929dfb4..f93716cb 100644 --- a/updater/README.md +++ b/updater/README.md @@ -168,6 +168,11 @@ Git lookup or fetch failures are also reported as errors. Annotated release tags * type: string * required: false * default: Dependencies +* `changelog-path`: Path of the changelog in the dependency repository, e.g. `packages/cli/CHANGELOG.md` for a package in a monorepo. + Used for the PR description and the changelog entry link. If the changelog isn't found, the commit-based fallback only lists commits in the changelog's directory. + * type: string + * required: false + * default: '' (a changelog in the repository root) * `pr-strategy`: How to handle PRs. Can be either of the following: * `create` - create a new PR for new dependency versions as they are released - maintainers may merge or close older PRs manually diff --git a/updater/action.yml b/updater/action.yml index ead6fa15..d90fb87f 100644 --- a/updater/action.yml +++ b/updater/action.yml @@ -25,6 +25,10 @@ inputs: description: 'Section header to attach the changelog entry to.' required: false default: 'Dependencies' + changelog-path: + description: 'Path of the changelog in the dependency repository, e.g. "packages/cli/CHANGELOG.md" for a package in a monorepo. Defaults to a changelog in the repository root.' + required: false + default: '' pr-strategy: description: 'How to handle PRs - can be either "create" (create new PRs for each version) or "update" (keep single PR updated with latest version)' required: false @@ -361,11 +365,13 @@ runs: TARGET_REPO_URL: ${{ steps.target.outputs.url }} ORIGINAL_TAG: ${{ steps.target.outputs.originalTag }} LATEST_TAG: ${{ steps.target.outputs.latestTag }} + CHANGELOG_PATH: ${{ inputs.changelog-path }} run: | $changelog = ${{ github.action_path }}/scripts/get-changelog.ps1 ` -RepoUrl $env:TARGET_REPO_URL ` -OldTag $env:ORIGINAL_TAG ` - -NewTag $env:LATEST_TAG + -NewTag $env:LATEST_TAG ` + -ChangelogPath "$env:CHANGELOG_PATH" ${{ github.action_path }}/scripts/set-github-env.ps1 TARGET_CHANGELOG $changelog # First we create a PR only if it doesn't exist. We will later overwrite the content with the same action. @@ -448,6 +454,7 @@ runs: TARGET_MAIN_BRANCH: ${{ steps.target.outputs.mainBranch }} ORIGINAL_TAG: ${{ steps.target.outputs.originalTag }} LATEST_TAG: ${{ steps.target.outputs.latestTag }} + CHANGELOG_PATH: ${{ inputs.changelog-path }} run: | ${{ github.action_path }}/scripts/update-changelog.ps1 ` -Name $env:DEPENDENCY_NAME ` @@ -456,7 +463,8 @@ runs: -MainBranch $env:TARGET_MAIN_BRANCH ` -OldTag $env:ORIGINAL_TAG ` -NewTag $env:LATEST_TAG ` - -Section $env:CHANGELOG_SECTION + -Section $env:CHANGELOG_SECTION ` + -ChangelogPath "$env:CHANGELOG_PATH" - name: Show final git diff if: ${{ ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }} diff --git a/updater/scripts/get-changelog.ps1 b/updater/scripts/get-changelog.ps1 index c892160a..efd19db9 100644 --- a/updater/scripts/get-changelog.ps1 +++ b/updater/scripts/get-changelog.ps1 @@ -1,11 +1,14 @@ param( [Parameter(Mandatory = $true)][string] $RepoUrl, [Parameter(Mandatory = $true)][string] $OldTag, - [Parameter(Mandatory = $true)][string] $NewTag + [Parameter(Mandatory = $true)][string] $NewTag, + # Path of the changelog in the repository, e.g. `packages/cli/CHANGELOG.md`. Defaults to a changelog in the repository root. + [string] $ChangelogPath = '' ) Set-StrictMode -Version latest $PSNativeCommandErrorActionPreference = $false +$ChangelogPath = $ChangelogPath.TrimStart('/') $ErrorActionPreference = 'Stop' $prefix = 'https?://(www\.)?github.com/' @@ -26,7 +29,7 @@ New-Item -ItemType Directory $tmpDir | Out-Null function Get-ChangelogContent { param($ref, $filePath) - $changelogNames = @('CHANGELOG.md', 'changelog.md', 'CHANGELOG.txt', 'changelog.txt', 'CHANGELOG') + $changelogNames = if ($ChangelogPath) { @($ChangelogPath) } else { @('CHANGELOG.md', 'changelog.md', 'CHANGELOG.txt', 'changelog.txt', 'CHANGELOG') } foreach ($name in $changelogNames) { try { @@ -74,7 +77,10 @@ function Get-ChangelogFromCommits { # Get commit messages between tags Write-Host "Getting commits between $oldTag and $newTag..." - $commitMessages = git log "$oldTag..$newTag" --pretty=format:'%s' + # Limit commits to the changelog's directory, e.g. a package in a monorepo + $changelogDir = if ($ChangelogPath) { Split-Path $ChangelogPath -Parent } else { '' } + $pathFilter = if ($changelogDir) { @('--', $changelogDir) } else { @() } + $commitMessages = git log "$oldTag..$newTag" --pretty=format:'%s' @pathFilter if ($LASTEXITCODE -ne 0) { Write-Warning "Could not get commits between $oldTag and $newTag (exit code: $LASTEXITCODE)" return $null diff --git a/updater/scripts/update-changelog.ps1 b/updater/scripts/update-changelog.ps1 index 1ab2ec59..e3755560 100644 --- a/updater/scripts/update-changelog.ps1 +++ b/updater/scripts/update-changelog.ps1 @@ -5,7 +5,9 @@ param( [Parameter(Mandatory = $true)][string] $MainBranch, [Parameter(Mandatory = $true)][string] $OldTag, [Parameter(Mandatory = $true)][string] $NewTag, - [Parameter(Mandatory = $true)][string] $Section + [Parameter(Mandatory = $true)][string] $Section, + # Path of the dependency's changelog in its repository, used for the changelog link + [string] $ChangelogPath = '' ) Set-StrictMode -Version latest @@ -144,6 +146,7 @@ for ($i = 0; $i -lt $lines.Count; $i++) $sectionEnd = $i $tagAnchor = $NewTag.Replace('.', '') +$changelogFile = if ($ChangelogPath) { $ChangelogPath.TrimStart('/') } else { 'CHANGELOG.md' } $oldTagNice = ($OldTag -match "^[0-9]") ? "v$OldTag" : $OldTag $newTagNice = ($NewTag -match "^[0-9]") ? "v$NewTag" : $NewTag @@ -182,7 +185,7 @@ if (!$updated) $bulletPoint = $lines | Where-Object { ($_ -match '^ *[-*] ') -and -not ($_ -match '(Bump .* to|\[changelog\]|\[diff\])') } | Select-Object -First 1 $bulletPoint = "$("$bulletPoint".Trim())-"[0] $entry = @("$bulletPoint Bump $Name from $oldTagNice to $newTagNice ($PullRequestMD)", - " $bulletPoint [changelog]($RepoUrl/blob/$MainBranch/CHANGELOG.md#$tagAnchor)", + " $bulletPoint [changelog]($RepoUrl/blob/$MainBranch/$changelogFile#$tagAnchor)", " $bulletPoint [diff]($RepoUrl/compare/$OldTag...$NewTag)") Write-Host "Adding a changelog entry at line $($sectionEnd):" diff --git a/updater/tests/get-changelog.Tests.ps1 b/updater/tests/get-changelog.Tests.ps1 index aaa48c15..00a1d8be 100644 --- a/updater/tests/get-changelog.Tests.ps1 +++ b/updater/tests/get-changelog.Tests.ps1 @@ -381,4 +381,39 @@ Features, fixes and improvements in this release have been contributed by: # Should return empty/null and not crash the script $actual | Should -BeNullOrEmpty } + + It 'with changelog path' { + $actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" ` + -RepoUrl 'https://github.com/getsentry/github-workflows' -OldTag 'v2.0.0' -NewTag 'v2.1.0' -ChangelogPath 'CHANGELOG.md' + $expected = @' +## Changelog + +### 2.1.0 + +#### Features + +- New reusable workflow, `danger.yml`, to check Pull Requests with predefined rules ([#34](https://github-redirect.dependabot.com/getsentry/github-workflows/pull/34)) +'@ + + $actual | Should -Be $expected + } + + It 'git commit fallback only lists commits in the changelog path directory' { + # There's no updater/CHANGELOG.md, so this falls back to commits that touched updater/ + $actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" ` + -RepoUrl 'https://github.com/getsentry/github-workflows' -OldTag 'v2.4.0' -NewTag 'v2.5.0' -ChangelogPath 'updater/CHANGELOG.md' + + $expected = @' +## Changelog + +### Commits between v2.4.0 and v2.5.0 + +- feat: don't update existing branches if there are manually added commits ([#50](https://github-redirect.dependabot.com/getsentry/github-workflows/issues/50)) +- test: improve test scripts & test on all supported platforms ([#49](https://github-redirect.dependabot.com/getsentry/github-workflows/issues/49)) +- chore: use pwsh tee-object to print output as well as set it to GH +- chore: replace deprecated GH set-output +'@ + + $actual | Should -Be $expected + } } diff --git a/updater/tests/update-changelog.Tests.ps1 b/updater/tests/update-changelog.Tests.ps1 index 2665c420..a2a44d02 100644 --- a/updater/tests/update-changelog.Tests.ps1 +++ b/updater/tests/update-changelog.Tests.ps1 @@ -48,4 +48,22 @@ Describe 'update-changelog' { Get-Content "$testCasePath/CHANGELOG.md" | Should -Be (Get-Content "$testCasePath/CHANGELOG.md.expected") } + + It 'should link to the changelog path' { + $testCasePath = "$TestDrive/changelog-path" + New-Item $testCasePath -ItemType Directory | Out-Null + @('# Changelog', '', '## Unreleased', '', '### Dependencies', '', '- Existing entry', '') | Out-File "$testCasePath/CHANGELOG.md" + + pwsh -WorkingDirectory $testCasePath -File "$PSScriptRoot/../scripts/update-changelog.ps1" ` + -Name 'Dependency' ` + -PR 'https://github.com/getsentry/dependant/pulls/123' ` + -RepoUrl 'https://github.com/getsentry/dependency' ` + -MainBranch 'main' ` + -OldTag '7.16.0' ` + -NewTag '7.17.0' ` + -Section 'Dependencies' ` + -ChangelogPath 'packages/cli/CHANGELOG.md' + + Get-Content "$testCasePath/CHANGELOG.md" | Should -Contain ' - [changelog](https://github.com/getsentry/dependency/blob/main/packages/cli/CHANGELOG.md#7170)' + } } From 7d63b3093e87d2e1b0678d192738bbe7abe42d1d Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Thu, 5 Nov 2026 18:15:51 +0200 Subject: [PATCH 2/2] Add PR number to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 589333af..3772ee40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Features -- Updater - Add `changelog-path` input for dependencies whose changelog isn't in the repository root, e.g. a package in a monorepo. The commit-based fallback then only lists commits in that directory. ([#TBD](https://github.com/getsentry/github-workflows/pull/TBD)) +- Updater - Add `changelog-path` input for dependencies whose changelog isn't in the repository root, e.g. a package in a monorepo. The commit-based fallback then only lists commits in that directory. ([#183](https://github.com/getsentry/github-workflows/pull/183)) ### Fixes