Skip to content

Commit 1149fd2

Browse files
vaindclaude
andcommitted
feat: allow updater to target non-default branches
Add support for `target-branch` input parameter to allow dependency updates on branches other than the repository's default branch. This enables updating alpha, beta, or version-specific branches. - Add `target-branch` input parameter to action.yml - Modify base branch detection to use target-branch when provided - Update README with parameter documentation and usage example - Add workflow test for target-branch functionality Fixes #87 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent de9e3fa commit 1149fd2

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

.github/workflows/workflow-tests.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,70 @@ jobs:
7373
7474
echo "✅ PR creation scenario validation passed!"
7575
76+
# Test target-branch functionality - should use specified branch as base
77+
updater-target-branch:
78+
runs-on: ubuntu-latest
79+
steps:
80+
- uses: actions/checkout@v4
81+
82+
- name: Run updater action with target-branch
83+
id: updater
84+
uses: ./updater
85+
with:
86+
path: updater/tests/sentry-cli.properties
87+
name: TARGET-BRANCH-TEST-DO-NOT-MERGE
88+
pattern: '^2\.0\.'
89+
target-branch: test-branch
90+
pr-strategy: update
91+
api-token: ${{ github.token }}
92+
93+
- name: Validate target-branch outputs
94+
env:
95+
BASE_BRANCH: ${{ steps.updater.outputs.baseBranch }}
96+
ORIGINAL_TAG: ${{ steps.updater.outputs.originalTag }}
97+
LATEST_TAG: ${{ steps.updater.outputs.latestTag }}
98+
PR_URL: ${{ steps.updater.outputs.prUrl }}
99+
PR_BRANCH: ${{ steps.updater.outputs.prBranch }}
100+
run: |
101+
echo "🔍 Validating target-branch scenario outputs..."
102+
echo "Base Branch: '$BASE_BRANCH'"
103+
echo "Original Tag: '$ORIGINAL_TAG'"
104+
echo "Latest Tag: '$LATEST_TAG'"
105+
echo "PR URL: '$PR_URL'"
106+
echo "PR Branch: '$PR_BRANCH'"
107+
108+
# Validate base branch is the specified target-branch
109+
if [[ "$BASE_BRANCH" != "test-branch" ]]; then
110+
echo "❌ Expected base branch 'test-branch', got '$BASE_BRANCH'"
111+
exit 1
112+
fi
113+
114+
# Validate original tag is expected test value
115+
if [[ "$ORIGINAL_TAG" != "2.0.0" ]]; then
116+
echo "❌ Expected original tag '2.0.0', got '$ORIGINAL_TAG'"
117+
exit 1
118+
fi
119+
120+
# Validate latest tag is a valid version
121+
if [[ ! "$LATEST_TAG" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
122+
echo "❌ Latest tag '$LATEST_TAG' is not a valid version format"
123+
exit 1
124+
fi
125+
126+
# Validate PR URL format
127+
if [[ ! "$PR_URL" =~ ^https://github\.com/getsentry/github-workflows/pull/[0-9]+$ ]]; then
128+
echo "❌ PR URL '$PR_URL' is not a valid GitHub PR URL"
129+
exit 1
130+
fi
131+
132+
# Validate PR branch format
133+
if [[ "$PR_BRANCH" != "deps/updater/tests/sentry-cli.properties" ]]; then
134+
echo "❌ Expected PR branch 'deps/updater/tests/sentry-cli.properties', got '$PR_BRANCH'"
135+
exit 1
136+
fi
137+
138+
echo "✅ Target-branch scenario validation passed!"
139+
76140
# Test no-change scenario - should detect no updates needed
77141
updater-no-changes:
78142
runs-on: macos-latest

updater/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ jobs:
8282
path: vendor/dependencies.cmake#googletest
8383
name: GoogleTest
8484
api-token: ${{ secrets.CI_DEPLOY_KEY }}
85+
86+
# Update dependencies on a non-default branch (e.g., alpha, beta, or version branches)
87+
cocoa-v7:
88+
runs-on: ubuntu-latest
89+
steps:
90+
- uses: getsentry/github-workflows/updater@v3
91+
with:
92+
path: modules/sentry-cocoa
93+
name: Cocoa SDK
94+
target-branch: v7
95+
pattern: '^1\.' # Limit to major version '1'
96+
api-token: ${{ secrets.CI_DEPLOY_KEY }}
8597
```
8698
8799
## Inputs
@@ -118,6 +130,10 @@ jobs:
118130
Can be either of the following:
119131
* `create` (default) - create a new PR for new dependency versions as they are released - maintainers may merge or close older PRs manually
120132
* `update` - keep a single PR that gets updated with new dependency versions until merged - only the latest version update is available at any time
133+
* `target-branch`: Branch to use as base for dependency updates. Defaults to repository default branch if not specified.
134+
* type: string
135+
* required: false
136+
* default: '' (uses repository default branch)
121137
* `api-token`: Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`.
122138
If you provide the usual `${{ github.token }}`, no followup CI will run on the created PR.
123139
If you want CI to run on the PRs created by the Updater, you need to provide custom user-specific auth token.

updater/action.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ inputs:
2929
description: 'How to handle PRs - can be either "create" (create new PRs for each version) or "update" (keep single PR updated with latest version)'
3030
required: false
3131
default: 'create'
32+
target-branch:
33+
description: 'Branch to use as base for dependency updates. Defaults to repository default branch if not specified.'
34+
required: false
35+
default: ''
3236
api-token:
3337
description: 'Token for the repo. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
3438
required: true
@@ -122,8 +126,13 @@ runs:
122126
env:
123127
PR_STRATEGY: ${{ inputs.pr-strategy }}
124128
DEPENDENCY_PATH: ${{ inputs.path }}
129+
TARGET_BRANCH: ${{ inputs.target-branch }}
125130
run: |
126-
$mainBranch = $(git remote show origin | Select-String "HEAD branch: (.*)").Matches[0].Groups[1].Value
131+
if ([string]::IsNullOrEmpty($env:TARGET_BRANCH)) {
132+
$mainBranch = $(git remote show origin | Select-String "HEAD branch: (.*)").Matches[0].Groups[1].Value
133+
} else {
134+
$mainBranch = $env:TARGET_BRANCH
135+
}
127136
$prBranch = switch ($env:PR_STRATEGY)
128137
{
129138
'create' { "deps/$env:DEPENDENCY_PATH/${{ steps.target.outputs.latestTag }}" }

0 commit comments

Comments
 (0)