Skip to content

Commit eaa7ed7

Browse files
vaindclaude
andcommitted
feat: add gh-title-pattern input for release channel filtering
Implements Issue #85 by adding a new `gh-title-pattern` input parameter that allows filtering releases by GitHub release titles using regex patterns. Features: - Filter releases by title patterns (e.g., '\(Stable\)$' for stable releases) - Uses GitHub API to fetch release metadata - Fully backward compatible when parameter is not specified - Comprehensive test coverage with error handling Usage example: ```yaml uses: getsentry/github-workflows/updater@v3 with: path: modules/sentry-cocoa name: Cocoa SDK (Stable) gh-title-pattern: '\(Stable\)$' ``` 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 1dbbc41 commit eaa7ed7

File tree

4 files changed

+143
-3
lines changed

4 files changed

+143
-3
lines changed

updater/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ jobs:
3232
pattern: '^1\.' # Limit to major version '1'
3333
api-token: ${{ secrets.CI_DEPLOY_KEY }}
3434

35+
# Update to stable releases only by filtering GitHub release titles
36+
cocoa-stable:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: getsentry/github-workflows/updater@v3
40+
with:
41+
path: modules/sentry-cocoa
42+
name: Cocoa SDK (Stable)
43+
gh-title-pattern: '\(Stable\)$' # Only releases with "(Stable)" suffix
44+
api-token: ${{ secrets.CI_DEPLOY_KEY }}
45+
3546
# Update a properties file
3647
cli:
3748
runs-on: ubuntu-latest
@@ -91,6 +102,10 @@ jobs:
91102
* type: string
92103
* required: false
93104
* default: ''
105+
* `gh-title-pattern`: RegEx pattern to match against GitHub release titles. Only releases with matching titles will be considered. Useful for filtering to specific release channels (e.g., stable releases).
106+
* type: string
107+
* required: false
108+
* default: ''
94109
* `changelog-entry`: Whether to add a changelog entry for the update.
95110
* type: boolean
96111
* required: false

updater/action.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ inputs:
1313
description: 'RegEx pattern that will be matched against available versions when picking the latest one.'
1414
required: false
1515
default: ''
16+
gh-title-pattern:
17+
description: 'RegEx pattern to match against GitHub release titles. Only releases with matching titles will be considered.'
18+
required: false
19+
default: ''
1620
changelog-entry:
1721
description: 'Whether to add a changelog entry for the update.'
1822
required: false
@@ -107,7 +111,8 @@ runs:
107111
env:
108112
DEPENDENCY_PATH: ${{ inputs.path }}
109113
DEPENDENCY_PATTERN: ${{ inputs.pattern }}
110-
run: ${{ github.action_path }}/scripts/update-dependency.ps1 -Path $env:DEPENDENCY_PATH -Pattern $env:DEPENDENCY_PATTERN
114+
GH_TITLE_PATTERN: ${{ inputs.gh-title-pattern }}
115+
run: ${{ github.action_path }}/scripts/update-dependency.ps1 -Path $env:DEPENDENCY_PATH -Pattern $env:DEPENDENCY_PATTERN -GhTitlePattern $env:GH_TITLE_PATTERN
111116

112117
- name: Get the base repo info
113118
if: steps.target.outputs.latestTag != steps.target.outputs.originalTag

updater/scripts/update-dependency.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ param(
1212
[Parameter(Mandatory = $true)][string] $Path,
1313
# RegEx pattern that will be matched against available versions when picking the latest one
1414
[string] $Pattern = '',
15+
# RegEx pattern to match against GitHub release titles. Only releases with matching titles will be considered
16+
[string] $GhTitlePattern = '',
1517
# Specific version - if passed, no discovery is performed and the version is set directly
1618
[string] $Tag = ''
1719
)
@@ -188,6 +190,75 @@ if ("$Tag" -eq '')
188190

189191
$url = $url -replace '\.git$', ''
190192

