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 4cd4684
Show file tree
Hide file tree
Showing 2 changed files with 40 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__)
54 changes: 35 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,37 @@ 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: Check versions match version
run: |
export PYTHONPATH=$(pwd)
echo "VERSION=$(python .github/scripts/check_version.py)" >> $GITHUB_ENV
echo "POETRYVERSION=$(poetry version --short)" >> $GITHUB_ENV
- name: Test pass
if: contains(github.ref, env.VERSION) && env.VERSION == env.POETRYVERSION
run: echo "match!"

- name: Test fail
if: ${{ ! ( contains(github.ref, env.VERSION) && env.VERSION == env.POETRYVERSION ) }}
run: |
echo ${{ github.ref}} ${{ env.VERSION }} ${{ env.POETRYVERSION }}
exit 1
# - 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 4cd4684

Please sign in to comment.