diff --git a/README.md b/README.md index db4f7b5..4a8a29c 100644 --- a/README.md +++ b/README.md @@ -330,12 +330,15 @@ def stream_events(input_script: smi.Script, inputs: smi.InputDefinition, event_w * required: false * default: "bin" -#### is_remove_pyc_from_splunklib_dir -* description: "Remove `.pyc` files and `__pycache__` directory from splunk-python-sdk (splunklib) installation path before generating Pull Request. Do not turn this off unless you are facing any issues explicitly." +#### remove_pyc_before_commit +* description: "Remove `.pyc` files and `__pycache__` directory from the repository before generating Pull Request. Do not turn this off unless you are facing any issues explicitly." * required: false * default: true +### Removed Parameters in v5 +* is_remove_pyc_from_splunklib_dir + * Use remove_pyc_before_commit instead. diff --git a/action.yml b/action.yml index 5263ab3..f8e6e52 100644 --- a/action.yml +++ b/action.yml @@ -59,8 +59,8 @@ inputs: required: false default: "bin" - is_remove_pyc_from_splunklib_dir: - description: "Remove `.pyc` files and `__pycache__` directory from splunk-python-sdk (splunklib) installation path before generating Pull Request. Do not turn this off unless you are facing any issues explicitly." + remove_pyc_before_commit: + description: "Remove `.pyc` files and `__pycache__` directory from the repository before generating Pull Request. Do not turn this off unless you are facing any issues explicitly." required: false default: true @@ -104,7 +104,7 @@ runs: echo "logger_log_files_prefix -> ${{inputs.logger_log_files_prefix}}" echo "logger_sourcetype -> ${{inputs.logger_sourcetype}}" echo "splunk_python_sdk_install_path -> ${{inputs.splunk_python_sdk_install_path}}" - echo "is_remove_pyc_from_splunklib_dir -> ${{inputs.is_remove_pyc_from_splunklib_dir}}" + echo "remove_pyc_before_commit -> ${{inputs.remove_pyc_before_commit}}" - name: "Install Python" uses: actions/setup-python@v5 @@ -132,7 +132,7 @@ runs: SPLUNK_logger_log_files_prefix: ${{inputs.logger_log_files_prefix}} SPLUNK_logger_sourcetype: ${{inputs.logger_sourcetype}} SPLUNK_splunk_python_sdk_install_path: ${{inputs.splunk_python_sdk_install_path}} - SPLUNK_is_remove_pyc_from_splunklib_dir: ${{inputs.is_remove_pyc_from_splunklib_dir}} + SPLUNK_remove_pyc_before_commit: ${{inputs.remove_pyc_before_commit}} run: | python -u ${{ github.action_path }}/src/main.py diff --git a/src/utilities/base_utility.py b/src/utilities/base_utility.py index 7de00d3..9183734 100644 --- a/src/utilities/base_utility.py +++ b/src/utilities/base_utility.py @@ -2,6 +2,7 @@ import os from helpers.git_manager import GitHubPR, get_file_hash, get_multi_files_hash, get_folder_hash import helpers.github_action_utils as utils +from helpers.global_variables import GlobalVariables class BaseUtility: @@ -30,6 +31,14 @@ def add(self): else: utils.error("File to generate hash is invalid.") + self.remove_pyc_before_commit = utils.str_to_boolean_default_true( + utils.get_input('remove_pyc_before_commit')) + utils.info(f"remove_pyc_before_commit: {self.remove_pyc_before_commit}") + + # Removing .pyc and __pycache__ + if self.remove_pyc_before_commit: + self.remove_pycache(GlobalVariables.ORIGINAL_APP_DIR_PATH) + if hash: utils.debug("Committing and creating PR for the code change.") github.commit_and_pr(hash=hash) diff --git a/src/utilities/splunk_sdk_python/__init__.py b/src/utilities/splunk_sdk_python/__init__.py index 8464fd3..dd52695 100644 --- a/src/utilities/splunk_sdk_python/__init__.py +++ b/src/utilities/splunk_sdk_python/__init__.py @@ -38,10 +38,6 @@ def implement_utility(self): if not splunk_python_sdk_install_path or splunk_python_sdk_install_path == "NONE": splunk_python_sdk_install_path = "bin" - is_remove_pyc_from_splunklib_dir = utils.str_to_boolean_default_true( - utils.get_input('is_remove_pyc_from_splunklib_dir')) - utils.info(f"is_remove_pyc_from_splunklib_dir: {is_remove_pyc_from_splunklib_dir}") - folder_to_install_splunklib = os.path.join( self.app_write_dir, splunk_python_sdk_install_path) @@ -75,10 +71,6 @@ def implement_utility(self): utils.execute_system_command( f'pip install splunk-sdk --target "{folder_to_install_splunklib}"') - # Removing .pyc and __pycache__ - if is_remove_pyc_from_splunklib_dir: - self.remove_pycache(folder_to_install_splunklib) - new_version = self._get_splunklib_version(init_file) utils.info(f"New splunklib version = {new_version}") diff --git a/tests/helper.py b/tests/helper.py index 2ae10e5..e1f16d3 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -19,7 +19,7 @@ def setup_action_yml(test_app_repo, logger_log_files_prefix="NONE", logger_sourcetype="NONE", splunk_python_sdk_install_path="bin", - is_remove_pyc_from_splunklib_dir="true"): + remove_pyc_before_commit="true"): app_dir_path = os.path.join(os.path.dirname(__file__), "test_app_repos", test_app_repo) print(f"TestIntegration.setup_action_yml_work -> app_dir_path={app_dir_path}") @@ -40,7 +40,7 @@ def setup_action_yml(test_app_repo, os.environ["SPLUNK_logger_log_files_prefix"] = logger_log_files_prefix os.environ["SPLUNK_logger_sourcetype"] = logger_sourcetype os.environ["SPLUNK_splunk_python_sdk_install_path"] = splunk_python_sdk_install_path - os.environ["SPLUNK_is_remove_pyc_from_splunklib_dir"] = is_remove_pyc_from_splunklib_dir + os.environ["SPLUNK_remove_pyc_before_commit"] = remove_pyc_before_commit try: yield diff --git a/tests/test_utility_python_sdk.py b/tests/test_utility_python_sdk.py index e5bde9e..fd94563 100644 --- a/tests/test_utility_python_sdk.py +++ b/tests/test_utility_python_sdk.py @@ -36,7 +36,7 @@ def test_splunk_sdk_utility_installed_new_2(): with get_temp_directory() as temp_dir: with setup_temporary_env_vars({ "SPLUNK_splunk_python_sdk_install_path": "lib", - "SPLUNK_is_remove_pyc_from_splunklib_dir": "true" + "SPLUNK_remove_pyc_before_commit": "true" }): sdk_utility = SplunkPythonSDKUtility("nothing", temp_dir) result = sdk_utility.implement_utility() @@ -162,7 +162,7 @@ def test_splunk_sdk_utility_skipped_due_to_existing_and_same_version_2(): def test_splunk_sdk_utility_error_upgrading_existing(): with get_temp_directory() as temp_dir: with setup_temporary_env_vars({ - "SPLUNK_is_remove_pyc_from_splunklib_dir": "true", + "SPLUNK_remove_pyc_before_commit": "true", }): # Prepare the temporary directory folder_path = os.path.join(temp_dir, 'bin')