Skip to content

Commit 747517a

Browse files
vaindclaude
andauthored
feat: Allow updater to target non-default branches (#118)
* 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]> * docs: clarify limitations for updating dependencies on non-default branches * docs: add changelog entry for target-branch feature * fix: use existing branch for target-branch test The test was failing because 'test-branch' doesn't exist in this repository. Changed to use the existing 'test/nonbot-commits' branch instead. * fix: checkout target branch before making changes The previous implementation was creating PRs with the entire diff between the default branch and target branch. Now we properly checkout the target branch first, then make dependency updates on top of it. This ensures PRs only contain the dependency changes, not all differences between branches. * refactor: use actions/checkout ref parameter instead of separate git commands Much cleaner approach using the built-in ref parameter of actions/checkout to directly checkout the target branch instead of manual git commands. Uses: ref: ${{ inputs.target-branch || github.ref }} - If target-branch is provided, checkout that branch - Otherwise, use the default behavior (github.ref) * refactor: update checkout paths in workflow tests and remove redundant checkout step in updater action * fix: correct paths for checkout and updater action in workflow tests * fix: set working directory to caller-repo for all relevant steps in the updater action * roll back workflow-test changes * fix: update working directory path for create-pull-request action * fix: prepend main branch name to PR branch for better organization * fix: prepend PR branch prefix to generated branch name based on strategy * fix: update expected PR branch format in validation step --------- Co-authored-by: Claude <[email protected]>
1 parent de9e3fa commit 747517a

File tree

4 files changed

+112
-8
lines changed

4 files changed

