From a7ea4358410d31edb648b19d90ed418dcc5c77bc Mon Sep 17 00:00:00 2001 From: Jan Kowalleck Date: Sat, 5 Sep 2020 12:14:33 +0200 Subject: [PATCH] tox test - version --- .github/codeql/python-package.yaml | 2 ++ .github/workflows/release.yaml | 46 ++---------------------------- python-package/bin/test_version.py | 40 ++++++++++++++++++++++++++ python-package/tox.ini | 7 +++++ 4 files changed, 51 insertions(+), 44 deletions(-) create mode 100755 python-package/bin/test_version.py diff --git a/.github/codeql/python-package.yaml b/.github/codeql/python-package.yaml index 4e37002e..6f97bb66 100644 --- a/.github/codeql/python-package.yaml +++ b/.github/codeql/python-package.yaml @@ -7,6 +7,8 @@ queries: - uses: security-and-quality paths: + - python-package/bin - python-package/src paths-ignore: + # web-ui is generated - python-package/src/nichtparasoup/_web-ui diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 6748e284..77101445 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -18,45 +18,6 @@ env: latest-python-version: '3.8' jobs: - test-version: - name: Assert version - # assure that the correct version is marked where needed - runs-on: ubuntu-latest - steps: - - name: Fetch Code - # see https://github.com/actions/checkout - uses: actions/checkout@v2 - - name: Setup Python - # see https://github.com/actions/setup-python - uses: actions/setup-python@v2 - with: - python-version: ${{ env.latest-python-version }} - - name: get package version - id: package - run: echo "::set-output name=version::$(python setup.py --version)" - - name: get nichtparasoup version - id: nichtparasoup - run: | - from nichtparasoup import __version__ - print(f'::set-output name=version::{__version__}', sep='', flush=True) - shell: python - env: - PYTHONPATH: src - - name: Assert package_version - if: ${{ steps.package.outputs.version != github.event.release.tag_name }} - run: | - echo ERROR: assertion mismatch - echo package.version : ${{ steps.package.outputs.version }} - echo release.tag_name: ${{ github.event.release.tag_name }} - exit 1 - - name: Assert nichtparasoup_version - if: ${{ steps.nichtparasoup.outputs.version != github.event.release.tag_name }} - run: | - echo ERROR: assertion mismatch - echo nichtparasoup.version: ${{ steps.nichtparasoup.outputs.version }} - echo release.tag_name : ${{ github.event.release.tag_name }} - exit 2 - test: name: Tests # these tests are just to ensure that a minimal quality is given. full tests are done in `tests` action @@ -77,12 +38,11 @@ jobs: - name: Test nichtparasoup run: python -m tox -r -s false env: - TOXENV: style, tests_start, py38 + NP_VERSION_EXPECTED: ${{ github.event.release.tag_name }} + TOXENV: version, style, tests_start, py38 TOX_PARALLEL_NO_SPINNER: 1 - build: name: Build - needs: ['test-version'] # build in an isolated env runs-on: ubuntu-latest steps: @@ -109,7 +69,6 @@ jobs: name: build-results path: ${{ env.project-directory }}/${{ env.dist-dir }}/ if-no-files-found: error - publish-asset-wheel: name: Publish to assets needs: ['test', 'build'] @@ -147,7 +106,6 @@ jobs: asset_path: ${{ env.dist-dir }}/${{ steps.files.outputs.source }} asset_name: ${{ steps.files.outputs.source }} asset_content_type: application/tar+gzip - publish-pypi: name: Publish to PyPI needs: ['test', 'build'] diff --git a/python-package/bin/test_version.py b/python-package/bin/test_version.py new file mode 100755 index 00000000..38bc1228 --- /dev/null +++ b/python-package/bin/test_version.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +import os +import sys +from subprocess import check_output + +# region config + +PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +SOURCES_DIR = os.path.join(PROJECT_ROOT, 'src') +SETUP_FILE = os.path.join(PROJECT_ROOT, 'setup.py') + +# region config + +VERSION_EXPECTED = sys.argv[1] if len(sys.argv) > 1 else os.getenv('NP_VERSION_EXPECTED') +if not VERSION_EXPECTED: + print(f'VERSION_EXPECTED empty: {VERSION_EXPECTED!r}') + sys.exit(1) +print(f'expected version {VERSION_EXPECTED!r}') + +# region version_src + +sys.path.insert(0, SOURCES_DIR) +from nichtparasoup import __version__ as version_src # noqa isort:skip + +if version_src != VERSION_EXPECTED: + print(f'ERROR version_src: expected {VERSION_EXPECTED!r}, got {version_src!r}', file=sys.stderr) + sys.exit(2) + +# endregion version_src + +# region version_setup + +version_setup = check_output([sys.executable, SETUP_FILE, '--version'], shell=False, universal_newlines=True).strip() +if version_setup != VERSION_EXPECTED: + print(f'ERROR version_setup: expected {VERSION_EXPECTED!r}, got {version_setup!r}', file=sys.stderr) + sys.exit(3) + +# endregion version_setup + +sys.exit(0) diff --git a/python-package/tox.ini b/python-package/tox.ini index a07a1d77..918d139d 100644 --- a/python-package/tox.ini +++ b/python-package/tox.ini @@ -70,3 +70,10 @@ deps = -r requirements/style.txt commands = {envpython} -m flake8 {envpython} -m mypy + +[testenv:version] +depends = +skip_install = True +deps = +commands = + {envpython} bin/test_version.py {env:NP_VERSION_EXPECTED}