Skip to content

Commit

Permalink
Test version check
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar committed Apr 8, 2024
1 parent ddb679b commit bdceb2e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .github/scripts/check_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Print current version of janus_core."""

from janus_core import __version__

print(__version__)
59 changes: 40 additions & 19 deletions .github/workflows/publish-on-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit bdceb2e

Please sign in to comment.