Skip to content

Commit

Permalink
Publish to PyPi workflow
Browse files Browse the repository at this point in the history
Made the version dynamic using setuptools_scm and publish to PyPi using
a github action and "trusted publishers"
  • Loading branch information
fzakaria committed Sep 22, 2023
1 parent fde5e41 commit eabc3fb
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 2 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on: push

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
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/sqlelf
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
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
needs:
- publish-to-pypi
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@v3
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
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 }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: testpypi
url: https://test.pypi.org/p/sqlelf

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
requires = ["setuptools", "setuptools-scm[toml]", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "sqlelf"
version = "0.0.1"
# Using the dynamic version
# version = "0.0.1"
dynamic = ["version"]
authors = [{ name = "Farid Zakaria", email = "[email protected]" }]
readme = "README.md"
description = "Explore ELF objects through the power of SQL"
Expand Down Expand Up @@ -41,6 +43,9 @@ dev = [
"mypy >= 1.0.0",
]

[tool.setuptools_scm]
write_to = "sqlelf/_version.py"

[tool.setuptools]
packages = ["sqlelf"]

Expand Down
7 changes: 7 additions & 0 deletions sqlelf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import apsw.bestpractice
from importlib.metadata import version, PackageNotFoundError

# forward sqlite logs to logging module
apsw.bestpractice.apply(apsw.bestpractice.recommended)

try:
__version__ = version("sqlelf")
except PackageNotFoundError:
# If the package is not installed, don't add __version__
pass
8 changes: 8 additions & 0 deletions sqlelf/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# file generated by setuptools_scm
# don't change, don't track in version control
TYPE_CHECKING = False
if TYPE_CHECKING:
from typing import Tuple

__version__ = version = '0.1.dev53+gfde5e41.d20230922' # type: str
__version_tuple__ = version_tuple = (0, 1, 'dev53', 'gfde5e41.d20230922') # type: Tuple[int | str, ...]

0 comments on commit eabc3fb

Please sign in to comment.