From 22894454d6c74244afd32201071b5717297fa407 Mon Sep 17 00:00:00 2001 From: "Jimmy C. Kromann" Date: Fri, 5 Apr 2024 18:10:01 +0200 Subject: [PATCH] Starting the versioning CI (#8) * Enable format * Enable Makefile versioning * Init Release and Publish workflow --- .github/workflows/publish.yml | 29 ++++++++++++ .github/workflows/release.yml | 24 ++++++++++ .github/workflows/test.yml | 11 ++--- Makefile | 49 ++++++++++++++++++--- environment_dev.yaml | 1 + src/qmllib/representations/arad/__init__.py | 2 +- tests/test_fchl_acsf.py | 2 +- tests/test_fchl_force.py | 2 + 8 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..22e042a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,29 @@ +name: Publish PyPI + +on: + release: + branches: + - main + +jobs: + + deploy: + name: Publish Release + runs-on: "ubuntu-latest" + steps: + - uses: actions/checkout@v1 + - name: Setup Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install setuptools build twine + - name: Build package + run: make build python=python + - name: Publish package + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + run: make upload python=python diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..45e025d --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,24 @@ +name: Release Version + +on: + push: + branches: + - main + +jobs: + + release: + name: Testing + runs-on: "ubuntu-latest" + defaults: + run: + shell: bash -l {0} + steps: + - name: Bump version + run: make something + - name: Commit version + run: make something + - name: Push to main + run: git push origin --tags + - name: Create release + run: no idea diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 41fab53..5774cf8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,4 @@ - -name: Test Python package +name: Test on: push: @@ -9,6 +8,7 @@ on: branches: [ main ] jobs: + test: name: Testing runs-on: "ubuntu-latest" @@ -25,11 +25,6 @@ jobs: activate-environment: dev environment-file: ./environment_dev.yaml python-version: ${{ matrix.python-version }} - - run: | - ls - pwd - which python - conda info - run: pip install . -v - run: make test python=python - # - run: make format python=python + - run: make format python=python diff --git a/Makefile b/Makefile index a27cfea..dbbe9ea 100644 --- a/Makefile +++ b/Makefile @@ -5,20 +5,24 @@ pip=./env/bin/pip pytest=pytest j=1 +version_file=src/qmllib/version.py + .PHONY: build -all: env setup +all: env + +## Setup env: ${mamba} env create -f ./environment_dev.yaml -p ./env --quiet ${python} -m pre_commit install ${python} -m pip install -e . -setup: ./.git/hooks/pre-commit - ./.git/hooks/pre-commit: ${python} -m pre_commit install +## Development + format: ${python} -m pre_commit run --all-files @@ -37,9 +41,42 @@ compile: build: ${python} -m build --sdist --skip-dependency-check . - @# ${python} -m pip wheel --no-deps -v . - @# ${python} -m pip wheel -v . - @#ls *.whl + +upload: + ${python} -m twine upload ./dist/*.tar.gz + +## Version + +VERSION=$(shell cat ${version_file} | egrep -o "([0-9]{1,}\.)+[0-9]{1,}") +VERSION_PATCH=$(shell echo ${VERSION} | cut -d'.' -f3) +VERSION_MINOR=$(shell echo ${VERSION} | cut -d'.' -f2) +VERSION_MAJOR=$(shell echo ${VERSION} | cut -d'.' -f1) +GIT_COMMIT=$(shell git rev-parse --short HEAD) + +bump-version-dev: + test ! -z "${VERSION}" + test ! -z "${GIT_COMMIT}" + exit 1 + # Not Implemented + +bump-version-patch: + test ! -z "${VERSION_PATCH}" + echo "__version__ = \"${VERSION_MAJOR}.${VERSION_MINOR}.$(shell awk 'BEGIN{print ${VERSION_PATCH}+1}')\"" > ${version_file} + +bump-version-minor: + test ! -z "${VERSION_MINOR}" + echo "__version__ = \"${VERSION_MAJOR}.$(shell awk 'BEGIN{print ${VERSION_MINOR}+1}').0\"" > ${version_file} + +bump-version-major: + test ! -z "${VERSION_MAJOR}" + echo "__version__ = \"$(shell awk 'BEGIN{print ${VERSION_MAJOR}+1}').0.0\"" > ${version_file} + +commit-version-tag: + git tag --list | grep -qix "${VERSION}" + git commit -m "Release ${VERSION}" --no-verify ${version_file} + git tag 'v${VERSION}' + +## Clean clean: find ./src/ -type f \ diff --git a/environment_dev.yaml b/environment_dev.yaml index e3031ae..4d7d959 100644 --- a/environment_dev.yaml +++ b/environment_dev.yaml @@ -18,4 +18,5 @@ dependencies: - build - meson - ninja + # publish - twine diff --git a/src/qmllib/representations/arad/__init__.py b/src/qmllib/representations/arad/__init__.py index 8042565..608ef7c 100644 --- a/src/qmllib/representations/arad/__init__.py +++ b/src/qmllib/representations/arad/__init__.py @@ -20,4 +20,4 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from .arad import * +from .arad import * # noqa: F403 diff --git a/tests/test_fchl_acsf.py b/tests/test_fchl_acsf.py index 92908e2..3e4bc64 100644 --- a/tests/test_fchl_acsf.py +++ b/tests/test_fchl_acsf.py @@ -5,10 +5,10 @@ from copy import deepcopy import numpy as np +from conftest import ASSETS from qmllib.representations import generate_fchl_acsf from qmllib.utils.xyz_format import read_xyz -from tests.conftest import ASSETS np.set_printoptions(linewidth=666, edgeitems=10) REP_PARAMS = dict() diff --git a/tests/test_fchl_force.py b/tests/test_fchl_force.py index 7a90d97..98af0ba 100644 --- a/tests/test_fchl_force.py +++ b/tests/test_fchl_force.py @@ -1,3 +1,5 @@ +# flake8: noqa + import ast import csv from copy import deepcopy