Skip to content

Commit 52f5379

Browse files
author
Antoine
committed
Add CI workflow, build script, and setup for package versioning
1 parent f230fa8 commit 52f5379

File tree

5 files changed

+90
-7
lines changed

5 files changed

+90
-7
lines changed

.github/workflows/OnPush.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: On Push Workflow
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.txt
29+
30+
- name: Run tests
31+
run: make tests
32+
33+
- name: Upload test reports
34+
uses: actions/upload-artifact@v3
35+
with:
36+
name: test-reports
37+
path: tests_reports/
38+
39+
- name: publish test report
40+
uses: mikepenz/action-junit-report@v5
41+
with:
42+
report_paths: tests_reports/**/report.xml
43+
include_passed: true

build_package.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
This script builds a Python package using the `build` module.
3+
It allows for passing additional arguments to the build command and
4+
supports specifying a version number via command line arguments.
5+
It also sets the `PACKAGE_VERSION` environment variable if a version is provided.
6+
"""
7+
8+
import os
9+
import subprocess
10+
import sys
11+
12+
if "--version" in sys.argv:
13+
idx = sys.argv.index("--version")
14+
version = sys.argv[idx + 1]
15+
os.environ["PACKAGE_VERSION"] = version
16+
sys.argv.pop(idx) # remove --version
17+
sys.argv.pop(idx) # remove version value
18+
19+
print(f"{sys.executable} -m build {' '.join(sys.argv[1:])}")
20+
try:
21+
subprocess.run([sys.executable, "-m", "build"] + sys.argv[1:],
22+
check=True, stderr=sys.stderr, stdout=sys.stdout)
23+
except subprocess.CalledProcessError as e:
24+
print(f"Build failed with error code {e.returncode}")
25+
sys.exit(e.returncode)

config/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ authors = [
77
]
88
requires-python = ">=3.8"
99

10+
[tool.setuptools]
11+
packages = { find = { include = ["config*"], exclude = ["*_tests"] } }
1012

1113
[tool.pytest.ini_options]
1214
minversion = "8.0"

makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11

2+
VERSION = 0.1.0
3+
24
MODULES = cache colors config http_code version
35

4-
TARGETS = $(addprefix dist/,$(addsuffix -0.1.0.tar.gz,$(MODULES)))
5-
TARGETS += $(addprefix dist/,$(addsuffix -0.1.0-py3-none-any.whl,$(MODULES)))
6+
TARGETS = $(addprefix dist/,$(addsuffix -$(VERSION).tar.gz,$(MODULES)))
7+
TARGETS += $(addprefix dist/,$(addsuffix -$(VERSION)-py3-none-any.whl,$(MODULES)))
68

79
.PHONY: all clean tests
810

911
all: $(TARGETS)
1012

11-
dist/%-0.1.0-py3-none-any.whl: dist/%-0.1.0.tar.gz
12-
python3 -m pip wheel --no-deps --wheel-dir dist $<
13+
dist/%-$(VERSION)-py3-none-any.whl: dist/%-$(VERSION).tar.gz
14+
python -m pip wheel --no-deps --wheel-dir dist $<
1315

14-
dist/%-0.1.0.tar.gz: %
15-
python3 -m build --sdist --outdir dist $<
16+
dist/%-$(VERSION).tar.gz: %
17+
python build_package.py --version $(VERSION) --sdist --outdir dist $<
1618

1719
tests/%: % #with pytest
18-
-coverage run -m --branch pytest --tb=short --disable-warnings --junitxml=tests_reports/$*/report.xml $<
20+
-coverage run --branch -m pytest --tb=short --disable-warnings --junitxml=tests_reports/$*/report.xml $<
1921
@coverage report -m
2022
@coverage html -d tests_reports/$*/coverage
2123
@rm .coverage

setup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""
2+
Setup script for the package, used by setuptools to build and install the package.
3+
"""
4+
5+
import os
6+
7+
from setuptools import setup
8+
9+
setup(
10+
version=os.environ.get("PACKAGE_VERSION", "0.0.0-dev")
11+
)

0 commit comments

Comments
 (0)