Skip to content

Commit df5a2d0

Browse files
committed
Add: vcs versioning
1 parent f67a245 commit df5a2d0

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed

.github/workflows/publish-pypi.yml

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Publish to PyPI
2+
on:
3+
release:
4+
types: [published]
5+
push:
6+
branches:
7+
- main
8+
jobs:
9+
# setup build separate from publish
10+
# See https://github.com/pypa/gh-action-pypi-publish/issues/217#issuecomment-1965727093
11+
build:
12+
runs-on: ubuntu-latest
13+
# This ensures that the publish action only runs in the main repository
14+
# rather than on any forks of your repo. You only should publish from the
15+
# main repository
16+
# Environment is encouraged but not required. The build step of this action
17+
# Only builds your package's sdist and wheel
18+
environment: build
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
# This fetch element is only important if you are use SCM based
24+
# versioning (that looks at git tags to gather the version)
25+
fetch-depth: 100
26+
27+
# Need the tags so that setuptools-scm can form a valid version number
28+
- name: Fetch git tags
29+
run: git fetch origin 'refs/tags/*:refs/tags/*'
30+
31+
- name: Setup Python
32+
uses: actions/setup-python@v5
33+
with:
34+
python-version: "3.10"
35+
- name: Install Hatch
36+
run: |
37+
pipx install hatch
38+
pip list
39+
40+
- name: Build package using Hatch
41+
run: |
42+
hatch build
43+
echo ""
44+
echo "Generated files:"
45+
ls -lh dist/
46+
# Store an artifact of the build to use in the publish step below
47+
- name: Store the distribution packages
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: python-package-distributions
51+
path: dist/
52+
publish:
53+
name: >-
54+
Publish Python 🐍 distribution 📦 to PyPI
55+
if: github.repository_owner == 'pyopensci'
56+
needs:
57+
- build
58+
runs-on: ubuntu-latest
59+
# This is the trusted environment. Notice that it's called pypi
60+
# that is the name that you will use in your pypi configuration
61+
environment:
62+
name: pypi
63+
url: https://pypi.org/p/pyospackage
64+
permissions:
65+
id-token: write # this permission is mandatory for pypi publishing
66+
steps:
67+
# Version 4 doesn't support GitHub enterprise yet
68+
- name: Download all the dists
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: python-package-distributions
72+
path: dist/
73+
- name: Publish package to PyPI
74+
# Only publish to real PyPI on release
75+
if: github.event_name == 'release'
76+
uses: pypa/gh-action-pypi-publish@release/v1

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Unreleased
44

5+
* Add: CI based pypi release workflow & dynamic versioning (@lwasser, #)
56
* Add: readthedocs config for building documentation (@lwasser)
67
* Add: Cleanup documentation structure (@lwasser)
78

pyproject.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[build-system]
2-
requires = ["hatchling"]
2+
requires = ["hatchling", "hatch-vcs"]
33
build-backend = "hatchling.build"
44

55
[project]
@@ -23,8 +23,6 @@ classifiers = [
2323

2424
dependencies = []
2525

26-
27-
2826
[project.urls]
2927
Homepage = "https://pypi.org/project/pyospackage/"
3028
Documentation = "https://github.com/pyopensci/pyospackage"
@@ -47,6 +45,12 @@ docs = [
4745
"sphinx-autoapi",
4846
]
4947

48+
# ******* Hatch configuration here ******* #
49+
50+
[tool.hatch]
51+
version.source = "vcs"
52+
build.hooks.vcs.version-file = "src/pyosmeta/_version.py"
53+
5054
[tool.hatch.envs.docs]
5155
# https://hatch.pypa.io/1.12/config/environment/overview/#features
5256
features = ["docs"]

0 commit comments

Comments
 (0)