Skip to content

Commit

Permalink
Github action to test, build and publish Python package
Browse files Browse the repository at this point in the history
  • Loading branch information
ecarrara committed Oct 2, 2024
1 parent f207723 commit 4b3d227
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 7 deletions.
128 changes: 128 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: "build"

on: push

jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install hatch
run: |
python -m pip install hatch
- name: Lint (ruff check)
run: hatch run lint

- name: Type check (pyright)
run: hatch run check

- name: Tests
run: hatch run test

build:
name: Build package
runs-on: ubuntu-latest
needs: [test]
steps:
- name: Build
run: hatch build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [build]
environment:
name: pypi
url: https://pypi.org/p/yapcache
permissions:
id-token: write
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
needs:
- publish-to-pypi
runs-on: ubuntu-latest

permissions:
contents: write
id-token: write

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/[email protected]
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 }}'
--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 }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs: [build]
runs-on: ubuntu-latest

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

permissions:
id-token: write

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
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/
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ keywords = []
authors = [{ name = "Erle Carrara", email = "[email protected]" }]
classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
Expand All @@ -30,21 +31,18 @@ Source = "https://github.com/ecarrara/yapcache"
path = "src/yapcache/__about__.py"

[tool.hatch.envs.default]
dependencies = ["coverage[toml]>=6.5", "pytest", "ruff"]
dependencies = ["coverage[toml]>=6.5", "pytest", "ruff", "pyright"]

[tool.hatch.envs.default.scripts]
test = "pytest {args:tests}"
test-cov = "coverage run -m pytest {args:tests}"
cov-report = ["- coverage combine", "coverage report"]
cov = ["test-cov", "cov-report"]
lint = "ruff check {args:src/yapcache tests}"
check = "pyright {args:src/yapcache tests}"

[[tool.hatch.envs.all.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

[tool.hatch.envs.types]
dependencies = ["mypy>=1.0.0"]
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive {args:src/yapcache tests}"
python = ["3.10", "3.11", "3.12"]

[tool.coverage.run]
source_pkgs = ["yapcache", "tests"]
Expand Down

0 comments on commit 4b3d227

Please sign in to comment.