diff --git a/.github/scripts/check_version.py b/.github/scripts/check_version.py new file mode 100644 index 00000000..c898bf3a --- /dev/null +++ b/.github/scripts/check_version.py @@ -0,0 +1,5 @@ +"""Print current version of janus_core.""" + +from janus_core import __version__ + +print(__version__) diff --git a/.github/workflows/publish-on-pypi.yml b/.github/workflows/publish-on-pypi.yml index d312c222..bb2138a4 100644 --- a/.github/workflows/publish-on-pypi.yml +++ b/.github/workflows/publish-on-pypi.yml @@ -2,14 +2,14 @@ name: Publish on PyPI on: push: - tags: - # After vMajor.Minor.Patch _anything_ is allowed (without "/") ! - - v[0-9]+.[0-9]+.[0-9]+* +# tags: +# # After vMajor.Minor.Patch _anything_ is allowed (without "/") ! +# - v[0-9]+.[0-9]+.[0-9]+* jobs: publish: runs-on: ubuntu-latest - if: github.repository == 'stfc/janus-core' && startsWith(github.ref, 'refs/tags/v') + #if: github.repository == 'stfc/janus-core' && startsWith(github.ref, 'refs/tags/v') steps: - name: Checkout repository @@ -28,21 +28,42 @@ jobs: poetry env use 3.11 poetry build - - name: Check Version - id: check-version + - name: Check prerelease + id: check-prerelease run: | [[ "$(poetry version --short)" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || echo prerelease=true >> $GITHUB_OUTPUT - - name: Create Release - uses: ncipollo/release-action@v1 - with: - artifacts: "dist/*" - token: ${{ secrets.GITHUB_TOKEN }} - draft: false - prerelease: steps.check-version.outputs.prerelease == 'true' - skipIfReleaseExists: true - - - name: Publish to PyPI - env: - POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} - run: poetry publish + - name: Get versions from __init__ and pyproject.toml + run: | + export PYTHONPATH=$(pwd) + echo "VERSION=$(python .github/scripts/check_version.py)" >> $GITHUB_ENV + echo "POETRYVERSION=$(poetry version --short)" >> $GITHUB_ENV + + - name: Check __init__ matches pyproject.toml + if: ${{ env.VERSION != env.POETRYVERSION }} + run: | + echo "Version in __init__.py and pyproject.toml do not match" + exit 1 + + - name: Check versions match tag + if: ${{ ! contains(github.ref, env.VERSION) }} + run: | + echo "Tag does not match version in __init__.py do not match" + exit 1 + + - name: Continue + run: echo "Success!" + +# - name: Create Release +# uses: ncipollo/release-action@v1 +# with: +# artifacts: "dist/*" +# token: ${{ secrets.GITHUB_TOKEN }} +# draft: false +# prerelease: steps.check-prerelease.outputs.prerelease == 'true' +# skipIfReleaseExists: true +# +# - name: Publish to PyPI +# env: +# POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }} +# run: poetry publish