Skip to content

Commit 99aa380

Browse files
authored
Merge pull request #296 from labthings/fix-feature-branch-detection
Use a regex to match feature branch
2 parents d01f53e + 8adc4f2 commit 99aa380

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

.github/workflows/test.yml

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ jobs:
161161

162162
test-against-ofm-v3:
163163
runs-on: ubuntu-latest
164-
continue-on-error: true
165164
defaults:
166165
run:
167166
working-directory: ../openflexure-microscope-server/
@@ -211,40 +210,37 @@ jobs:
211210
- name: Type check with `mypy`
212211
run: mypy src
213212

214-
check-for-ofm-feature-branch:
215-
# This job runs only if a feature branch is specified in the merge request description.
216-
# The line below looks for a line starting with `OFM Feature Branch:`. This should
217-
# match the `grep` command in the step script.
218-
if: contains(toJson(github.event.pull_request.body), '\r\nOFM Feature Branch:')
213+
analyse-pr-description:
214+
# This job uses a regex to match the feature branch specified in the
215+
# PR description. If there isn't one, it should be an empty string.
219216
runs-on: ubuntu-latest
220217
outputs:
221-
feature-branch: ${{ steps.determine-feature-branch.outputs.feature-branch}}
218+
feature-branch: ${{ steps.regex-match.outputs.group1 }}
222219
steps:
223-
- name: Determine feature branch
224-
env:
225-
PULL_REQUEST_BODY: ${{ github.event.pull_request.body }}
226-
# The `if:` block for this job has already checked we will have a matching line.
227-
# The logic below will first extract the matching line from the PR description,
228-
# then remove the prefix so we're left with only the branch name, which we check
229-
# out.
220+
- name: Check the pull request body for an OFM feature branch
221+
id: regex-match
222+
uses: KyoriPowered/action-regex-match@v3
223+
with:
224+
text: ${{ github.event.pull_request.body }}
225+
regex: '^\s*OFM[ \-_]Feature[ \-_]Branch:\s*([\w\-./]+)'
226+
flags: 'mi'
227+
228+
- name: Print the recovered branch
230229
run: |
231-
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"
235-
id: determine-feature-branch
230+
echo "Matched string: '${{ steps.regex-match.outputs.match }}'"
231+
echo "Matched group: '${{ steps.regex-match.outputs.group1 }}'"
236232
237233
test-against-ofm-feature-branch:
238-
# This job uses the feature branch found by the previous job.
239-
# It is split from that job in order to allow re-use of the steps from
240-
# test-against-ofm-v3
241-
needs: check-for-ofm-feature-branch
234+
# This job uses the feature branch found by `analyse-pr-description`.
235+
# If that job didn't find a feature branch, it will be an empty string
236+
# so this job won't run.
237+
needs: analyse-pr-description
238+
if: needs.analyse-pr-description.outputs.feature-branch != ''
242239
runs-on: ubuntu-latest
243240
continue-on-error: true
244241
defaults:
245242
run:
246243
working-directory: ../openflexure-microscope-server/
247244
env:
248-
REF: ${{ needs.check-for-ofm-feature-branch.outputs.feature-branch }}
245+
REF: ${{ needs.analyse-pr-description.outputs.feature-branch }}
249246
steps: *test-against-ofm-steps
250-

0 commit comments

Comments
 (0)