From 83e75877c4339fb227334d270a570d503c3fe7ba Mon Sep 17 00:00:00 2001 From: Revathyvenugopal162 Date: Tue, 20 Aug 2024 19:41:31 +0200 Subject: [PATCH] feat: update the release workflow --- .github/workflows/publish-pypi.yml | 106 +++++++++++++++++++++++++++++ noxfile.py | 6 +- pyproject.toml | 20 +++--- 3 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/publish-pypi.yml diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml new file mode 100644 index 0000000..88ca221 --- /dev/null +++ b/.github/workflows/publish-pypi.yml @@ -0,0 +1,106 @@ +name: Publish to PyPI +on: + release: + types: [published] + push: + branches: + - main +jobs: + # setup build separate from publish + # See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093 + build: + runs-on: ubuntu-latest + # This ensures that the publish action only runs in the main repository + # rather than forks + # Environment is encouraged so adding + environment: build + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + # This fetch element is only important if you are use SCM based + # versioning (that looks at git tags to gather the version) + fetch-depth: 100 + + # Need the tags so that setuptools-scm can form a valid version number + - name: Fetch git tags + run: git fetch origin 'refs/tags/*:refs/tags/*' + + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install Hatch + run: | + pipx install hatch + pip list + + - name: Build package using Hatch + run: | + hatch build + echo "" + echo "Generated files:" + ls -lh dist/ + # Store an artifact of the build to use in the publish step below + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + publish: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + if: github.repository_owner == 'pyopensci' + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/pyosmeta + permissions: + id-token: write # this permission is mandatory for pypi publishing + steps: + # Version 4 doesn't support github enterprise yet + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish package to PyPI + # Only publish to real PyPI on release + if: github.event_name == 'release' + uses: pypa/gh-action-pypi-publish@release/v1 + sign-files: + name: >- + Sign the Python 🐍 distribution 📦 with Sigstore + and upload them to GitHub Release + # Only sign on release + if: github.repository_owner == 'pyopensci' && github.event_name == 'release' + needs: + - publish + runs-on: ubuntu-latest + permissions: + contents: write # this permission is mandatory for modifying GitHub Releases + id-token: write # this permission is mandatory for sigstore + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Sign the dists with Sigstore + uses: sigstore/gh-action-sigstore-python@v2.1.1 + with: + inputs: >- + ./dist/*.tar.gz + ./dist/*.whl + - name: Upload artifact signatures to GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + # Upload to GitHub Release using the `gh` CLI. + # `dist/` contains the built packages, and the + # sigstore-produced signatures and certificates. + run: >- + gh release upload + '${{ github.ref_name }}' dist/** + --repo '${{ github.repository }}' diff --git a/noxfile.py b/noxfile.py index 558d370..47bb34b 100644 --- a/noxfile.py +++ b/noxfile.py @@ -104,7 +104,5 @@ def linkcheck(session): @nox.session(name="build-project") def build_project(session): - """Build the project and create a wheel distribution for pyproject.toml file.""" - session.install("build", "twine") - session.run("python", "-m", "build") - session.run("twine", "check", "dist/*") + """Build the project and create the distribution files using hatch.""" + session.run("hatch", "build", *session.posargs) diff --git a/pyproject.toml b/pyproject.toml index af255e0..484bc49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,6 @@ [build-system] -requires = [ - "sphinx-theme-builder @ https://github.com/pradyunsg/sphinx-theme-builder/archive/87214d0671c943992c05e3db01dca997e156e8d6.zip", -] -build-backend = "sphinx_theme_builder" +requires = ["hatchling", "hatch-vcs"] +build-backend = "hatchling.build" [tool.sphinx-theme-builder] node-version = "16.13.2" @@ -13,6 +11,10 @@ name = "pyos-sphinx-theme" description = "PyOS Documentation Theme." dynamic = ["version"] readme = "README.md" +authors = [{ name = "Leah Wasser", email = "leah@pyopensci.org" }] +maintainers = [ + { name = "pyOpenSci", email = "admin@pyopensci.org" }, # Optional +] requires-python = ">=3.9" dependencies = [ @@ -34,14 +36,9 @@ classifiers = [ "License :: OSI Approved :: MIT License", "Environment :: Web Environment", "Intended Audience :: Developers", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3 :: Only", # BE sure to specify that you use python 3.x "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Operating System :: OS Independent", - "Topic :: Documentation", - "Topic :: Software Development :: Documentation", ] [project.optional-dependencies] @@ -54,6 +51,9 @@ docs = [ "IPython", ] +[tool.hatch] +version.source = "vcs" + [project.entry-points."sphinx.html_themes"] "pyos_sphinx_theme" = "pyos_sphinx_theme"