From 7710ad2f952de56dcecc440f48bdec94eda43f84 Mon Sep 17 00:00:00 2001 From: Flavio Amurrio <25621374+FlavioAmurrioCS@users.noreply.github.com> Date: Thu, 20 Jun 2024 21:04:29 -0400 Subject: [PATCH] Publish with github action anc git versioning --- .github/workflows/pythonpackage.yml | 81 +++++++++++++++++++++++++++++ pyproject.toml | 7 ++- 2 files changed, 86 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 90c6003..fec3418 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -6,6 +6,7 @@ name: Python package on: push: branches: [master, dev] + tags: '*' pull_request: branches: [master] @@ -39,5 +40,85 @@ jobs: run: poetry run mypy functional if: always() - uses: codecov/codecov-action@v1 + # only upload coverage for one python version + if: matrix.python-version == '3.11' with: file: ./coverage.xml + - name: Install poetry-dynamic-versioning + run: python -m pip install "poetry-dynamic-versioning[plugin]" + if: matrix.python-version == '3.11' + - name: Build a binary wheel and a source tarball + if: matrix.python-version == '3.11' + run: poetry build + - name: Store the distribution packages + if: matrix.python-version == '3.11' + uses: actions/upload-artifact@v4 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + if: ${{ startsWith(github.ref, 'refs/tags/') }} # only publish to PyPI on tag pushes + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/pyfunctional + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + github-release: + name: >- + Sign the Python 🐍 distribution 📦 with Sigstore + and upload them to GitHub Release + if: ${{ startsWith(github.ref, 'refs/tags/') }} # only publish to GitHub Releases on tag pushes + needs: + - build + runs-on: ubuntu-latest + + permissions: + contents: write # IMPORTANT: mandatory for making GitHub Releases + id-token: write # IMPORTANT: 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: Create GitHub Release + env: + GITHUB_TOKEN: ${{ github.token }} + run: >- + gh release create + '${{ github.ref_name }}' + --repo '${{ github.repository }}' + --generate-notes + - 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/pyproject.toml b/pyproject.toml index 3ac4ce2..193deb3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,9 +47,12 @@ mypy = "^1.1.1" types-tabulate = "^0.9.0.3" pandas-stubs = "^2.0.3.230814" +[tool.poetry-dynamic-versioning] +enable = true + [build-system] -requires = ["poetry>=0.12"] -build-backend = "poetry.masonry.api" +requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"] +build-backend = "poetry_dynamic_versioning.backend" [tool.coverage.report] exclude_lines = [