Skip to content

Commit a448500

Browse files
authored
Merge pull request #4 from NIRaspberryJam/build_pip_package
add pip package action
2 parents 1a950fc + 034b23d commit a448500

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

‎.github/workflows/publish.yml‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
build:
13+
name: Build and validate distributions
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Check out repository
18+
uses: actions/checkout@v6
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v6
22+
with:
23+
python-version: "3.13"
24+
cache: pip
25+
26+
- name: Install build tools
27+
run: python -m pip install --upgrade pip build twine
28+
29+
- name: Check release tag matches package version
30+
env:
31+
RELEASE_TAG: ${{ github.event.release.tag_name }}
32+
run: |
33+
python - <<'PY'
34+
import os
35+
import pathlib
36+
import tomllib
37+
38+
project = tomllib.loads(
39+
pathlib.Path("pyproject.toml").read_text(encoding="utf-8")
40+
)
41+
package_version = project["project"]["version"]
42+
release_version = os.environ["RELEASE_TAG"].removeprefix("v")
43+
44+
if package_version != release_version:
45+
raise SystemExit(
46+
f"Release tag {release_version!r} does not match "
47+
f"package version {package_version!r}"
48+
)
49+
PY
50+
51+
- name: Build distributions
52+
run: python -m build
53+
54+
- name: Validate distributions
55+
run: python -m twine check dist/*
56+
57+
- name: Smoke-test wheel
58+
run: |
59+
python -m venv /tmp/jamkit-smoke
60+
/tmp/jamkit-smoke/bin/python -m pip install dist/*.whl
61+
/tmp/jamkit-smoke/bin/python -c \
62+
"from jamkit.hack_the_robot.loader import load_workshop"
63+
64+
- name: Upload distributions
65+
uses: actions/upload-artifact@v4
66+
with:
67+
name: python-distributions
68+
path: dist/
69+
if-no-files-found: error
70+
71+
publish:
72+
name: Publish to PyPI
73+
needs: build
74+
runs-on: ubuntu-latest
75+
environment:
76+
name: pypi
77+
url: https://pypi.org/project/jamkit/
78+
permissions:
79+
id-token: write
80+
81+
steps:
82+
- name: Download distributions
83+
uses: actions/download-artifact@v4
84+
with:
85+
name: python-distributions
86+
path: dist/
87+
88+
- name: Publish distributions
89+
uses: pypa/gh-action-pypi-publish@release/v1

‎pyproject.toml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@ requires-python = ">=3.11"
77
dependencies = []
88

99
[build-system]
10-
requires = ["setuptools>=68", "wheel"]
10+
requires = ["setuptools>=77"]
1111
build-backend = "setuptools.build_meta"
1212

1313
[tool.setuptools]
1414
package-dir = {"" = "src"}
15+
include-package-data = true
16+
17+
[tool.setuptools.packages.find]
18+
where = ["src"]
19+
20+
[tool.setuptools.package-data]
21+
jamkit = [
22+
"jam_collector/assets/*.gif",
23+
"hack_the_robot/*.json",
24+
"hack_the_robot/data/*.txt",
25+
]

0 commit comments

Comments
 (0)