From fea466be608d8ea239b7cb0f3ac1626c08770ebc Mon Sep 17 00:00:00 2001 From: Richard Darst Date: Fri, 20 Oct 2023 01:19:27 +0300 Subject: [PATCH] Add workflow for release + version in code --- .github/workflows/release.yml | 89 +++++++++++++++++++++++++ setup.py | 6 +- sphinx_ext_substitution/__init__.py | 1 + sphinx_ext_substitution/_version.py | 1 + sphinx_ext_substitution/substitution.py | 4 +- 5 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 sphinx_ext_substitution/_version.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..535a4e7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +name: PyPI release + +# Make a PyPI release. This action: +# - builds the release files +# - checks the tag version matches the source version +# - releases on PyPI using the action +# +# The first time, you have to upload the release yourself to get the +# API key, to add to gh-secrets. +# +# I upload it with: +# python setup.py sdist bdist_wheel +# twine upload dist/* +# +# To configure the secrets, see steps here: +# https://github.com/pypa/gh-action-pypi-publish +# secret name= pypi_password + + +# If MOD_NAME not defined, infer it from the current directory. If +# inferred from the directory, '-' is replaced with '_'. This is used +# when checking the version name. +#env: +# MOD_NAME: numpy + +on: + # For Github release-based publishing + #release: + # types: [published] + # For tag-based (instead of Github-specific release-based): + push: + tags: + - '*' + +jobs: + build: + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + permissions: + contents: read + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v4 + #with: + # python-version: 3.8 + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install -r requirements-dev.txt + pip install twine wheel + + - name: Build + run: | + python setup.py sdist bdist_wheel + + # Verify that the git tag has the same version as the python + # project version. + - uses: rkdarst/action-verify-python-version@main + + - uses: actions/upload-artifact@master + with: + name: dist-directory + path: dist/ + + + upload: + runs-on: ubuntu-latest + needs: build + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + permissions: + id-token: write # for trusted publishing + steps: + + - uses: actions/download-artifact@v3 + with: + name: dist-directory + path: dist/ + + - name: Publish on PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + #with: + #user: __token__ + #password: ${{ secrets.pypi_password }} + #repository_url: https://test.pypi.org/legacy/ diff --git a/setup.py b/setup.py index 608e9e5..1d44ab2 100644 --- a/setup.py +++ b/setup.py @@ -10,8 +10,12 @@ requirementstxt = join(dirname(__file__), "requirements.txt") requirements = [ line.strip() for line in open(requirementstxt, "r") if line.strip() ] +version_ns = { } +exec(open('sphinx_ext_substitution/_version.py').read(), version_ns) +version = version_ns['__version__'] + setuptools.setup(name='sphinx_ext_substitution', - version='0.1.2', + version=version, description='Sphinx extension for substituting variables', long_description=long_description, long_description_content_type="text/x-rst", # ReST is the default diff --git a/sphinx_ext_substitution/__init__.py b/sphinx_ext_substitution/__init__.py index ff2014b..f576c62 100644 --- a/sphinx_ext_substitution/__init__.py +++ b/sphinx_ext_substitution/__init__.py @@ -1,4 +1,5 @@ from __future__ import print_function +from ._version import __version__ from .substitution import * from .util import * diff --git a/sphinx_ext_substitution/_version.py b/sphinx_ext_substitution/_version.py new file mode 100644 index 0000000..8ce9b36 --- /dev/null +++ b/sphinx_ext_substitution/_version.py @@ -0,0 +1 @@ +__version__ = '0.1.3' diff --git a/sphinx_ext_substitution/substitution.py b/sphinx_ext_substitution/substitution.py index 3a2353b..82010b8 100644 --- a/sphinx_ext_substitution/substitution.py +++ b/sphinx_ext_substitution/substitution.py @@ -13,6 +13,8 @@ from jsonpath_ng import jsonpath, parse from .get_replacements import get_substitutions +from . import __version__ + class sub(nodes.Admonition, nodes.Element): pass @@ -327,7 +329,7 @@ def setup(app): app.add_css_file("sphinx_ext_substitution.css") return { - 'version': '0.1', + 'version': __version__, 'parallel_read_safe': True, 'parallel_write_safe': True, }