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 :
@@ -239,26 +249,51 @@ jobs:
239249 uses : actions/checkout@v4
240250 with :
241251 fetch-depth : 2
242- - name : Check if there is a parent commit
243- id : check-parent-commit
252+ fetch-tags : true
253+ - name : Get parent commit
254+ if : inputs.force-publish != 'true'
255+ id : get-parent-commit
244256 run : |
245257 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
246261
247- - name : Detect new version
262+ - name : Detect new version from last commit and create tag
248263 id : tag-version
249- 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'
250265251266 with :
252267 create-tag : true
253268 version-command : |
254- 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+
255290 - uses : actions/download-artifact@v4
256- 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
257292 with :
258293 name : dist
259294 path : dist
260295 - name : Publish package on PyPI
261- 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
262297 uses : pypa/gh-action-pypi-publish@release/v1
263298 with :
264299 packages-dir : dist/
@@ -267,7 +302,7 @@ jobs:
267302 if : github.ref == 'refs/heads/main'
268303 uses :
release-drafter/[email protected] 269304 with :
270- publish : " ${{ steps.tag- version.outputs.tag != '' }}"
271- tag : ' ${{ steps.tag- version.outputs.tag }}'
305+ publish : " ${{ steps.get-new- version.outputs.new-version != '' }}"
306+ tag : ' ${{ steps.get-new- version.outputs.new-version }}'
272307 env :
273308 GITHUB_TOKEN : ' ${{ secrets.GITHUB_TOKEN }}'
0 commit comments