Skip to content

Commit 932da27

Browse files
committed
wip: add target-branch-pattern
1 parent 7240d2c commit 932da27

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

action.yml

+31-16
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ inputs:
5858
Branch to open pull release PR against. Defaults to the repository's
5959
default branch.
6060
default: ""
61-
maintenance-branch-pattern:
61+
target-branch-pattern:
6262
description: >-
63-
Regex pattern for maintenance branches. Defaults to `^release-[0-9]+(\.[0-9]+)?\.x$`.
64-
default: |-
65-
^release-[0-9]+(\.[0-9]+)?\.x$
63+
Regular expression pattern to determine if current branch is a target
64+
branch. When specified, the action will only run if the current branch
65+
matches the pattern, and the current branch will be used as the target
66+
branch. When not specified, the action will always run, and target the
67+
specified target-branch, or the repository's default branch if
68+
target-branch is not specified.
69+
default: ""
6670
config-file:
6771
description: Path to config file within the project.
6872
default: ".github/release-please-config.json"
@@ -138,8 +142,26 @@ outputs:
138142
runs:
139143
using: "composite"
140144
steps:
145+
- name: prepare
146+
shell: bash
147+
id: prepare
148+
run: |
149+
if [[ -n "$TARGET_BRANCH_PATTERN" ]]; then
150+
if [[ "$GITHUB_REF_NAME" =~ $TARGET_BRANCH_PATTERN ]]; then
151+
RUN="true"
152+
TARGET="$GITHUB_REF_NAME"
153+
fi
154+
else
155+
RUN="true"
156+
fi
157+
158+
echo "target_branch=${TARGET:-$TARGET_BRANCH}" >> "$GITHUB_OUTPUT"
159+
echo "run=${RUN:-false}" >> "$GITHUB_OUTPUT"
160+
env:
161+
TARGET_BRANCH: "${{ inputs.target-branch }}"
162+
TARGET_BRANCH_PATTERN: "${{ inputs.target-branch-pattern }}"
141163
- uses: tibdex/github-app-token@v2
142-
if: inputs.app-id != null && inputs.app-id != ''
164+
if: steps.prepare.outputs.run == 'true' && inputs.app-id != null && inputs.app-id != ''
143165
id: github-app-token
144166
with:
145167
app_id: ${{ inputs.app-id }}
@@ -151,27 +173,20 @@ runs:
151173
repositories: ${{ inputs.repositories }}
152174
revoke: true
153175
- name: resolve token
176+
if: steps.prepare.outputs.run == 'true'
154177
id: token
178+
shell: bash
155179
run: |-
156180
echo "token=${APP_TOKEN:-$INPUT_TOKEN}" >> "$GITHUB_OUTPUT"
157181
env:
158182
APP_TOKEN: "${{ steps.github-app-token.outputs.token }}"
159183
INPUT_TOKEN: "${{ inputs.token }}"
160-
shell: bash
161-
- name: determine target-branch
162-
id: branch
163-
run: |
164-
if [[ -z "${{ inputs.target-branch }}" ]] && [[ "${{ github.ref_name }}" =~ ${{ inputs.maintenance-branch-pattern }} ]]; then
165-
echo "target_branch=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
166-
else
167-
echo "target_branch=${{ inputs.target-branch }}" >> "$GITHUB_OUTPUT"
168-
fi
169-
shell: bash
170184
- uses: googleapis/release-please-action@v4
185+
if: steps.prepare.outputs.run == 'true'
171186
id: release-please
172187
with:
173188
token: ${{ steps.token.outputs.token }}
174-
target-branch: ${{ steps.branch.outputs.target_branch }}
189+
target-branch: ${{ steps.prepare.outputs.target_branch }}
175190
config-file: ${{ inputs.config-file }}
176191
manifest-file: ${{ inputs.manifest-file }}
177192
github-api-url: ${{ inputs.github-api-url }}

0 commit comments

Comments
 (0)