Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### 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))
- Updater - Support prefixed release tags, such as `cli@1.2.3`, via a `version` named group in `pattern`. ([#184](https://github.com/getsentry/github-workflows/pull/184))

## 3.4.1

Expand Down
3 changes: 3 additions & 0 deletions updater/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ Git lookup or fetch failures are also reported as errors. Annotated release tags
* type: string
* required: true
* `pattern`: RegEx pattern that will be matched against available versions when picking the latest one.
An optional `version` named group marks the version part of the tag, which is used to compare versions and in the PR title and changelog entry.
For monorepos that tag releases with a product prefix (e.g. `cli@1.2.3`), use a pattern like `'^cli@(?<version>[0-9.]+)$'`.
Without the group, only a leading `v` is removed from the tag.
* type: string
* required: false
* default: ''
Expand Down
6 changes: 5 additions & 1 deletion updater/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ inputs:
description: 'Name used in the PR title and the changelog entry.'
required: true
pattern:
description: 'RegEx pattern that will be matched against available versions when picking the latest one.'
description: 'RegEx pattern that will be matched against available versions when picking the latest one. An optional `version` named group marks the version part of the tag, e.g. `^cli@(?<version>[0-9.]+)$`.'
required: false
default: ''
gh-title-pattern:
Expand Down Expand Up @@ -448,6 +448,8 @@ runs:
TARGET_MAIN_BRANCH: ${{ steps.target.outputs.mainBranch }}
ORIGINAL_TAG: ${{ steps.target.outputs.originalTag }}
LATEST_TAG: ${{ steps.target.outputs.latestTag }}
ORIGINAL_VERSION: ${{ steps.target.outputs.originalVersion }}
LATEST_VERSION: ${{ steps.target.outputs.latestVersion }}
run: |
${{ github.action_path }}/scripts/update-changelog.ps1 `
-Name $env:DEPENDENCY_NAME `
Expand All @@ -456,6 +458,8 @@ runs:
-MainBranch $env:TARGET_MAIN_BRANCH `
-OldTag $env:ORIGINAL_TAG `
-NewTag $env:LATEST_TAG `
-OldVersion $env:ORIGINAL_VERSION `
-NewVersion $env:LATEST_VERSION `
-Section $env:CHANGELOG_SECTION

- name: Show final git diff
Expand Down
35 changes: 35 additions & 0 deletions updater/scripts/common.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@

$FallbackVersionPattern = '^v?(?<version>.+)$'

function GetVersionFromTag([string] $tag, [string] $pattern = '')
{
if ($pattern -ne '' -and $tag -match $pattern -and $Matches.ContainsKey('version'))
{
return $Matches['version']
}
if ($tag -match $FallbackVersionPattern)
{
return $Matches['version']
}
return $tag
}

# E.g. `cli@` for both `cli@1.2.3` and `cli@v1.2.3`
function GetTagPrefix([string] $tag, [string] $pattern)
{
$match = [regex]::Match($tag, $pattern, 'IgnoreCase')
if (-not $match.Success -or -not $match.Groups['version'].Success)
{
return ''
}
return $tag.Substring(0, $match.Groups['version'].Index) -replace 'v$', ''
}

function GetVersionAfterPrefix([string] $tag, [string] $prefix)
{
if ($tag -match ('^' + [regex]::Escape($prefix) + 'v?(?<version>.+)$'))
{
return $Matches['version']
}
return $null
}

function GetComparableVersion([string] $value)
{
$value = $value -replace '^v', ''
Expand Down
4 changes: 2 additions & 2 deletions updater/scripts/get-changelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ function Format-ChangelogContent {
}

# Apply standard formatting
# Remove at-mentions
$changelog = $changelog -replace '@', ''
# Remove at-mentions, but keep prefixed tags (`cli@1.2.3`) and email addresses
$changelog = $changelog -replace '(?<!\w)@', ''

# Make PR/issue references into links to the original repository (unless they already are links)
$changelog = $changelog -replace '(?<!\[)#([0-9]+)(?![\]0-9])', ('[#$1](' + $repoUrl + '/issues/$1)')
Expand Down
7 changes: 4 additions & 3 deletions updater/scripts/sort-versions.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
param(
[Parameter(Mandatory = $true)][string[]] $List
[Parameter(Mandatory = $true)][string[]] $List,
[string] $Pattern = ''
)

Set-StrictMode -Version latest
. "$PSScriptRoot/common.ps1"

$List `
| Where-Object { $null -ne (GetComparableVersion $_) } `
| Sort-Object -Property @{Expression = { GetComparableVersion $_ } }
| Where-Object { $null -ne (GetComparableVersion (GetVersionFromTag $_ $Pattern)) } `
| Sort-Object -Property @{Expression = { GetComparableVersion (GetVersionFromTag $_ $Pattern) } }
13 changes: 9 additions & 4 deletions updater/scripts/update-changelog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ 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,
[string] $OldVersion = '',
[string] $NewVersion = ''
)

Set-StrictMode -Version latest
. "$PSScriptRoot/common.ps1"

$file = $(Get-ChildItem | Where-Object { $_.Name -match '^changelog(\.md|\.txt|)$' } )
if ("$file" -eq "")
Expand Down Expand Up @@ -143,9 +146,11 @@ for ($i = 0; $i -lt $lines.Count; $i++)
# What line we want to insert at - the empty line at the end of the currently unreleased section.
$sectionEnd = $i

$tagAnchor = $NewTag.Replace('.', '')
$oldTagNice = ($OldTag -match "^[0-9]") ? "v$OldTag" : $OldTag
$newTagNice = ($NewTag -match "^[0-9]") ? "v$NewTag" : $NewTag
if ("$OldVersion" -eq '') { $OldVersion = GetVersionFromTag $OldTag }
if ("$NewVersion" -eq '') { $NewVersion = GetVersionFromTag $NewTag }
$tagAnchor = ($NewTag.EndsWith("v$NewVersion") ? "v$NewVersion" : $NewVersion).Replace('.', '')
$oldTagNice = ($OldVersion -match "^[0-9]") ? "v$OldVersion" : $OldTag
$newTagNice = ($NewVersion -match "^[0-9]") ? "v$NewVersion" : $NewTag

$PullRequestMD = "[#$($PR | Split-Path -Leaf)]($PR)"

Expand Down
22 changes: 18 additions & 4 deletions updater/scripts/update-dependency.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ if ("$Tag" -eq '') {

if ("$Pattern" -eq '') {
# Use a default pattern that excludes pre-releases
$Pattern = '^v?([0-9.]+)$'
$Pattern = '^v?(?<version>[0-9.]+)$'
}

Write-Host "Filtering tags with pattern '$Pattern'"
Expand All @@ -215,10 +215,19 @@ if ("$Tag" -eq '') {
throw "Found no tags matching pattern '$Pattern'"
}

$tags = & "$PSScriptRoot/sort-versions.ps1" $tags
$tags = @(& "$PSScriptRoot/sort-versions.ps1" $tags -Pattern $Pattern)

if ($tags.Count -eq 0) {
throw "Found no tags with a semantic version matching pattern '$Pattern'. If the tags have a prefix, mark the version with a ``version`` named group, e.g. '^cli@(?<version>[0-9.]+)$'."
}

Write-Host "Sorted tags: $tags"
$latestTag = $tags[-1]
$latestVersion = GetVersionFromTag $latestTag $Pattern

# Read the original tag with the latest tag's prefix, so that a tag of another product is never read as a version
$tagPrefix = GetTagPrefix $latestTag $Pattern
$originalVersion = GetVersionAfterPrefix $originalTag $tagPrefix

if (("$originalTag" -ne '') -and ("$latestTag" -ne '') -and ("$latestTag" -ne "$originalTag")) {
do {
Expand All @@ -245,7 +254,7 @@ if ("$Tag" -eq '') {

# It's possible that the dependency was updated to a pre-release version manually in which case we don't want to
# roll back, even though it's not the latest version matching the configured pattern.
if (-not $isUnreleasedPin -and (GetComparableVersion $originalTag) -ge (GetComparableVersion $latestTag)) {
if (-not $isUnreleasedPin -and $null -ne $originalVersion -and (GetComparableVersion $originalVersion) -ge (GetComparableVersion $latestVersion)) {
Write-Host "SemVer represented by the original tag '$originalTag' is newer than the latest tag '$latestTag'. Skipping update."
$latestTag = $originalTag
break
Expand All @@ -265,10 +274,15 @@ if ("$Tag" -eq '') {
} while ($false)
}

$latestTagNice = ($latestTag -match '^[0-9]') ? "v$latestTag" : $latestTag
if ("$originalTag" -eq "$latestTag") {
$latestVersion = $originalVersion
}
$latestTagNice = ($latestVersion -match '^[0-9]') ? "v$latestVersion" : $latestTag

SetOutput 'originalTag' $originalTag
SetOutput 'originalVersion' $originalVersion
SetOutput 'latestTag' $latestTag
SetOutput 'latestVersion' $latestVersion
SetOutput 'latestTagNice' $latestTagNice
SetOutput 'url' $url
SetOutput 'mainBranch' $mainBranch
Expand Down
20 changes: 20 additions & 0 deletions updater/tests/get-changelog.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,26 @@ Features, fixes and improvements in this release have been contributed by:
$actual | Should -Be $expected
}

It 'git commit fallback keeps prefixed tags' {
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
-RepoUrl 'https://github.com/getsentry/javascript-debug-ids' -OldTag '@debugids/browser@0.1.2' -NewTag '@debugids/browser@0.1.3'

$expected = @'
## Changelog

### Commits between debugids/browser@0.1.2 and debugids/browser@0.1.3

- meta(changelog): Update package versions ([#50](https://github-redirect.dependabot.com/getsentry/javascript-debug-ids/issues/50))
- chore: Update dev deps to latest versions ([#49](https://github-redirect.dependabot.com/getsentry/javascript-debug-ids/issues/49))
- chore: Add changeset for native vite support
- feat: Document native Vite support ([#48](https://github-redirect.dependabot.com/getsentry/javascript-debug-ids/issues/48))
- feat: Update LICENSE date range for 2025 ([#47](https://github-redirect.dependabot.com/getsentry/javascript-debug-ids/issues/47))
- chore: Format package.json
'@

$actual | Should -Be $expected
}

It 'git commit fallback returns empty when no commits found' {
# Test with same tags (no commits between them)
$actual = & "$PSScriptRoot/../scripts/get-changelog.ps1" `
Expand Down
19 changes: 17 additions & 2 deletions updater/tests/sort-versions.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

BeforeAll {
function SortVersions([Parameter(Mandatory = $true)][string[]] $List)
function SortVersions([Parameter(Mandatory = $true)][string[]] $List, [string] $Pattern = '')
{
$result = & "$PSScriptRoot/../scripts/sort-versions.ps1" $List
$result = & "$PSScriptRoot/../scripts/sort-versions.ps1" $List -Pattern $Pattern
if (-not $?)
{
throw $result
Expand All @@ -27,4 +27,19 @@ Describe 'sort-versions' {
$sorted = SortVersions @('1.0.0-rc.1', '1.0.0', '1.0.0-beta.11', '1.0.0-alpha.1', '1.0.0-beta', '1.0.0-alpha.beta', '1.0.0-alpha', '1.0.0-beta.2')
$sorted | Should -Be @('1.0.0-alpha', '1.0.0-alpha.1', '1.0.0-alpha.beta', '1.0.0-beta', '1.0.0-beta.2', '1.0.0-beta.11', '1.0.0-rc.1', '1.0.0')
}

It 'prefixed versions with a version group' {
$sorted = SortVersions @('cli@0.47.0', 'cli@0.9.0', 'cli@0.46.0', 'cli@0.47.0-beta.1') '^cli@(?<version>.+)$'
$sorted | Should -Be @('cli@0.9.0', 'cli@0.46.0', 'cli@0.47.0-beta.1', 'cli@0.47.0')
}

It 'skips prefixed versions without a version group' {
$sorted = SortVersions @('cli@0.47.0', '0.42.0') '^(cli@)?[0-9.]+$' 3>$null
$sorted | Should -Be @('0.42.0')
}

It 'skips tags of another product' {
$sorted = SortVersions @('cli@0.47.0', 'logger@9.0.0') '^cli@(?<version>.+)$' 3>$null
$sorted | Should -Be @('cli@0.47.0')
}
}
66 changes: 66 additions & 0 deletions updater/tests/update-changelog.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,70 @@ Describe 'update-changelog' {

Get-Content "$testCasePath/CHANGELOG.md" | Should -Be (Get-Content "$testCasePath/CHANGELOG.md.expected")
}

Context 'prefixed tags' {
BeforeEach {
$testCasePath = "$TestDrive/prefixed-tags"
New-Item $testCasePath -ItemType Directory -Force | Out-Null
}

It 'should use the versions in displayed versions and the changelog anchor' {
@('# 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 'cli@0.46.0' `
-NewTag 'cli@0.47.0' `
-OldVersion '0.46.0' `
-NewVersion '0.47.0' `
-Section 'Dependencies'

$content = Get-Content "$testCasePath/CHANGELOG.md"
$content | Should -Contain '- Bump Dependency from v0.46.0 to v0.47.0 ([#123](https://github.com/getsentry/dependant/pulls/123))'
$content | Should -Contain ' - [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#0470)'
$content | Should -Contain ' - [diff](https://github.com/getsentry/dependency/compare/cli@0.46.0...cli@0.47.0)'
}

It 'should update an existing entry' {
@('# Changelog', '', '## Unreleased', '', '### Dependencies', '',
'- Bump Dependency from v0.45.0 to v0.46.0 ([#100](https://github.com/getsentry/dependant/pulls/100))',
' - [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#0460)',
' - [diff](https://github.com/getsentry/dependency/compare/cli@0.45.0...cli@0.46.0)', '') | 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 'cli@0.46.0' `
-NewTag 'cli@0.47.0' `
-OldVersion '0.46.0' `
-NewVersion '0.47.0' `
-Section 'Dependencies'

$content = Get-Content "$testCasePath/CHANGELOG.md"
$content | Should -Contain '- Bump Dependency from v0.45.0 to v0.47.0 ([#100](https://github.com/getsentry/dependant/pulls/100), [#123](https://github.com/getsentry/dependant/pulls/123))'
$content | Should -Contain ' - [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#0470)'
$content | Should -Contain ' - [diff](https://github.com/getsentry/dependency/compare/cli@0.45.0...cli@0.47.0)'
}

It 'should show the tag when the old version is unknown' {
@('# 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 'logger@0.46.0' `
-NewTag 'cli@0.47.0' `
-NewVersion '0.47.0' `
-Section 'Dependencies'

Get-Content "$testCasePath/CHANGELOG.md" | Should -Contain '- Bump Dependency from logger@0.46.0 to v0.47.0 ([#123](https://github.com/getsentry/dependant/pulls/123))'
}
}
}
44 changes: 44 additions & 0 deletions updater/tests/update-dependency.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,50 @@ Describe ('update-dependency') {
Get-Content $testFile | Should -Be @("repo=$repo", 'version=3.2.1')
}

It 'version pattern match with prefixed tags' {
$testFile = "$testDir/test.properties"
$repo = 'https://github.com/getsentry/toolkit'
@("repo=$repo", 'version=cli@0.45.0') | Out-File $testFile
$stdout = UpdateDependency $testFile '^cli@(?<version>0\.46\.[0-9]+)$'
Get-Content $testFile | Should -Be @("repo=$repo", 'version=cli@0.46.0')
$stdout | Should -Contain 'originalVersion=0.45.0'
$stdout | Should -Contain 'latestTag=cli@0.46.0'
$stdout | Should -Contain 'latestVersion=0.46.0'
$stdout | Should -Contain 'latestTagNice=v0.46.0'
}

It 'will not update from a later prefixed release to an earlier release' {
$testFile = "$testDir/test.properties"
$repo = 'https://github.com/getsentry/toolkit'
@("repo=$repo", 'version=cli@99.0.0') | Out-File $testFile
UpdateDependency $testFile '^cli@(?<version>0\.46\.[0-9]+)$'
Get-Content $testFile | Should -Be @("repo=$repo", 'version=cli@99.0.0')
}

It 'reads the prefix of the original tag regardless of case' {
$testFile = "$testDir/test.properties"
$repo = 'https://github.com/getsentry/toolkit'
@("repo=$repo", 'version=cli@99.0.0') | Out-File $testFile
UpdateDependency $testFile '^CLI@(?<version>0\.46\.[0-9]+)$'
Get-Content $testFile | Should -Be @("repo=$repo", 'version=cli@99.0.0')
}

It 'fails when no matching tag has a semantic version' {
$testFile = "$testDir/test.properties"
$repo = 'https://github.com/getsentry/toolkit'
@("repo=$repo", 'version=cli@0.45.0') | Out-File $testFile
{ UpdateDependency $testFile '^cli@0\.46\.[0-9]+$' 3>$null } | Should -Throw '*Found no tags with a semantic version*'
}

It 'does not read a tag without the prefix as a version' {
$testFile = "$testDir/test.properties"
$repo = 'https://github.com/getsentry/toolkit'
@("repo=$repo", 'version=99.0.0') | Out-File $testFile
$stdout = UpdateDependency $testFile '^cli@(?<version>0\.46\.[0-9]+)$'
Get-Content $testFile | Should -Be @("repo=$repo", 'version=cli@0.46.0')
$stdout | Should -Contain 'originalVersion='
}

It 'will not update from a later release to an earlier release' {
$testFile = "$testDir/test.properties"
$repo = 'https://github.com/getsentry/sentry-java'
Expand Down