+112
-8
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/nonbot-commits
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/nonbot-commits" ]]; then
110+
echo "❌ Expected base branch 'test/nonbot-commits', 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" != "test/nonbot-commits-deps/updater/tests/sentry-cli.properties" ]]; then
134+
echo "❌ Expected PR branch 'test/nonbot-commits-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

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ To update your existing Danger workflows:
4444
4545
### Features
4646
47+
- Updater now supports targeting non-default branches via the new `target-branch` input parameter ([#118](https://github.com/getsentry/github-workflows/pull/118))
4748
- Updater now supports filtering releases by GitHub release title patterns, e.g. to support release channels ([#117](https://github.com/getsentry/github-workflows/pull/117))
4849
- Updater now supports dependencies without changelog files by falling back to git commit messages ([#116](https://github.com/getsentry/github-workflows/pull/116))
4950
- Danger - Improve conventional commit scope handling, and non-conventional PR title support ([#105](https://github.com/getsentry/github-workflows/pull/105))

updater/README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ 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+
# Note: due to limitations in GitHub Actions' schedule trigger, this code needs to be pushed to the default branch.
88+
cocoa-v7:
89+
runs-on: ubuntu-latest
90+
steps:
91+
- uses: getsentry/github-workflows/updater@v3
92+
with:
93+
path: modules/sentry-cocoa
94+
name: Cocoa SDK
95+
target-branch: v7
96+
pattern: '^1\.' # Limit to major version '1'
97+
api-token: ${{ secrets.CI_DEPLOY_KEY }}
8598
```
8699
87100
## Inputs
@@ -118,6 +131,10 @@ jobs:
118131
Can be either of the following:
119132
* `create` (default) - create a new PR for new dependency versions as they are released - maintainers may merge or close older PRs manually
120133
* `update` - keep a single PR that gets updated with new dependency versions until merged - only the latest version update is available at any time
134+
* `target-branch`: Branch to use as base for dependency updates. Defaults to repository default branch if not specified.
135+
* type: string
136+
* required: false
137+
* default: '' (uses repository default branch)
121138
* `api-token`: Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`.
122139
If you provide the usual `${{ github.token }}`, no followup CI will run on the created PR.
123140
If you want CI to run on the PRs created by the Updater, you need to provide custom user-specific auth token.
@@ -139,4 +156,4 @@ If you're migrating from the v2 reusable workflow, see the [changelog migration
139156
Key changes:
140157
- Add `runs-on` to specify the runner
141158
- Move `secrets.api-token` to `with.api-token`
142-
- No need for explicit `actions/checkout` step (handled internally)
159+
- No need for explicit `actions/checkout` step (handled internally)

updater/action.yml

Lines changed: 29 additions & 7 deletions
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
@@ -53,11 +57,6 @@ outputs:
5357
runs:
5458
using: 'composite'
5559
steps:
56-
- name: Checkout repository
57-
uses: actions/checkout@v4
58-
with:
59-
token: ${{ inputs.api-token }}
60-
6160
- name: Cancel Previous Runs
6261
uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # Tag: 0.12.1
6362
with:
@@ -104,10 +103,13 @@ runs:
104103
uses: actions/checkout@v4
105104
with:
106105
token: ${{ inputs.api-token }}
106+
ref: ${{ inputs.target-branch || github.ref }}
107+
path: caller-repo
107108

108109
- name: Update to the latest version
109110
id: target
110111
shell: pwsh
112+
working-directory: caller-repo
111113
env:
112114
DEPENDENCY_PATH: ${{ inputs.path }}
113115
DEPENDENCY_PATTERN: ${{ inputs.pattern }}
@@ -119,17 +121,26 @@ runs:
119121
if: steps.target.outputs.latestTag != steps.target.outputs.originalTag
120122
id: root
121123
shell: pwsh
124+
working-directory: caller-repo
122125
env:
123126
PR_STRATEGY: ${{ inputs.pr-strategy }}
124127
DEPENDENCY_PATH: ${{ inputs.path }}
128+
TARGET_BRANCH: ${{ inputs.target-branch }}
125129
run: |
126-
$mainBranch = $(git remote show origin | Select-String "HEAD branch: (.*)").Matches[0].Groups[1].Value
130+
if ([string]::IsNullOrEmpty($env:TARGET_BRANCH)) {
131+
$mainBranch = $(git remote show origin | Select-String "HEAD branch: (.*)").Matches[0].Groups[1].Value
132+
$prBranchPrefix = ''
133+
} else {
134+
$mainBranch = $env:TARGET_BRANCH
135+
$prBranchPrefix = "$mainBranch-"
136+
}
127137
$prBranch = switch ($env:PR_STRATEGY)
128138
{
129139
'create' { "deps/$env:DEPENDENCY_PATH/${{ steps.target.outputs.latestTag }}" }
130140
'update' { "deps/$env:DEPENDENCY_PATH" }
131141
default { throw "Unkown PR strategy '$env:PR_STRATEGY'." }
132142
}
143+
$prBranch = $prBranchPrefix + $prBranch
133144
"baseBranch=$mainBranch" | Tee-Object $env:GITHUB_OUTPUT -Append
134145
"prBranch=$prBranch" | Tee-Object $env:GITHUB_OUTPUT -Append
135146
$nonBotCommits = ${{ github.action_path }}/scripts/nonbot-commits.ps1 `
@@ -144,9 +155,10 @@ runs:
144155
- name: Parse the existing PR URL
145156
if: ${{ ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }}
146157
id: existing-pr
158+
shell: pwsh
159+
working-directory: caller-repo
147160
env:
148161
GH_TOKEN: ${{ inputs.api-token }}
149-
shell: pwsh
150162
run: |
151163
$urls = @(gh api 'repos/${{ github.repository }}/pulls?base=${{ steps.root.outputs.baseBranch }}&head=${{ github.repository_owner }}:${{ steps.root.outputs.prBranch }}' --jq '.[].html_url')
152164
if ($urls.Length -eq 0)
@@ -165,11 +177,13 @@ runs:
165177
- name: Show git diff
166178
if: ${{ ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.existing-pr.outputs.url == '') && ( steps.root.outputs.changed == 'false') }}
167179
shell: bash
180+
working-directory: caller-repo
168181
run: git --no-pager diff
169182

170183
- name: Get target changelog
171184
if: ${{ ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }}
172185
shell: pwsh
186+
working-directory: caller-repo
173187
env:
174188
GH_TOKEN: ${{ inputs.api-token }}
175189
run: |
@@ -188,6 +202,7 @@ runs:
188202
DEPENDENCY_PATH: ${{ inputs.path }}
189203
DEPENDENCY_NAME: ${{ inputs.name }}
190204
with:
205+
path: caller-repo
191206
base: ${{ steps.root.outputs.baseBranch }}
192207
branch: ${{ steps.root.outputs.prBranch }}
193208
commit-message: 'chore: update ${{ env.DEPENDENCY_PATH }} to ${{ steps.target.outputs.latestTag }}'
@@ -204,6 +219,7 @@ runs:
204219
if: ${{ ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }}
205220
id: pr
206221
shell: pwsh
222+
working-directory: caller-repo
207223
run: |
208224
if ('${{ steps.create-pr.outputs.pull-request-url }}' -ne '')
209225
{
@@ -225,10 +241,13 @@ runs:
225241
uses: actions/checkout@v4
226242
with:
227243
token: ${{ inputs.api-token }}
244+
ref: ${{ inputs.target-branch || github.ref }}
245+
path: caller-repo
228246

229247
- name: 'After new PR: redo the update'
230248
if: ${{ ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.existing-pr.outputs.url == '') && ( steps.root.outputs.changed == 'false') }}
231249
shell: pwsh
250+
working-directory: caller-repo
232251
env:
233252
DEPENDENCY_PATH: ${{ inputs.path }}
234253
GH_TOKEN: ${{ inputs.api-token }}
@@ -237,6 +256,7 @@ runs:
237256
- name: Update Changelog
238257
if: ${{ inputs.changelog-entry && ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }}
239258
shell: pwsh
259+
working-directory: caller-repo
240260
env:
241261
DEPENDENCY_NAME: ${{ inputs.name }}
242262
CHANGELOG_SECTION: ${{ inputs.changelog-section }}
@@ -254,6 +274,7 @@ runs:
254274
- name: Show final git diff
255275
if: ${{ ( steps.target.outputs.latestTag != steps.target.outputs.originalTag ) && ( steps.root.outputs.changed == 'false') }}
256276
shell: bash
277+
working-directory: caller-repo
257278
run: git --no-pager diff
258279

259280
# Now make the PR in its final state. This way we only have one commit and no updates if there are no changes between runs.
@@ -265,6 +286,7 @@ runs:
265286
DEPENDENCY_PATH: ${{ inputs.path }}
266287
DEPENDENCY_NAME: ${{ inputs.name }}
267288
with:
289+
path: caller-repo
268290
base: ${{ steps.root.outputs.baseBranch }}
269291
branch: ${{ steps.root.outputs.prBranch }}
270292
commit-message: 'chore: update ${{ env.DEPENDENCY_PATH }} to ${{ steps.target.outputs.latestTag }}'

0 commit comments

Comments
 (0)