Skip to content

Commit

Permalink
Publish to PyPi workflow (#13)
Browse files Browse the repository at this point in the history
* Publish to PyPi workflow

Made the version dynamic using setuptools_scm and publish to PyPi using
a github action and "trusted publishers"

* Fix lint and format

* Remove _version.py from tracking

* exclude _version.py from pyright and flake8

* removed testpypi from workflow

* Changed script to run on release creation

* Add dependency caching
  • Loading branch information
fzakaria authored Sep 23, 2023
1 parent fde5e41 commit 4a9ed28
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: pip # caching pip dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
Expand Down
87 changes: 87 additions & 0 deletions .github/workflows/publish-to-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Publish Python 🐍 distribution 📦 to PyPI

on:
release:
types: [created]

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 }}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ temp/
nosetests.xml
coverage.xml
htmlcov
sqlelf/_version.py
13 changes: 9 additions & 4 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 All @@ -55,12 +60,12 @@ profile = "black"
addopts = ""

[tool.pyright]
include = ["sqlelf", "tests"]
exclude = ["**/__pycache__"]
exclude = ["**/__pycache__", "sqlelf/_version.py"]

reportMissingImports = true
reportMissingTypeStubs = true
useLibraryCodeForTypes = true

pythonVersion = "3.10"
pythonPlatform = "Linux"
include = ["sqlelf", "tests"]
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[flake8]
extend-ignore = E203
max-line-length = 88
max-line-length = 88
exclude =
_version.py
8 changes: 8 additions & 0 deletions sqlelf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
from importlib.metadata import PackageNotFoundError, version

import apsw.bestpractice

# 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

0 comments on commit 4a9ed28

Please sign in to comment.