Skip to content

Commit 75e6e30

Browse files
authored
Merge pull request #293 from labthings/ci-improvements
CI improvements
2 parents 90c0a60 + 7457105 commit 75e6e30

File tree

2 files changed

+62
-19
lines changed

2 files changed

+62
-19
lines changed

.github/workflows/publish.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
name: Publish to TestPyPI
1+
name: Publish to PyPI
22

3-
on: push
4-
5-
#on:
6-
# release:
7-
# types: [published]
3+
on:
4+
push:
5+
# Only try to publish if it's tagged
6+
tags:
7+
- 'v*'
8+
- 'testpypi-v*'
89

910
jobs:
1011
build:

.github/workflows/test.yml

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,37 @@ jobs:
159159
send-summary-comment: true
160160
show-annotations: "warning"
161161

162-
test-against-ofm:
162+
test-against-ofm-v3:
163163
runs-on: ubuntu-latest
164164
continue-on-error: true
165165
defaults:
166166
run:
167-
working-directory: /home/runner/work/openflexure-microscope-server/
168-
steps:
167+
working-directory: ../openflexure-microscope-server/
168+
env:
169+
REF: v3
170+
steps: &test-against-ofm-steps
169171
- uses: actions/checkout@v3
170172

171-
- name: Set up Python
172-
uses: actions/setup-python@v4
173+
- uses: actions/setup-python@v4
173174
with:
174-
python-version: 3.11
175+
python-version: '3.11'
175176

176-
- name: Install OpenFlexure Microscope Server
177-
working-directory: /home/runner/work/
177+
- name: Clone OpenFlexure Microscope Server
178+
working-directory: .. # This step creates the default working directory
178179
run: |
179180
git clone https://gitlab.com/openflexure/openflexure-microscope-server.git
180-
cd openflexure-microscope-server
181-
git checkout v3
182-
pip install -e .[dev]
181+
182+
- name: Check out OpenFlexure Microscope Server
183+
run: "git checkout $REF"
184+
185+
- name: Install OpenFlexure Microscope Server
186+
run: "pip install -e ../openflexure-microscope-server/[dev]"
183187

184188
- name: Install LabThings-FastAPI
185-
run: pip install -e ../labthings-fastapi/labthings-fastapi/
189+
run: "pip install -e ../labthings-fastapi"
186190

187191
- name: Print installed packages
188-
run: pip freeze
192+
run: "pip freeze"
189193

190194
- name: Configure Git identity
191195
run: |
@@ -206,3 +210,41 @@ jobs:
206210

207211
- name: Type check with `mypy`
208212
run: mypy src
213+
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:')
219+
runs-on: ubuntu-latest
220+
outputs:
221+
feature-branch: ${{ steps.determine-feature-branch.outputs.feature-branch}}
222+
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.
230+
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
236+
237+
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
242+
runs-on: ubuntu-latest
243+
continue-on-error: true
244+
defaults:
245+
run:
246+
working-directory: ../openflexure-microscope-server/
247+
env:
248+
REF: ${{ needs.check-for-ofm-feature-branch.outputs.feature-branch }}
249+
steps: *test-against-ofm-steps
250+

0 commit comments

Comments
 (0)