Skip to content

Commit 5d60d71

Browse files
committed
Use a regex to match feature branch
I had some odd issues where the feature branch seemed to contain junk characters at the end. This changes two things: 1. We now match the branch name more robustly with a regex. 2. We no longer use an `if` condition on `check-for-ofm-feature-branch`, instead it will just return an empty string. There's now an `if` condition on the `test-against-ofm-feature-branch` job.
1 parent 75e6e30 commit 5d60d71

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ jobs:
215215
# This job runs only if a feature branch is specified in the merge request description.
216216
# The line below looks for a line starting with `OFM Feature Branch:`. This should
217217
# match the `grep` command in the step script.
218-
if: contains(toJson(github.event.pull_request.body), '\r\nOFM Feature Branch:')
219-
runs-on: ubuntu-latest
218+
runs-on: alpine
220219
outputs:
221220
feature-branch: ${{ steps.determine-feature-branch.outputs.feature-branch}}
222221
steps:
@@ -229,16 +228,23 @@ jobs:
229228
# out.
230229
run: |
231230
matching_line=$(echo "$PULL_REQUEST_BODY" | grep "^OFM Feature Branch:")
232-
feature_branch="${matching_line##"OFM Feature Branch: "}"
233-
echo "Using feature branch '$feature_branch'"
234-
echo "feature-branch=$feature_branch" >> "$GITHUB_OUTPUT"
231+
regex="OFM Feature Branch: ([a-zA-Z0-9_\-]+)"
232+
if [[ $matching_line =~ $regex ]]; then
233+
feature_branch="${BASH_REMATCH[1]}"
234+
echo "Using feature branch '$feature_branch'"
235+
echo "feature-branch=$feature_branch" >> "$GITHUB_OUTPUT"
236+
else
237+
echo "No feature branch found."
238+
echo "feature-branch=''" >> "$GITHUB_OUTPUT"
239+
fi
235240
id: determine-feature-branch
236241

237242
test-against-ofm-feature-branch:
238243
# This job uses the feature branch found by the previous job.
239244
# It is split from that job in order to allow re-use of the steps from
240245
# test-against-ofm-v3
241246
needs: check-for-ofm-feature-branch
247+
if: ${{ needs.check-for-ofm-feature-branch.outputs.feature-branch }}
242248
runs-on: ubuntu-latest
243249
continue-on-error: true
244250
defaults:

0 commit comments

Comments
 (0)