193+
# Filter by GitHub release titles if pattern is provided
194+
if ("$GhTitlePattern" -ne '')
195+
{
196+
Write-Host "Filtering tags by GitHub release title pattern '$GhTitlePattern'"
197+
198+
# Check if URL is a GitHub URL first
199+
if ($url -notmatch 'github\.com')
200+
{
201+
throw "Could not parse GitHub owner/repo from URL: $url"
202+
}
203+
204+
# Parse GitHub repo owner/name from URL
205+
if ($url -match 'github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$')
206+
{
207+
$owner = $Matches[1]
208+
$repo = $Matches[2]
209+
210+
try
211+
{
212+
# Fetch all releases from GitHub API
213+
$releases = gh api "repos/$owner/$repo/releases" --paginate --jq '.[] | {tag_name: .tag_name, name: .name}' | ConvertFrom-Json
214+
215+
# Handle case where releases might be null or single object
216+
if ($null -eq $releases)
217+
{
218+
$releases = @()
219+
}
220+
elseif ($releases -isnot [array])
221+
{
222+
$releases = @($releases)
223+
}
224+
225+
# Create a hashtable of tag->title mappings for releases that match the pattern
226+
$validTags = @{}
227+
foreach ($release in $releases)
228+
{
229+
if ($release.name -match $GhTitlePattern)
230+
{
231+
$validTags[$release.tag_name] = $true
232+
}
233+
}
234+
235+
# Filter tags to only include those with matching release titles
236+
$originalTagCount = $tags.Length
237+
$tags = @($tags | Where-Object { $validTags.ContainsKey($_) })
238+
Write-Host "GitHub release title filtering: $originalTagCount -> $($tags.Count) tags"
239+
240+
if ($tags.Count -le 0)
241+
{
242+
throw "Found no tags with GitHub releases matching title pattern '$GhTitlePattern'"
243+
}
244+
}
245+
catch
246+
{
247+
# If it's our specific "no matching tags" error, re-throw it
248+
if ($_.Exception.Message -like "*Found no tags with GitHub releases matching title pattern*")
249+
{
250+
throw
251+
}
252+
# Otherwise, wrap it as a GitHub API error
253+
throw "Failed to fetch GitHub releases for $owner/$repo`: $($_.Exception.Message)"
254+
}
255+
}
256+
else
257+
{
258+
throw "Could not parse GitHub owner/repo from URL: $url"
259+
}
260+
}
261+
191262
if ("$Pattern" -eq '')
192263
{
193264
# Use a default pattern that excludes pre-releases

updater/tests/update-dependency.Tests.ps1

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
BeforeAll {
2-
function UpdateDependency([Parameter(Mandatory = $true)][string] $path, [string] $pattern = $null)
2+
function UpdateDependency([Parameter(Mandatory = $true)][string] $path, [string] $pattern = $null, [string] $ghTitlePattern = $null)
33
{
4-
$result = & "$PSScriptRoot/../scripts/update-dependency.ps1" -Path $path -Pattern $pattern
4+
$params = @{ Path = $path }
5+
if ($pattern) { $params.Pattern = $pattern }
6+
if ($ghTitlePattern) { $params.GhTitlePattern = $ghTitlePattern }
7+
8+
$result = & "$PSScriptRoot/../scripts/update-dependency.ps1" @params
59
if (-not $?)
610
{
711
throw $result
@@ -426,4 +430,49 @@ FetchContent_Declare(
426430
{ UpdateDependency "$testFile#nonexistent" } | Should -Throw "*FetchContent_Declare for 'nonexistent' not found*"
427431
}
428432
}
433+
434+
Context 'gh-title-pattern' {
435+
It 'filters by GitHub release title pattern' {
436+
$testFile = "$testDir/test.properties"
437+
# Use sentry-cocoa repo which has releases with "(Stable)" suffix
438+
$repo = 'https://github.com/getsentry/sentry-cocoa'
439+
@("repo=$repo", 'version=0') | Out-File $testFile
440+
441+
# Test filtering for releases with "(Stable)" suffix
442+
UpdateDependency $testFile '' '\(Stable\)$'
443+
444+
$content = Get-Content $testFile
445+
$version = ($content | Where-Object { $_ -match '^version\s*=\s*(.+)$' }) -replace '^version\s*=\s*', ''
446+
447+
# Verify that a version was selected (should be a stable release)
448+
$version | Should -Not -Be '0'
449+
$version | Should -Match '^\d+\.\d+\.\d+$'
450+
}
451+
452+
It 'throws error when no releases match title pattern' {
453+
$testFile = "$testDir/test.properties"
454+
# Use a smaller repo that's less likely to timeout
455+
$repo = 'https://github.com/getsentry/github-workflows'
456+
@("repo=$repo", 'version=0') | Out-File $testFile
457+
458+
# Use a pattern that should match no releases
459+
{ UpdateDependency $testFile '' 'NonExistentPattern' } | Should -Throw '*Found no tags with GitHub releases matching title pattern*'
460+
}
461+
462+
It 'works without title pattern (backward compatibility)' {
463+
$testFile = "$testDir/test.properties"
464+
$repo = 'https://github.com/getsentry/sentry-cocoa'
465+
@("repo=$repo", 'version=0') | Out-File $testFile
466+
467+
# Test without title pattern should work as before
468+
UpdateDependency $testFile '^8\.'
469+
470+
$content = Get-Content $testFile
471+
$version = ($content | Where-Object { $_ -match '^version\s*=\s*(.+)$' }) -replace '^version\s*=\s*', ''
472+
473+
# Should get a version starting with 8
474+
$version | Should -Match '^8\.'
475+
}
476+
477+
}
429478
}

0 commit comments

Comments
 (0)