diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c9fe77a..f5d57f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,15 +22,15 @@ jobs: name: OS ${{matrix.runner}} Python ${{matrix.python-version}} steps: - - name: Checkout - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} + cache: pip - - name: Install dependencies + - name: Install package run: pip install -e . - name: Check Python version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..7bcd957 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,54 @@ +name: Release new version + +on: + workflow_dispatch: + inputs: + version_name: + description: 'Version name' + required: true + pypi_repo: + description: 'PyPI repository' + required: true + type: choice + default: 'pypi' + options: + - 'pypi' + - 'testpypi' + release: + types: [published] + +jobs: + release: + permissions: + id-token: write + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + cache: pip + + - name: Build + env: + SETUPTOOLS_SCM_PRETEND_VERSION: ${{ inputs.version_name }} + run: | + python -m pip install --upgrade pip + pip install build + python -m build + + - name: Store build artifact + uses: actions/upload-artifact@v4 + with: + path: dist + + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: https://test.pypi.org/legacy/ + if: ${{ inputs.pypi_repo == 'testpypi' }} + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + if: ${{ inputs.pypi_repo == 'pypi' || github.event_name == 'release' }} diff --git a/pyproject.toml b/pyproject.toml index e69de29..a675a2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.setuptools_scm] +local_scheme = "no-local-version" diff --git a/setup.cfg b/setup.cfg index a5be960..301b143 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,12 +1,15 @@ [metadata] name = sssimp -version = attr: sssimp.__version__ author = Tina author_email = me@tina.moe description = A simple static website generator long_description = file: README.md long_description_content_type = text/markdown url = https://github.com/Tina-otoge/sssimp +dynamic = ["version"] + +[build-system] +requires = ["setuptools", "setuptools_scm[toml]"] [options] packages = find: diff --git a/src/sssimp/__init__.py b/src/sssimp/__init__.py index eeb8e88..56ec067 100644 --- a/src/sssimp/__init__.py +++ b/src/sssimp/__init__.py @@ -1,11 +1,14 @@ import functools +import importlib.metadata from pathlib import Path from jinja2 import Environment, FileSystemLoader from . import config -__version__ = "0.0.17" +__pkg__ = __name__.split(".")[-1] +__version__ = importlib.metadata.version(__pkg__) +print(f"sssimp version {__version__}") APP_DIR = Path(__file__).parent INPUT_DIR = Path(config.INPUT_PATH)