From 5e41959099ee3f8dc581435dd708f8d18faa3440 Mon Sep 17 00:00:00 2001 From: hminaee-tc Date: Tue, 2 Jul 2024 18:18:35 -0300 Subject: [PATCH] feat/check-v2 add e2e for check v --- .github/workflows/tests.yml | 10 ++++- .../pypi_bumpversion_check/main.py | 2 +- .../.pre-commit-config.yaml | 25 +++++++++++ .../tests-pre-commit-hook/pyproject.test | 44 +++++++++++++++++++ .../test-pre-commit-hook.sh | 35 +++++++++++++++ 5 files changed, 113 insertions(+), 3 deletions(-) mode change 100644 => 100755 opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml create mode 100644 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test create mode 100755 opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c3ea9db..1f6c0e4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -46,7 +46,7 @@ jobs: with: python-version: 3.11 - - name: Run test-package-e2e.sh + - name: Run test-package-e2e.sh for find-replace-strings package run: | cd opencepk_lib_python_common/find_and_replace_strings_package/tests-package-e2e ./test-package-e2e.sh @@ -67,8 +67,14 @@ jobs: with: python-version: 3.11 - - name: Run test-pre-commit-hook.sh + - name: Run test-pre-commit-hook.sh for find-replace-strings package run: | pip install pre-commit cd opencepk_lib_python_common/find_and_replace_strings_package/tests-pre-commit-hook ./test-pre-commit-hook.sh + + - name: Run test-pre-commit-hook.sh for check version package + run: | + pip install pre-commit + cd opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook + ./test-pre-commit-hook.sh diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py old mode 100644 new mode 100755 index 82f161c..47a6f65 --- a/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/main.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- #!/usr/bin/env python3 +# -*- coding: utf-8 -*- import argparse import toml import sys diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml new file mode 100644 index 0000000..34f0738 --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/.pre-commit-config.yaml @@ -0,0 +1,25 @@ +--- +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + + # ----------------------------- + # PYPI bumpversion check + # ----------------------------- + - repo: local + hooks: + - id: install-pypi_bumpversion_check-requirements + name: Install PYPI bumpversion check requirements + entry: sh -c 'python3 -m pip install -r ./opencepk_lib_python_common/pypi_bumpversion_check_package/pypi_bumpversion_check/requirements.txt && exit 0' + language: system + always_run: true + - repo: local + hooks: + - id: python-pypi-version-check + name: python-pypi-version-check + entry: python3 -m opencepk_lib_python_common.pypi_bumpversion_check_package.pypi_bumpversion_check + language: python + exclude_types: + - binary + args: ['./opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test'] + pass_filenames: false # Do not pass filenames to the hook (this is important to keep) diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test new file mode 100644 index 0000000..1a68cda --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/pyproject.test @@ -0,0 +1,44 @@ +[build-system] +requires = ["setuptools>=61.0", "wheel"] +build-backend = "setuptools.build_meta" + +[tool.setuptools] +packages = { find = { where = ["."] } } + +[project] +name = "opencepk-lib-python-common" +version = "0.0.0" +description = "Python package and pre-commit-hook for finding and replacing string(s) in file(s)." +readme = "README.md" +license = { text = "GPLv3" } +authors = [{name = "OpenCEPK Open Cloud Engineering Platform Kit", email = "opencepk@gmail.com"}] +requires-python = ">=3.9" + +keywords = ["find", "replace", "string", "file", "pre-commit", "hook", "git", "tool", "utility", "opencepk"] +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Natural Language :: English", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Topic :: File Formats :: JSON", + "Topic :: Software Development :: Pre-processors", + "Topic :: Software Development :: Version Control :: Git", + "Topic :: Text Processing", + "Topic :: Text Processing :: Filters", + "Topic :: Text Processing :: General", + "Topic :: Utilities" +] + +[project.entry-points."console_scripts"] +python-pypi-version-check = "opencepk_lib_python_common.pypi_bumpversion_check_package.pypi_bumpversion_check.main:main" +find-and-replace-strings = "opencepk_lib_python_common.find_and_replace_strings_package.find_and_replace_strings.main:main" diff --git a/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh new file mode 100755 index 0000000..972c5b6 --- /dev/null +++ b/opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook/test-pre-commit-hook.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +TEST_DIR_FROM_ROOT="opencepk_lib_python_common/pypi_bumpversion_check_package/tests-pre-commit-hook" +TEST_DIR="tests-pre-commit-hook" +TEST_SCRIPT_FILENAME=$(basename -- "$0") +TEST_SCRIPT_NAME="${TEST_SCRIPT_FILENAME%.*}" +TEST_TARGET_FILE="README_TEST_PRE_COMMIT.md" + +#------------------------------- +# Run the pre-commit hook test +#------------------------------- +echo "${TEST_SCRIPT_NAME}: Running pre-commit using ${TEST_DIR_FROM_ROOT}/.pre-commit-config.yaml" +cd ../../.. +pwd +pre-commit run -a -c "${TEST_DIR_FROM_ROOT}/.pre-commit-config.yaml" + +# #------------------------------- +# # Evaluate results +# #------------------------------- +# echo "${TEST_SCRIPT_NAME}: Running (cd ${TEST_DIR} && diff ${TEST_TARGET_FILE} ${TEST_TARGET_FILE}.expected)" +# echo "${TEST_SCRIPT_NAME}: Fetching return code of diff" +# diff "./${TEST_TARGET_FILE}" "${TEST_TARGET_FILE}.expected" +# evaluate_diff_status=$? + +# #------------------------------- +# # Run the pre-commit hook reset +# #------------------------------- +# echo "${TEST_SCRIPT_NAME}: Resetting ${TEST_DIR}/${TEST_TARGET_FILE} file to original state" +# cp -pf "${TEST_TARGET_FILE}.template" "${TEST_TARGET_FILE}" + +# #------------------------------- +# # Exit with exit code of diff evaluation +# #------------------------------- +# echo "${TEST_SCRIPT_NAME}: Exit code = $evaluate_diff_status" +# exit $evaluate_diff_status