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
919defaults :
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'
245265246266 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 }}'
0 commit comments