Skip to content

Commit cbea149

Browse files
authored
Merge pull request #475 from bioimage-io/dev
Improve CI
2 parents 75a3532 + ef34892 commit cbea149

File tree

3 files changed

+60
-18
lines changed

3 files changed

+60
-18
lines changed

.github/workflows/build.yaml

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ on:
55
branches: [main]
66
pull_request:
77
branches: ['**']
8+
workflow_dispatch:
9+
inputs:
10+
force-publish:
11+
description: 'Force publish even if no version change detected'
12+
required: false
13+
type: choice
14+
options:
15+
- 'true'
16+
- 'false'
17+
default: 'false'
818

919
defaults:
1020
run:
@@ -143,11 +153,10 @@ jobs:
143153
- uses: actions/upload-artifact@v4
144154
with:
145155
name: coverage-summary
146-
retention-days: 1
147156
path: dist
148157

149158
conda-build:
150-
needs: test # only so we run tests even if the pinned bioimageio.spec version is not yet published on conda-forge yet
159+
needs: [populate-cache, test] # only so we run tests even if the pinned bioimageio.spec version is not yet published on conda-forge
151160
runs-on: ubuntu-latest
152161
steps:
153162
- uses: actions/checkout@v4
@@ -169,14 +178,20 @@ jobs:
169178
pkgs/noarch
170179
pkgs/channeldata.json
171180
key: ${{ github.sha }}-packages
181+
- uses: actions/cache@v4
182+
with:
183+
path: bioimageio_cache
184+
key: ${{needs.populate-cache.outputs.cache-key}}
172185
- name: linux conda build test
173186
shell: bash -l {0}
174187
run: |
175188
mkdir -p ./pkgs/noarch
176189
conda-build -c conda-forge conda-recipe --output-folder ./pkgs
190+
env:
191+
BIOIMAGEIO_CACHE_PATH: bioimageio_cache
177192

178193
docs:
179-
needs: test
194+
needs: [coverage, test]
180195
if: github.ref == 'refs/heads/main'
181196
runs-on: ubuntu-latest
182197
steps:
@@ -234,26 +249,51 @@ jobs:
234249
uses: actions/checkout@v4
235250
with:
236251
fetch-depth: 2
237-
- name: Check if there is a parent commit
238-
id: check-parent-commit
252+
fetch-tags: true
253+
- name: Get parent commit
254+
if: inputs.force-publish != 'true'
255+
id: get-parent-commit
239256
run: |
240257
echo "sha=$(git rev-parse --verify --quiet HEAD^)" >> $GITHUB_OUTPUT
258+
- id: get-existing-tag
259+
if: inputs.force-publish == 'true'
260+
run: echo "existing-tag=$(git tag --points-at HEAD 'v[0-9]*.[0-9]*.[0-9]*')" >> $GITHUB_OUTPUT
241261

242-
- name: Detect new version
262+
- name: Detect new version from last commit and create tag
243263
id: tag-version
244-
if: github.ref == 'refs/heads/main' && steps.check-parent-commit.outputs.sha
264+
if: github.ref == 'refs/heads/main' && steps.get-parent-commit.outputs.sha && inputs.force-publish != 'true'
245265
uses: salsify/[email protected]
246266
with:
247267
create-tag: true
248268
version-command: |
249-
python -c "from pathlib import Path;import json;print(p_src.read_text().split('__version__ = \"')[1].split('\"')[0] if (p_src:=Path('src/bioimageio/core/__init__.py')).exists() else json.loads(Path('bioimageio/core/VERSION').read_text())['version'])"
269+
python -c "from pathlib import Path; p = Path('src/bioimageio/core/__init__.py'); v = p.read_text().split('__version__ = \"')[1].split('\"')[0]; print(v)"
270+
- shell: python
271+
id: get-new-version
272+
run: |
273+
import os
274+
from pathlib import Path
275+
276+
277+
278+
if "${{ inputs.force-publish }}" == "true":
279+
existing_tag = "${{ steps.get-existing-tag.outputs.existing-tag }}"
280+
valid = existing_tag.count("v") == 1 and existing_tag.count(".") == 2 and all(part.isdigit() for part in existing_tag.lstrip("v").split("."))
281+
if not valid:
282+
raise Exception(f"Current commit has invalid version tag {existing_tag}.")
283+
new_version = existing_tag
284+
else:
285+
new_version = "${{ steps.tag-version.outputs.tag }}"
286+
287+
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
288+
print(f"new-version={new_version}", file=f)
289+
250290
- uses: actions/download-artifact@v4
251-
if: github.ref == 'refs/heads/main' && steps.tag-version.outputs.tag
291+
if: github.ref == 'refs/heads/main' && steps.get-new-version.outputs.new-version
252292
with:
253293
name: dist
254294
path: dist
255295
- name: Publish package on PyPI
256-
if: github.ref == 'refs/heads/main' && steps.tag-version.outputs.tag
296+
if: github.ref == 'refs/heads/main' && steps.get-new-version.outputs.new-version
257297
uses: pypa/gh-action-pypi-publish@release/v1
258298
with:
259299
packages-dir: dist/
@@ -262,7 +302,7 @@ jobs:
262302
if: github.ref == 'refs/heads/main'
263303
uses: release-drafter/[email protected]
264304
with:
265-
publish: "${{ steps.tag-version.outputs.tag != '' }}"
266-
tag: '${{ steps.tag-version.outputs.tag }}'
305+
publish: "${{ steps.get-new-version.outputs.new-version != '' }}"
306+
tag: '${{ steps.get-new-version.outputs.new-version }}'
267307
env:
268308
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'

src/bioimageio/core/block_meta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class BlockMeta:
5252
The outer slice reaches from the sample member origin (0, 0) to the right halo point.
5353
5454
```terminal
55-
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐
55+
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
5656
╷ halo(left) ╷
5757
╷ ╷
5858
╷ (0, 0)┏━━━━━━━━━━━━━━━━━┯━━━━━━━━━┯━━━➔

src/bioimageio/core/digest_spec.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,15 @@ def get_input_halo(model: v0_5.ModelDescr, output_halo: PerMember[PerAxis[Halo]]
302302
axis = axes[a]
303303
ref_axis = {a.id: a for a in all_tensors[s.tensor_id].axes}[s.axis_id]
304304

305-
total_output_halo = sum(ah)
306-
total_input_halo = total_output_halo * axis.scale / ref_axis.scale
307-
assert (
308-
total_input_halo == int(total_input_halo) and total_input_halo % 2 == 0
305+
input_halo_left = ah.left * axis.scale / ref_axis.scale
306+
input_halo_right = ah.right * axis.scale / ref_axis.scale
307+
assert input_halo_left == int(input_halo_left), f"{input_halo_left} not int"
308+
assert input_halo_right == int(input_halo_right), (
309+
f"{input_halo_right} not int"
309310
)
311+
310312
input_halo.setdefault(s.tensor_id, {})[a] = Halo(
311-
int(total_input_halo // 2), int(total_input_halo // 2)
313+
int(input_halo_left), int(input_halo_right)
312314
)
313315

314316
return input_halo

0 commit comments

Comments
 (0)