From 9a89c02929c365617f9db622a55168945d846c9d Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Wed, 25 Mar 2026 14:28:31 +0000 Subject: [PATCH 1/4] 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. --- .github/workflows/test.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6265931e..9cfeabea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -215,7 +215,6 @@ jobs: # This job runs only if a feature branch is specified in the merge request description. # The line below looks for a line starting with `OFM Feature Branch:`. This should # match the `grep` command in the step script. - if: contains(toJson(github.event.pull_request.body), '\r\nOFM Feature Branch:') runs-on: ubuntu-latest outputs: feature-branch: ${{ steps.determine-feature-branch.outputs.feature-branch}} @@ -229,9 +228,15 @@ jobs: # out. run: | matching_line=$(echo "$PULL_REQUEST_BODY" | grep "^OFM Feature Branch:") - feature_branch="${matching_line##"OFM Feature Branch: "}" - echo "Using feature branch '$feature_branch'" - echo "feature-branch=$feature_branch" >> "$GITHUB_OUTPUT" + regex="OFM Feature Branch: ([a-zA-Z0-9_\-]+)" + if [[ $matching_line =~ $regex ]]; then + feature_branch="${BASH_REMATCH[1]}" + echo "Using feature branch '$feature_branch'" + echo "feature-branch=$feature_branch" >> "$GITHUB_OUTPUT" + else + echo "No feature branch found." + echo "feature-branch=''" >> "$GITHUB_OUTPUT" + fi id: determine-feature-branch test-against-ofm-feature-branch: @@ -239,6 +244,7 @@ jobs: # It is split from that job in order to allow re-use of the steps from # test-against-ofm-v3 needs: check-for-ofm-feature-branch + if: ${{ needs.check-for-ofm-feature-branch.outputs.feature-branch }} runs-on: ubuntu-latest continue-on-error: true defaults: From 446c25532bf2f4dfacbfbfd0d59656ce0d774355 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Wed, 25 Mar 2026 16:44:16 +0000 Subject: [PATCH 2/4] Don't hide test failures Given that we can still merge if the workflow fails, it feels best to remove the `continue-on-error` setting from the jobs that test against OFM. This isn't intended to be a change of policy, but it will make failures more visible. --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9cfeabea..52346ed6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -161,7 +161,6 @@ jobs: test-against-ofm-v3: runs-on: ubuntu-latest - continue-on-error: true defaults: run: working-directory: ../openflexure-microscope-server/ From 1c77aebbd06192f8e40a2a3d744b43aefe18f03c Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Thu, 26 Mar 2026 11:30:11 +0000 Subject: [PATCH 3/4] Use an action for regex matching This replaces my unpleasant bash script with a much clearer action --- .github/workflows/test.yml | 51 ++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 52346ed6..618b42fe 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -210,46 +210,37 @@ jobs: - name: Type check with `mypy` run: mypy src - check-for-ofm-feature-branch: - # This job runs only if a feature branch is specified in the merge request description. - # The line below looks for a line starting with `OFM Feature Branch:`. This should - # match the `grep` command in the step script. + analyse-pr-description: + # This job uses a regex to match the feature branch specified in the + # PR description. If there isn't one, it should be an empty string. runs-on: ubuntu-latest outputs: - feature-branch: ${{ steps.determine-feature-branch.outputs.feature-branch}} + feature-branch: ${{ steps.regex-match.outputs.group1 }} steps: - - name: Determine feature branch - env: - PULL_REQUEST_BODY: ${{ github.event.pull_request.body }} - # The `if:` block for this job has already checked we will have a matching line. - # The logic below will first extract the matching line from the PR description, - # then remove the prefix so we're left with only the branch name, which we check - # out. + - name: Check the pull request body for an OFM feature branch + id: regex-match + uses: KyoriPowered/action-regex-match@v3 + with: + text: ${{ github.event.pull_request.body }} + regex: '^\s*OFM[ \-_]Feature[ \-_]Branch:\s*([\w\-]+)' + flags: 'mi' + + - name: Print the recovered branch run: | - matching_line=$(echo "$PULL_REQUEST_BODY" | grep "^OFM Feature Branch:") - regex="OFM Feature Branch: ([a-zA-Z0-9_\-]+)" - if [[ $matching_line =~ $regex ]]; then - feature_branch="${BASH_REMATCH[1]}" - echo "Using feature branch '$feature_branch'" - echo "feature-branch=$feature_branch" >> "$GITHUB_OUTPUT" - else - echo "No feature branch found." - echo "feature-branch=''" >> "$GITHUB_OUTPUT" - fi - id: determine-feature-branch + echo "Matched string: '${{ steps.regex-match.outputs.match }}'" + echo "Matched group: '${{ steps.regex-match.outputs.group1 }}'" test-against-ofm-feature-branch: - # This job uses the feature branch found by the previous job. - # It is split from that job in order to allow re-use of the steps from - # test-against-ofm-v3 - needs: check-for-ofm-feature-branch - if: ${{ needs.check-for-ofm-feature-branch.outputs.feature-branch }} + # This job uses the feature branch found by `analyse-pr-description`. + # If that job didn't find a feature branch, it will be an empty string + # so this job won't run. + needs: analyse-pr-description + if: needs.analyse-pr-description.outputs.feature-branch != '' runs-on: ubuntu-latest continue-on-error: true defaults: run: working-directory: ../openflexure-microscope-server/ env: - REF: ${{ needs.check-for-ofm-feature-branch.outputs.feature-branch }} + REF: ${{ needs.analyse-pr-description.outputs.feature-branch }} steps: *test-against-ofm-steps - From 8adc4f20717b68a79c7098e9a04e952dab99c98b Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Thu, 26 Mar 2026 14:21:08 +0000 Subject: [PATCH 4/4] Permit dots and slashes in git refs This gives slightly more flexibility in specifying the git ref to test against. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 618b42fe..2e68f9b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -222,7 +222,7 @@ jobs: uses: KyoriPowered/action-regex-match@v3 with: text: ${{ github.event.pull_request.body }} - regex: '^\s*OFM[ \-_]Feature[ \-_]Branch:\s*([\w\-]+)' + regex: '^\s*OFM[ \-_]Feature[ \-_]Branch:\s*([\w\-./]+)' flags: 'mi' - name: Print the recovered branch