Skip to content

Commit

Permalink
Harness the github action to make a release
Browse files Browse the repository at this point in the history
  • Loading branch information
musale committed Aug 30, 2023
1 parent e2a0f1a commit a7dda43
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 14 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish

on:
push:
branches:
- master

jobs:
publish:
name: "Publish release"
runs-on: "ubuntu-latest"

environment:
name: deploy

steps:
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: 3.8
- name: "Install dependencies"
run: "scripts/install"
- name: "Build package"
run: "scripts/build"
- name: "Publish to PyPI"
run: "scripts/publish"
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
3 changes: 3 additions & 0 deletions pesapal_v3/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__title__ = "pesapal_v3"
__description__ = "A python wrapper of the Pesapal V3 payments API."
__version__ = "0.1.0"
2 changes: 1 addition & 1 deletion pesapal_v3/_pesapal.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _authenticate(self, *, consumer_key: str, consumer_secret: str) -> AccessTok
token: AccessToken = AccessToken(**response)
return token

def update_headers(self, *, headers: Dict[str, str]):
def update_headers(self, *, headers: Dict[str, str]) -> None:
"""Updates the header values."""
self._headers.update(headers)

Expand Down
51 changes: 38 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "pesapal_v3"
version = "0.1.0"
description = "Add your description here"
authors = [
{ name = "Musale Martin", email = "martinmshale@gmail.com" }
]
dependencies = []
description = "A python wrapper of the Pesapal V3 payments API."
authors = [{ name = "Musale Martin", email = "martinmshale@gmail.com" }]
readme = "README.md"
requires-python = ">= 3.8"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true
dev-dependencies = []
classifiers = [
"Development Status :: Development",
"Environment :: Web Environment",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Internet :: WWW/HTTP",
]
dependencies = ["httpx>=0.24.1"]

[tool.hatch.metadata]
allow-direct-references = true

[tool.ruff]
select = ["E", "F", "I", "B", "PIE"]
ignore = ["B904", "B028"]
line-length = 120

[tool.ruff.isort]
combine-as-imports = true

[tool.mypy]
ignore_missing_imports = true
strict = true

[[tool.mypy.overrides]]
module = "tests.*"
disallow_untyped_defs = false
check_untyped_defs = true
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
httpx==0.24.1
13 changes: 13 additions & 0 deletions scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh -e

if [ -d 'venv' ] ; then
PREFIX="venv/bin/"
else
PREFIX=""
fi

set -x

${PREFIX}python -m build
${PREFIX}twine check dist/*
# ${PREFIX}mkdocs build
19 changes: 19 additions & 0 deletions scripts/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh -e

# Use the Python executable provided from the `-p` option, or a default.
[ "$1" = "-p" ] && PYTHON=$2 || PYTHON="python3"

REQUIREMENTS="requirements.txt"
VENV="venv"

set -x

if [ -z "$GITHUB_ACTIONS" ]; then
"$PYTHON" -m venv "$VENV"
PIP="$VENV/bin/pip"
else
PIP="pip"
fi

"$PIP" install -U pip
"$PIP" install -r "$REQUIREMENTS"
26 changes: 26 additions & 0 deletions scripts/publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh -e

VERSION_FILE="pesapal/__version__.py"

if [ -d 'venv' ] ; then
PREFIX="venv/bin/"
else
PREFIX=""
fi

if [ ! -z "$GITHUB_ACTIONS" ]; then
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "GitHub Action"

VERSION=`grep __version__ ${VERSION_FILE} | grep -o '[0-9][^"]*'`

if [ "refs/tags/${VERSION}" != "${GITHUB_REF}" ] ; then
echo "GitHub Ref '${GITHUB_REF}' did not match package version '${VERSION}'"
exit 1
fi
fi

set -x

${PREFIX}twine upload dist/*
# ${PREFIX}mkdocs gh-deploy --force

0 comments on commit a7dda43

Please sign in to comment.