From 00b451bce867163068cf149a52c41f850056c7c8 Mon Sep 17 00:00:00 2001 From: gokborayilmaz Date: Fri, 16 Aug 2024 18:43:02 +0300 Subject: [PATCH] feat: Added refactoring process --- .github/workflows/refactor.yml | 27 +++++++++++++++++++++++++++ bump.py | 6 +++--- refactor.py | 26 ++++++++++++++++++++++++++ upsonic/__init__.py | 2 +- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/refactor.yml create mode 100644 refactor.py diff --git a/.github/workflows/refactor.yml b/.github/workflows/refactor.yml new file mode 100644 index 0000000..13951e1 --- /dev/null +++ b/.github/workflows/refactor.yml @@ -0,0 +1,27 @@ +name: Manual Refactor + +on: + workflow_dispatch: + +jobs: + run-refactor: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + + - name: setup git config + run: | + # setup the username and email. I tend to use 'GitHub Actions Bot' with no email by default + git config user.name "Upsonic Refactor Bot" + git config user.email "" + + - name: Run Refactor Script + run: | + python refactor.py \ No newline at end of file diff --git a/bump.py b/bump.py index 06368a7..9f1a5ed 100644 --- a/bump.py +++ b/bump.py @@ -5,7 +5,7 @@ def read_version(): with open('upsonic/__init__.py', 'r') as file: for line in file: - match = re.search(r"__version__ = '(.*)'", line) + match = re.search(r"__version__ = '(.*)'", line) # fmt: skip if match: return match.group(1) @@ -25,7 +25,7 @@ def increment_version(part, version): def write_version(version): with open('upsonic/__init__.py', 'r+') as file: content = file.read() - content = re.sub(r"__version__ = '.*'", f"__version__ = '{version}'", content) + content = re.sub(r"__version__ = '.*'", f"__version__ = '{version}'", content) # fmt: skip file.seek(0) file.write(content) @@ -34,7 +34,7 @@ def update_version(version): for file in files: with open(file, 'r+') as f: content = f.read() - content = re.sub(r' version=".*"', f' version="{version}"', content) + content = re.sub(r' version=".*"', f' version="{version}"', content) # fmt: skip f.seek(0) f.write(content) diff --git a/refactor.py b/refactor.py new file mode 100644 index 0000000..6276cb3 --- /dev/null +++ b/refactor.py @@ -0,0 +1,26 @@ +import os + + +def install_refactor_tool(): + os.system("pip install ruff==0.6.0") + + +def refactor(): + os.system("ruff check --fix") + os.system("ruff format") + + +def create_commit(): + os.system("git add .") + os.system("git commit -m 'refactor: Scheduled refactoring'") + + +def push(): + os.system("git push") + + +if __name__ == "__main__": + install_refactor_tool() + refactor() + create_commit() + push() \ No newline at end of file diff --git a/upsonic/__init__.py b/upsonic/__init__.py index 08c0e4f..e057c3f 100644 --- a/upsonic/__init__.py +++ b/upsonic/__init__.py @@ -28,7 +28,7 @@ open_databases = {} -__version__ = '0.28.4' +__version__ = '0.28.4' # fmt: skip