From e44d13e1cfa44440932f93c88280c310931004de Mon Sep 17 00:00:00 2001 From: Cullen Watson Date: Wed, 4 Dec 2024 16:29:38 -0600 Subject: [PATCH] enh:auto update version --- .github/workflows/publish-to-pypi.yml | 38 ++++++++++++++++++--------- increment_version.py | 21 +++++++++++++++ poetry.toml | 2 -- 3 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 increment_version.py delete mode 100644 poetry.toml diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/publish-to-pypi.yml index 13b0b3b..115828c 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/publish-to-pypi.yml @@ -1,33 +1,47 @@ name: Publish Python 🐍 distributions 📦 to PyPI -on: push +on: + pull_request: + types: + - closed jobs: build-n-publish: name: Build and publish Python 🐍 distributions 📦 to PyPI runs-on: ubuntu-latest + if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' + steps: - uses: actions/checkout@v3 + - name: Set up Python uses: actions/setup-python@v4 with: python-version: "3.10" + - name: Install dependencies + run: pip install toml + + - name: Increment version + run: python increment_version.py + + - name: Commit version increment + run: | + git config --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + git add pyproject.toml + git commit -m 'Increment version' + + - name: Push changes + run: git push + - name: Install poetry - run: >- - python3 -m - pip install - poetry - --user + run: pip install poetry --user - name: Build distribution 📦 - run: >- - python3 -m - poetry - build + run: poetry build - name: Publish distribution 📦 to PyPI - if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 with: - password: ${{ secrets.PYPI_API_TOKEN }} \ No newline at end of file + password: ${{ secrets.PYPI_API_TOKEN }} diff --git a/increment_version.py b/increment_version.py new file mode 100644 index 0000000..f359bd7 --- /dev/null +++ b/increment_version.py @@ -0,0 +1,21 @@ +import toml + +def increment_version(version): + major, minor, patch = map(int, version.split('.')) + patch += 1 + return f"{major}.{minor}.{patch}" + +# Load pyproject.toml +with open('pyproject.toml', 'r') as file: + pyproject = toml.load(file) + +# Increment the version +current_version = pyproject['tool']['poetry']['version'] +new_version = increment_version(current_version) +pyproject['tool']['poetry']['version'] = new_version + +# Save the updated pyproject.toml +with open('pyproject.toml', 'w') as file: + toml.dump(pyproject, file) + +print(f"Version updated from {current_version} to {new_version}") diff --git a/poetry.toml b/poetry.toml deleted file mode 100644 index ab1033b..0000000 --- a/poetry.toml +++ /dev/null @@ -1,2 +0,0 @@ -[virtualenvs] -in-project = true