From 7aeb6acd809a5e4d1bf506b4e59eca373c5aeac4 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Mon, 23 Mar 2026 23:30:15 +0000 Subject: [PATCH 1/5] Use custom branch for OFM test This will look for a branch called `v3-labthings-branch` and fall back to `v3-labthings-main` then `v3` if it doesn't exist. I've added a line to print the branch that's actually checked out. --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e4ebcfb6..e711aae7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -178,7 +178,9 @@ jobs: run: | git clone https://gitlab.com/openflexure/openflexure-microscope-server.git cd openflexure-microscope-server - git checkout v3 + git checkout v3-labthings-${{ github.head_ref }} || git checkout v3-labthings-main || git checkout v3 + git rev-parse --abbrev-ref HEAD + git rev-parse HEAD pip install -e .[dev] - name: Install LabThings-FastAPI From ea065dfe09859dede8625f91f78fccd1e9e5662e Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Mon, 23 Mar 2026 23:37:14 +0000 Subject: [PATCH 2/5] Rename publish workflow and run only on tags. This should tidy up the "checks" tab in merge requests. --- .github/workflows/publish.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5bac0501..20f6044e 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,10 +1,11 @@ -name: Publish to TestPyPI +name: Publish to PyPI -on: push - -#on: -# release: -# types: [published] +on: + push: + # Only try to publish if it's tagged + tags: + - v** + - testpypi-v** jobs: build: From 20399cb07a8d97b2e12c7faefaa58e21ea5022bd Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 24 Mar 2026 10:51:36 +0000 Subject: [PATCH 3/5] Test against feature branch if requested It's now possible to add a line to the PR description that starts with "OFM Feature Branch:". This specifies a feature branch to test against. There's some CI logic to: * Run the job only if a matching line is present * Extract the matching line from the PR description * Check out the relevant branch. --- .github/workflows/test.yml | 69 +++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e711aae7..3596d899 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -159,7 +159,7 @@ jobs: send-summary-comment: true show-annotations: "warning" - test-against-ofm: + test-against-ofm-v3: runs-on: ubuntu-latest continue-on-error: true defaults: @@ -178,9 +178,7 @@ jobs: run: | git clone https://gitlab.com/openflexure/openflexure-microscope-server.git cd openflexure-microscope-server - git checkout v3-labthings-${{ github.head_ref }} || git checkout v3-labthings-main || git checkout v3 - git rev-parse --abbrev-ref HEAD - git rev-parse HEAD + git checkout v3 pip install -e .[dev] - name: Install LabThings-FastAPI @@ -208,3 +206,66 @@ jobs: - name: Type check with `mypy` run: mypy src + + test-against-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 relevant step. + if: contains(toJson(github.event.pull_request.body), '\r\nOFM Feature Branch:') + runs-on: ubuntu-latest + continue-on-error: true + defaults: + run: + working-directory: /home/runner/work/openflexure-microscope-server/ + steps: + - uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + + - name: Clone OpenFlexure Microscope Server + working-directory: /home/runner/work/ + run: git clone https://gitlab.com/openflexure/openflexure-microscope-server.git + + - name: Checkout 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. + run: | + matching_line=$(echo "${PULL_REQUEST_BODY}" | grep "^OFM Feature Branch:") + feature_branch="${matching_line##"OFM Feature Branch: "}" + git checkout "${feature_branch}" + + - name: Install OpenFlexure Microscope Server + run: pip install -e .[dev] + + - name: Install LabThings-FastAPI + run: pip install -e ../labthings-fastapi/labthings-fastapi/ + + - name: Print installed packages + run: pip freeze + + - name: Configure Git identity + run: | + git config --global user.name "Sir Unit of Test" + git config --global user.email "bogus@email.com" + + - name: Pull OFM web app + run: python ./pull_webapp.py + + - name: Run OFM unit tests + run: pytest + + - name: Run OFM integration tests + run: pytest tests/integration_tests + + - name: Run OFM lifecycle test + run: tests/lifecycle_test/testfile.py + + - name: Type check with `mypy` + run: mypy src \ No newline at end of file From 5783a02cb487f8a8019ae25c39baa75d4f68c9c3 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Tue, 24 Mar 2026 16:38:57 +0000 Subject: [PATCH 4/5] Update .github/workflows/publish.yml Co-authored-by: Beth <167304066+bprobert97@users.noreply.github.com> --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 20f6044e..4fbe75e9 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,8 +4,8 @@ on: push: # Only try to publish if it's tagged tags: - - v** - - testpypi-v** + - 'v*' + - 'testpypi-v*' jobs: build: From 7457105b8afba2891f0efca3059ba5ee8f9c7165 Mon Sep 17 00:00:00 2001 From: Richard Bowman Date: Wed, 25 Mar 2026 09:45:53 +0000 Subject: [PATCH 5/5] Deduplicate and use relative working directories This uses YAML anchors to reduce duplication, and switches to relative paths for the working directories. GitHub Workflows don't offer a way to merge YAML arrays, so I've needed to split the feature branch job so that it determines the name of the feature branch in a separate job. I spent a while playing with a custom action to deduplicate the steps, but it doesn't work as nicely. I also removed some unnecessary curly braces. --- .github/workflows/test.yml | 99 +++++++++++++++----------------------- 1 file changed, 39 insertions(+), 60 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3596d899..6265931e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -164,28 +164,32 @@ jobs: continue-on-error: true defaults: run: - working-directory: /home/runner/work/openflexure-microscope-server/ - steps: + working-directory: ../openflexure-microscope-server/ + env: + REF: v3 + steps: &test-against-ofm-steps - uses: actions/checkout@v3 - - name: Set up Python - uses: actions/setup-python@v4 + - uses: actions/setup-python@v4 with: - python-version: 3.11 + python-version: '3.11' - - name: Install OpenFlexure Microscope Server - working-directory: /home/runner/work/ + - name: Clone OpenFlexure Microscope Server + working-directory: .. # This step creates the default working directory run: | git clone https://gitlab.com/openflexure/openflexure-microscope-server.git - cd openflexure-microscope-server - git checkout v3 - pip install -e .[dev] + + - name: Check out OpenFlexure Microscope Server + run: "git checkout $REF" + + - name: Install OpenFlexure Microscope Server + run: "pip install -e ../openflexure-microscope-server/[dev]" - name: Install LabThings-FastAPI - run: pip install -e ../labthings-fastapi/labthings-fastapi/ + run: "pip install -e ../labthings-fastapi" - name: Print installed packages - run: pip freeze + run: "pip freeze" - name: Configure Git identity run: | @@ -207,29 +211,16 @@ jobs: - name: Type check with `mypy` run: mypy src - test-against-ofm-feature-branch: + 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 relevant step. + # match the `grep` command in the step script. if: contains(toJson(github.event.pull_request.body), '\r\nOFM Feature Branch:') runs-on: ubuntu-latest - continue-on-error: true - defaults: - run: - working-directory: /home/runner/work/openflexure-microscope-server/ + outputs: + feature-branch: ${{ steps.determine-feature-branch.outputs.feature-branch}} steps: - - uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.11 - - - name: Clone OpenFlexure Microscope Server - working-directory: /home/runner/work/ - run: git clone https://gitlab.com/openflexure/openflexure-microscope-server.git - - - name: Checkout feature branch + - 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. @@ -237,35 +228,23 @@ jobs: # then remove the prefix so we're left with only the branch name, which we check # out. run: | - matching_line=$(echo "${PULL_REQUEST_BODY}" | grep "^OFM Feature Branch:") + matching_line=$(echo "$PULL_REQUEST_BODY" | grep "^OFM Feature Branch:") feature_branch="${matching_line##"OFM Feature Branch: "}" - git checkout "${feature_branch}" - - - name: Install OpenFlexure Microscope Server - run: pip install -e .[dev] - - - name: Install LabThings-FastAPI - run: pip install -e ../labthings-fastapi/labthings-fastapi/ - - - name: Print installed packages - run: pip freeze - - - name: Configure Git identity - run: | - git config --global user.name "Sir Unit of Test" - git config --global user.email "bogus@email.com" - - - name: Pull OFM web app - run: python ./pull_webapp.py - - - name: Run OFM unit tests - run: pytest - - - name: Run OFM integration tests - run: pytest tests/integration_tests + echo "Using feature branch '$feature_branch'" + echo "feature-branch=$feature_branch" >> "$GITHUB_OUTPUT" + id: determine-feature-branch + + 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 + 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 }} + steps: *test-against-ofm-steps - - name: Run OFM lifecycle test - run: tests/lifecycle_test/testfile.py - - - name: Type check with `mypy` - run: mypy src \ No newline at end of file