Skip to content

Commit bd39c33

Browse files
authored
Merge pull request #23 from andhus/publish-workflow
[WIP] Auto publishing
2 parents c69fe9f + 89f7241 commit bd39c33

File tree

9 files changed

+828
-7
lines changed

9 files changed

+828
-7
lines changed

.coveragerc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[run]
22
branch = True
33
source = dirhash
4+
omit = _version.py

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/dirhash/_version.py export-subst

.github/workflows/publish.yml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
# Based on https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/#
2+
name: Publish Python Package
3+
4+
on:
5+
push:
6+
tags:
7+
- 'v[0-9]+.[0-9]+.[0-9]*'
8+
9+
jobs:
10+
build:
11+
name: Build distribution
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
# NOTE: tags are not present unless triggered by tag push
17+
# - name: Get tags
18+
# run: git fetch --tags origin
19+
# - name: List tags
20+
# run: git tag --list
21+
# TODO: somehow versioneer does not pickup the tag when workflow is not triggered by a
22+
# tag push, getting e.g. (for sister repo scantree) scantree-0+untagged.1.gd74b1d5,
23+
# see: https://github.com/andhus/scantree/actions/runs/7485873305/job/20375116541#step:7:42)
24+
- name: Set up Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: "3.x"
28+
- name: Install pypa/build
29+
run: >-
30+
python3 -m
31+
pip install
32+
build
33+
--user
34+
- name: Build a binary wheel and a source tarball
35+
run: python3 -m build
36+
- name: Store the distribution packages
37+
uses: actions/upload-artifact@v3
38+
with:
39+
name: python-package-distributions
40+
path: dist/
41+
42+
publish-to-pypi:
43+
name: Publish to PyPI
44+
# TODO we need to make sure the tag matches the version!
45+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
46+
needs:
47+
- build
48+
runs-on: ubuntu-latest
49+
environment:
50+
name: pypi
51+
url: https://pypi.org/p/dirhash
52+
permissions:
53+
id-token: write # IMPORTANT: mandatory for trusted publishing
54+
55+
steps:
56+
- name: Download all the dists
57+
uses: actions/download-artifact@v3
58+
with:
59+
name: python-package-distributions
60+
path: dist/
61+
- name: Publish distribution 📦 to PyPI
62+
uses: pypa/gh-action-pypi-publish@release/v1
63+
64+
github-release:
65+
name: Sign and upload to GitHub Release
66+
needs:
67+
- publish-to-pypi
68+
runs-on: ubuntu-latest
69+
70+
permissions:
71+
contents: write # IMPORTANT: mandatory for making GitHub Releases
72+
id-token: write # IMPORTANT: mandatory for sigstore
73+
74+
steps:
75+
- name: Download all the dists
76+
uses: actions/download-artifact@v3
77+
with:
78+
name: python-package-distributions
79+
path: dist/
80+
- name: Sign the dists with Sigstore
81+
uses: sigstore/[email protected]
82+
with:
83+
inputs: >-
84+
./dist/*.tar.gz
85+
./dist/*.whl
86+
- name: Create GitHub Release
87+
env:
88+
GITHUB_TOKEN: ${{ github.token }}
89+
run: >-
90+
gh release create
91+
'${{ github.ref_name }}'
92+
--repo '${{ github.repository }}'
93+
--notes ""
94+
- name: Upload artifact signatures to GitHub Release
95+
env:
96+
GITHUB_TOKEN: ${{ github.token }}
97+
# Upload to GitHub Release using the `gh` CLI.
98+
# `dist/` contains the built packages, and the
99+
# sigstore-produced signatures and certificates.
100+
run: >-
101+
gh release upload
102+
'${{ github.ref_name }}' dist/**
103+
--repo '${{ github.repository }}'
104+
105+
publish-to-testpypi:
106+
name: Publish to TestPyPI
107+
if: startsWith(github.ref, 'refs/tags/') # only publish on tag pushes
108+
needs:
109+
- build
110+
runs-on: ubuntu-latest
111+
112+
environment:
113+
name: testpypi
114+
url: https://test.pypi.org/p/dirhash
115+
116+
permissions:
117+
id-token: write # IMPORTANT: mandatory for trusted publishing
118+
119+
steps:
120+
- name: Download all the dists
121+
uses: actions/download-artifact@v3
122+
with:
123+
name: python-package-distributions
124+
path: dist/
125+
- name: Publish distribution 📦 to TestPyPI
126+
uses: pypa/gh-action-pypi-publish@release/v1
127+
with:
128+
repository-url: https://test.pypi.org/legacy/

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools", "versioneer==0.29"]
3+
build-backend = "setuptools.build_meta"

setup.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[versioneer]
2+
VCS = git
3+
style = pep440
4+
versionfile_source = src/dirhash/_version.py
5+
versionfile_build = dirhash/_version.py
6+
tag_prefix = v
7+
parentdir_prefix = dirhash-

setup.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
import os
33
from setuptools import setup, find_packages
44

5-
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
5+
import versioneer
66

7-
version = {}
8-
with io.open(os.path.join(PROJECT_ROOT, "src", "dirhash", "version.py")) as fp:
9-
exec(fp.read(), version)
7+
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
108

119
DESCRIPTION = 'Python module and CLI for hashing of file system directories.'
1210

@@ -18,7 +16,7 @@
1816

1917
setup(
2018
name='dirhash',
21-
version=version['__version__'],
19+
version=versioneer.get_version(),
2220
description=DESCRIPTION,
2321
long_description=long_description,
2422
long_description_content_type="text/markdown",

src/dirhash/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
CyclicLinkedDir,
1616
)
1717

18-
from dirhash.version import __version__
18+
from . import _version
19+
__version__ = _version.get_versions()['version']
1920

2021
__all__ = [
2122
'__version__',

0 commit comments

Comments
 (0)