From c49506f3e0c54e4df707202c0031f90cff31b4cd Mon Sep 17 00:00:00 2001 From: Asher Norland Date: Tue, 3 Mar 2026 16:00:42 -0800 Subject: [PATCH] Simplify CI Version Script --- .github/workflows/release-build.yml | 21 +++++++-------------- pyproject.toml | 1 + tool/scripts/version.py | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 14 deletions(-) create mode 100644 tool/scripts/version.py diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 9920d64..ce4205b 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -49,25 +49,18 @@ jobs: uses: pdm-project/setup-pdm@v4 with: python-version: "3.14" + cache: true + + - name: Install dependencies + if: github.event_name == 'workflow_run' + run: pdm install - name: Get version id: version run: | if [ "${{ github.event_name }}" == "workflow_run" ]; then - # PDM SCM is the single source of truth for version numbers. - # It reads git tags and produces a PEP 440 version string. - pep440_version=$(pdm show --version) - - # Convert PEP 440 → SemVer for Velopack (e.g. 0.1.0.dev47 → 0.1.0-dev.47) - installer_version=$(python3 -c " - from packaging.version import Version - v = Version('${pep440_version}') - base = f'{v.major}.{v.minor}.{v.micro}' - print(f'{base}-dev.{v.dev}' if v.dev is not None else base) - ") - - echo "version=${pep440_version}" >> $GITHUB_OUTPUT - echo "installer-version=${installer_version}" >> $GITHUB_OUTPUT + # pdm run version outputs version= and installer-version= + pdm run version >> $GITHUB_OUTPUT echo "channel=dev" >> $GITHUB_OUTPUT echo "tag=dev" >> $GITHUB_OUTPUT echo "is-dev=true" >> $GITHUB_OUTPUT diff --git a/pyproject.toml b/pyproject.toml index f7fa189..3d8953a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,6 +87,7 @@ dev = { call = "tool.scripts.dev:main" } format = "ruff format" lint = { composite = ["analyze", "format", "type-check"] } package = { call = "tool.scripts.package:main" } +version = { call = "tool.scripts.version:main" } post_install = { call = "tool.scripts.setup_dev:main" } test = "pytest --cov=synodic_client --verbose tests" type-check = "pyrefly check" diff --git a/tool/scripts/version.py b/tool/scripts/version.py new file mode 100644 index 0000000..44db8a7 --- /dev/null +++ b/tool/scripts/version.py @@ -0,0 +1,23 @@ +"""Print project version in PEP 440 and SemVer formats. + +Outputs ``version=`` and ``installer-version=`` lines, +one per line. In CI these can be appended directly to ``$GITHUB_OUTPUT``. + +Usage examples: + pdm run version + pdm run python -m tool.scripts.version +""" + +from synodic_client import __version__ +from synodic_client.updater import pep440_to_semver + + +def main() -> None: + """Entry point for the version script.""" + semver = pep440_to_semver(__version__) + print(f'version={__version__}') + print(f'installer-version={semver}') + + +if __name__ == '__main__': + main()