From f737256133a3e5870c4740ca445e978183ff12e3 Mon Sep 17 00:00:00 2001 From: Daniel Tamayo Date: Fri, 24 Jan 2025 17:25:41 -0800 Subject: [PATCH] update_pypi action --- .github/workflows/upload_pypi.yml | 41 +++++++++++++++++++++++++++++++ setup.py | 2 +- update_version.py | 32 ++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/upload_pypi.yml diff --git a/.github/workflows/upload_pypi.yml b/.github/workflows/upload_pypi.yml new file mode 100644 index 0000000..ea3b70e --- /dev/null +++ b/.github/workflows/upload_pypi.yml @@ -0,0 +1,41 @@ +name: Upload to PyPI + +on: + workflow_dispatch: + push: + branches: + - main + release: + types: + - published + +jobs: + make_sdist: + name: Make SDist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Optional, use if you use setuptools_scm + + - name: Build SDist + run: pipx run build --sdist + + - uses: actions/upload-artifact@v4 + with: + path: dist/*.tar.gz + + upload_all: + needs: [make_sdist] + environment: pypi + permissions: + id-token: write + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'published' + steps: + - uses: actions/download-artifact@v4 + with: + name: artifact + path: dist + + - uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/setup.py b/setup.py index ef65a49..4289966 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ ghash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("ascii") ghash_arg = "-DCELMECHGITHASH="+ghash.strip() except: - ghash_arg = "-DCELMECHGITHASH=485554c96625e8d3f90d5dd7cfac3e6a29eea763" #GITHASHAUTOUPDATE + ghash_arg = "-DCELMECHGITHASH=b48d1d9fb4e0e7a82402ea61d84f9dff899f048d" #GITHASHAUTOUPDATE extra_link_args=[] if sys.platform == 'darwin': diff --git a/update_version.py b/update_version.py index a894c4b..312d354 100755 --- a/update_version.py +++ b/update_version.py @@ -28,5 +28,33 @@ with open("setup.py", "w") as f: f.writelines(setuplines) -print("To commit, copy and paste:") -print("\ngit commit -a -m \"Updating version to "+celmechversion+"\"") +# find changelog +with open("changelog.md") as f: + found_start = 0 + changelog = "" + cl = f.readlines() + for l in cl: + if found_start == 0 and l.startswith("### Version"): + if celmechversion in l: + found_start = 1 + continue + if found_start == 1 and l.startswith("### Version"): + found_start = 2 + if found_start == 1: + changelog += l + +if found_start != 2 or len(changelog.strip())<5: + raise RuntimeError("Changelog not found") + +with open("_changelog.tmp", "w") as f: + f.writelines(changelog.strip()+"\n") + +print("----") +print("Changelog:\n") +print(changelog.strip()) +print("----") +print("Next:") +print("\ngit commit -a -m \""+celmechversion+"\"") +print("git tag "+celmechversion+" && git push && git push --tags") +print("gh release create "+celmechversion+" --notes-file _changelog.tmp") +print("----")