Skip to content

Commit 7e24e1b

Browse files
committed
feat: add publish-to-test-pypi.yml
Signed-off-by: Milad Makdesi <milad@id8-engineering.io>
1 parent 1a8fcb4 commit 7e24e1b

2 files changed

Lines changed: 85 additions & 2 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: publish-to-test-pypi
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
7+
jobs:
8+
build:
9+
name: Build distribution
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c
18+
with:
19+
python-version: "3.x"
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@85856786d1ce8acfbcc2f13a5f3fbd6b938f9f41 # v7.1.2
23+
24+
- name: Build distributions with uv
25+
run: uv build
26+
27+
- name: Rename distributions with build number
28+
run: |
29+
BUILD_NUMBER=${GITHUB_RUN_NUMBER}
30+
31+
for file in dist/*.whl; do
32+
base=$(basename "$file")
33+
34+
new=$(echo "$base" | sed "s/\(-py[0-9]\)/-${BUILD_NUMBER}\1/")
35+
36+
mv "dist/$base" "dist/$new"
37+
echo "Renamed $base → $new"
38+
done
39+
40+
- name: Validate metadata
41+
run: |
42+
uv run twine check dist/*
43+
44+
- name: Test import
45+
run: python -c "import em511"
46+
47+
- name: Run tests
48+
run: |
49+
uv pip install pytest
50+
pytest
51+
52+
- name: Upload distributions as artifact
53+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
54+
with:
55+
name: dist-files
56+
path: dist/
57+
58+
publish-to-test-pypi:
59+
name: Publish Python distribution to TestPyPI
60+
needs: [build]
61+
runs-on: ubuntu-latest
62+
63+
environment:
64+
name: testpypi
65+
url: https://test.pypi.org/p/python-em511
66+
67+
permissions:
68+
id-token: write
69+
70+
steps:
71+
- name: Download all build artifacts
72+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
73+
with:
74+
name: dist-files
75+
path: dist/
76+
77+
- name: Publish distribution to TestPyPI
78+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e
79+
with:
80+
repository-url: https://test.pypi.org/legacy/

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "python-em511"
3-
version = "0.0.1"
3+
dynamic = ["version"]
44
description = "Driver for Carlo Gavazzi EM511 Series Single Phase Energy Meters using Modbus RTU"
55
readme = "README.md"
66

@@ -36,12 +36,15 @@ classifiers = [
3636
]
3737

3838
[build-system]
39-
requires = ["hatchling"]
39+
requires = ["hatchling", "hatch-vcs"]
4040
build-backend = "hatchling.build"
4141

4242
[tool.hatch.build.targets.wheel]
4343
packages = ["src/em511"]
4444

45+
[tool.hatch.version]
46+
source = "vcs"
47+
4548
[dependency-groups]
4649
dev = [
4750
"pre-commit>=4.3.0",

0 commit comments

Comments
 (0)