From a4964a40fdedf1e5490c0182e09cee1d51a1aaa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6=C3=B6k=2C=20Vidar?= Date: Mon, 16 Sep 2024 14:13:39 +0200 Subject: [PATCH] Add CI pipelines and make --- .github/workflows/premerge.yaml | 22 ++++++++++++++++++++++ .github/workflows/release.yaml | 29 +++++++++++++++++++++++++++++ .gitignore | 1 + Makefile | 27 +++++++++++++++++++++++++++ README.md | 6 +++--- pyproject.toml | 18 +++++++++++++----- 6 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/premerge.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 Makefile diff --git a/.github/workflows/premerge.yaml b/.github/workflows/premerge.yaml new file mode 100644 index 0000000..3077de4 --- /dev/null +++ b/.github/workflows/premerge.yaml @@ -0,0 +1,22 @@ +name: CI + +on: + push: + branches: + - '**' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.8' + + - name: Run Makefile + run: make -B diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..8625522 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,29 @@ +name: Release to PyPI + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + environment: release + permissions: + id-token: write + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.8' + + - name: Build the package + run: make build + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: objs/dist/ diff --git a/.gitignore b/.gitignore index 0077b66..0885a34 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ __pycache__/** .idea/ test_run_logs/ +objs dist build diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..945d267 --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +ARTIFACTS_DIR := objs +ENV_DIR := $(ARTIFACTS_DIR)/.env +DIST_DIR := $(ARTIFACTS_DIR)/dist +VERSION := $(shell grep -Po '(?<=^version = ")[^"]*' pyproject.toml) +DIST_WHL := $(DIST_DIR)/coppercomm-$(VERSION)-py3-none-any.whl + +.PHONY: all test build clean requirements + +all: test build + +test: requirements + hatch run test + +build: requirements $(DIST_WHL) + +$(DIST_WHL): + rm -rf $(DIST_DIR) + hatch build + +requirements: $(ENV_DIR) + +$(ENV_DIR): + pip install hatch pytest + hatch env create + +clean: + rm -rf $(ARTIFACTS_DIR) \ No newline at end of file diff --git a/README.md b/README.md index 7f32f94..68ea8a2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Coppercomm Coppercomm is a lightweight library, written in Python. It is used by tests for communicating through different protocols. -![Coppercomm overview](images/coppercomm_overview.png) +![Coppercomm overview](https://raw.githubusercontent.com/volvo-cars/coppercomm/cf0f53986e5d438f1c485191af390252ece99e19/images/coppercomm_overview.png) Introduction ------------ @@ -12,10 +12,10 @@ One challenge with sharing test cases across different organizations/companies i When test cases across companies and organizations are using Coppercomm, the test cases can be executed without modifications or if-statements for different environments, in the test cases. It becomes convenient to execute test cases at different places. -![Coppercomm overview](images/coppercomm_config.png) +![Coppercomm overview](https://raw.githubusercontent.com/volvo-cars/coppercomm/cf0f53986e5d438f1c485191af390252ece99e19/images/coppercomm_config.png) Examples -------- There are some examples on how to use it here: -[test_example_pytest.py](examples/test_example_pytest.py). +[test_example_pytest.py](https://raw.githubusercontent.com/volvo-cars/coppercomm/cf0f53986e5d438f1c485191af390252ece99e19/examples/test_example_pytest.py). diff --git a/pyproject.toml b/pyproject.toml index 8da8710..dd36b47 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,24 +6,32 @@ build-backend = "hatchling.build" name = "coppercomm" version = "0.1.0" description = "Coppercomm" +readme = "README.md" authors = [{ name = "Volvo Cars" }] license = { file = "LICENSE" } +requires-python = ">=3.8" dependencies = ["paramiko", "pyserial", "pexpect"] +[project.urls] +Homepage = "https://github.com/volvo-cars/coppercomm" +Issues = "https://github.com/volvo-cars/coppercomm/issues" + [tool.hatch.envs.default] dependencies = ["types-paramiko", "mypy >= 0.991"] +path = "objs/.env" + +[tool.hatch.build] +directory = "objs/dist" [tool.hatch.build.targets.wheel] packages = ["src/coppercomm"] -[tool.hatch.build.targets.sdist] -include = ["src/coppercomm"] [tool.hatch.envs.default.scripts] -test = "pytest {args:tests}" -system-test = "pytest ./system_tests" -test-cov = "coverage run -m pytest {args:tests}" +test = "pytest -o cache_dir=objs/.pytest_cache {args:tests}" +system-test = "pytest -o cache_dir=objs/.pytest_cache ./system_tests" +test-cov = "coverage run -m pytest -o cache_dir=objs/.pytest_cache {args:tests}" cov-report = ["- coverage combine", "coverage report"] cov = ["test-cov", "cov-report"]