Skip to content

Commit 8a1782b

Browse files
authored
Merge pull request #77 from hnez/auto-pypi
CI: add automatic publication to pypi.org and test.pypi.org
2 parents 2da3f46 + 51d9421 commit 8a1782b

File tree

4 files changed

+71
-44
lines changed

4 files changed

+71
-44
lines changed

.github/workflows/check-and-build.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Check and Publish
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
codespell:
7+
name: Codespell
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
- run: make qa-codespell
12+
13+
pytest:
14+
name: Python Test
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- run: make qa-pytest
19+
20+
ruff:
21+
name: Python Format and Lint
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
- run: make qa-ruff
26+
27+
build:
28+
name: Python Build
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
# include tags and full history for setuptools_scm
34+
fetch-depth: 0
35+
- run: make build
36+
- uses: actions/upload-artifact@v4
37+
with:
38+
name: dist
39+
path: dist
40+
41+
publish:
42+
name: Publish
43+
if: ${{ github.event_name == 'push' && vars.PUBLISH_PYPI == 'true' && (startsWith(github.ref, 'refs/tags') || github.ref == 'refs/heads/master') }}
44+
runs-on: ubuntu-latest
45+
needs:
46+
- codespell
47+
- pytest
48+
- ruff
49+
- build
50+
permissions:
51+
id-token: write
52+
steps:
53+
- name: Download artifacts from build stage
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: dist
57+
path: dist/
58+
- name: Publish distribution package to TestPyPI
59+
uses: pypa/gh-action-pypi-publish@release/v1
60+
with:
61+
repository-url: https://test.pypi.org/legacy/
62+
- name: Publish distribution package to PyPI
63+
if: ${{ startsWith(github.ref, 'refs/tags') }}
64+
uses: pypa/gh-action-pypi-publish@release/v1

Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ $(PYTHON_PACKAGING_VENV)/.created:
1212
$(PYTHON) -m venv $(PYTHON_PACKAGING_VENV) && \
1313
. $(PYTHON_PACKAGING_VENV)/bin/activate && \
1414
$(PYTHON) -m pip install --upgrade pip && \
15-
$(PYTHON) -m pip install build twine
15+
$(PYTHON) -m pip install build
1616
date > $(PYTHON_PACKAGING_VENV)/.created
1717

18-
.PHONY: packaging-env build _release
18+
.PHONY: packaging-env build
1919

2020
packaging-env: $(PYTHON_PACKAGING_VENV)/.created
2121

@@ -24,10 +24,6 @@ build: packaging-env
2424
rm -rf dist *.egg-info && \
2525
$(PYTHON) -m build
2626

27-
_release: build
28-
. $(PYTHON_PACKAGING_VENV)/bin/activate && \
29-
$(PYTHON) -m twine upload dist/*
30-
3127
# helper ######################################################################
3228
.PHONY: clean envs
3329

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[build-system]
2-
requires = ["setuptools"]
2+
requires = ["setuptools", "setuptools_scm[toml]"]
33
build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "usbsdmux"
77
description = "Tool to control an USB-SD-Mux from the command line"
8-
version = "24.01.1"
98
authors = [
109
{ name = "Chris Fiege", email = "[email protected]" },
1110
]
@@ -18,6 +17,7 @@ classifiers = [
1817
"Operating System :: Unix",
1918
"Programming Language :: Python :: 3 :: Only",
2019
]
20+
dynamic = ["version"] # via setuptools_scm
2121

2222
[project.optional-dependencies]
2323
mqtt = ["paho-mqtt"]
@@ -37,6 +37,9 @@ packages = [
3737
]
3838
include-package-data = true
3939

40+
[tool.setuptools_scm]
41+
local_scheme = "no-local-version"
42+
4043
[tool.ruff]
4144
line-length = 119
4245
exclude = [

0 commit comments

Comments
 (0)