From 8adacc5d76092bb30b293861f0864763b7b09978 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Tue, 29 Jul 2025 20:19:45 +0530 Subject: [PATCH 01/14] ruff-check.yml file updated --- .github/workflows/ruff-check.yml | 72 ++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/.github/workflows/ruff-check.yml b/.github/workflows/ruff-check.yml index 8e5cbbce..b0d4589a 100644 --- a/.github/workflows/ruff-check.yml +++ b/.github/workflows/ruff-check.yml @@ -1,38 +1,46 @@ -name: Ruff check for python code +name: Ruff check on changed files only on: - push: - branches: - - main - paths: - - 'api-server/**' - - 'state-manager/**' - pull_request: - branches: - - main - paths: - - 'api-server/**' - - 'state-manager/**' - workflow_dispatch: + push: + branches: [main] + paths: + - 'api-server/**' + - 'state-manager/**' + pull_request: + branches: [main] + paths: + - 'api-server/**' + - 'state-manager/**' + workflow_dispatch: permissions: - contents: read - id-token: write - pages: write + contents: read jobs: - check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: '3.12' - - name: Ruff Check - uses: astral-sh/ruff-action@v3 - with: - src: './api-server' - - name: Ruff Check - uses: astral-sh/ruff-action@v3 - with: - src: './state-manager' + ruff-changed-files: + 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.12' + + - name: Get changed Python files in api-server and state-manager + id: changed-files + run: | + CHANGED=$(git diff --name-only origin/main...HEAD | grep -E '^api-server/|^state-manager/' | grep '\.py$' || true) + echo "files=$CHANGED" >> $GITHUB_OUTPUT + + - name: Run Ruff on changed files + if: steps.changed-files.outputs.files != '' + run: | + echo "Linting the following files:" + echo "${{ steps.changed-files.outputs.files }}" + ruff check ${{ steps.changed-files.outputs.files }} + + - name: Skip Ruff if no files changed + if: steps.changed-files.outputs.files == '' + run: echo "No Python files changed in target folders. Skipping Ruff." From 4ff356b6cc7fdc9250fcd385dccfb93fa8f9d746 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 00:08:27 +0530 Subject: [PATCH 02/14] test of ruff-check --- api-server/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-server/run.py b/api-server/run.py index a69dcdc8..dd33b831 100644 --- a/api-server/run.py +++ b/api-server/run.py @@ -18,7 +18,7 @@ def serve(): print(f"Running with {workers} workers") uvicorn.run("app.main:app", workers=workers, host="0.0.0.0", port=8000) else: - raise ValueError(f"Invalid mode: {mode}") + raise ValueError(f"Invalid mode provided: {mode}") if __name__ == "__main__": serve() From e3da0809cbd24f43332fa9e1104222851561b4fd Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 00:30:30 +0530 Subject: [PATCH 03/14] ruff-check-yaml updated --- .github/workflows/ruff-check.yml | 38 ++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ruff-check.yml b/.github/workflows/ruff-check.yml index b0d4589a..3b3e44a1 100644 --- a/.github/workflows/ruff-check.yml +++ b/.github/workflows/ruff-check.yml @@ -3,14 +3,8 @@ name: Ruff check on changed files only on: push: branches: [main] - paths: - - 'api-server/**' - - 'state-manager/**' pull_request: branches: [main] - paths: - - 'api-server/**' - - 'state-manager/**' workflow_dispatch: permissions: @@ -19,28 +13,48 @@ permissions: jobs: ruff-changed-files: runs-on: ubuntu-latest + steps: - - name: Checkout Code + # 1. Checkout entire history for accurate diffs + - name: Checkout code uses: actions/checkout@v4 + with: + fetch-depth: 0 + # 2. Set up Python for Ruff - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' - - name: Get changed Python files in api-server and state-manager + # 3. Determine changed Python files in api-server/ and state-manager/ + - name: Get changed Python files id: changed-files run: | - CHANGED=$(git diff --name-only origin/main...HEAD | grep -E '^api-server/|^state-manager/' | grep '\.py$' || true) - echo "files=$CHANGED" >> $GITHUB_OUTPUT + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + BASE_SHA=${{ github.event.pull_request.base.sha }} + HEAD_SHA=${{ github.sha }} + else + BASE_SHA=${{ github.event.before }} + HEAD_SHA=${{ github.event.after }} + fi + + # List all changed .py files in target directories + FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA \ + | grep -E '^(api-server|state-manager)/.*\.py$' || true) + echo "files=$FILES" >> $GITHUB_OUTPUT + + # 4. Run Ruff on changed files, if any - name: Run Ruff on changed files if: steps.changed-files.outputs.files != '' run: | - echo "Linting the following files:" + echo "Linting the following Python files:" echo "${{ steps.changed-files.outputs.files }}" ruff check ${{ steps.changed-files.outputs.files }} + # 5. Skip Ruff when no relevant files changed - name: Skip Ruff if no files changed if: steps.changed-files.outputs.files == '' - run: echo "No Python files changed in target folders. Skipping Ruff." + run: | + echo "No Python files changed in api-server/ or state-manager/. Skipping Ruff." From 6df06c384771c736bf2f75bc1b6bc4c000911665 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 00:32:02 +0530 Subject: [PATCH 04/14] test --- api-server/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-server/run.py b/api-server/run.py index dd33b831..a69dcdc8 100644 --- a/api-server/run.py +++ b/api-server/run.py @@ -18,7 +18,7 @@ def serve(): print(f"Running with {workers} workers") uvicorn.run("app.main:app", workers=workers, host="0.0.0.0", port=8000) else: - raise ValueError(f"Invalid mode provided: {mode}") + raise ValueError(f"Invalid mode: {mode}") if __name__ == "__main__": serve() From 9b6a998e9f8c029c358c68fd9e4b3c89e44541b4 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 00:42:06 +0530 Subject: [PATCH 05/14] workflow error fixed --- .github/workflows/ruff-check.yml | 6 +++++- api-server/run.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruff-check.yml b/.github/workflows/ruff-check.yml index 3b3e44a1..8a27c845 100644 --- a/.github/workflows/ruff-check.yml +++ b/.github/workflows/ruff-check.yml @@ -45,10 +45,14 @@ jobs: echo "files=$FILES" >> $GITHUB_OUTPUT - # 4. Run Ruff on changed files, if any + + + + # 4. Install and Run Ruff on changed files, if any - name: Run Ruff on changed files if: steps.changed-files.outputs.files != '' run: | + pip install ruff echo "Linting the following Python files:" echo "${{ steps.changed-files.outputs.files }}" ruff check ${{ steps.changed-files.outputs.files }} diff --git a/api-server/run.py b/api-server/run.py index a69dcdc8..dd33b831 100644 --- a/api-server/run.py +++ b/api-server/run.py @@ -18,7 +18,7 @@ def serve(): print(f"Running with {workers} workers") uvicorn.run("app.main:app", workers=workers, host="0.0.0.0", port=8000) else: - raise ValueError(f"Invalid mode: {mode}") + raise ValueError(f"Invalid mode provided: {mode}") if __name__ == "__main__": serve() From db21b52a897f4666910c2185b0465dab36d95cfe Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 00:50:34 +0530 Subject: [PATCH 06/14] error fixed --- .github/workflows/ruff-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruff-check.yml b/.github/workflows/ruff-check.yml index 8a27c845..104738a9 100644 --- a/.github/workflows/ruff-check.yml +++ b/.github/workflows/ruff-check.yml @@ -43,7 +43,7 @@ jobs: FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA \ | grep -E '^(api-server|state-manager)/.*\.py$' || true) - echo "files=$FILES" >> $GITHUB_OUTPUT + echo "files=$FILES" >> "$GITHUB_OUTPUT" From b4466c6f07a6191513ef99a6f2e85108bbb6a435 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 00:52:49 +0530 Subject: [PATCH 07/14] final check --- api-server/run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api-server/run.py b/api-server/run.py index dd33b831..a69dcdc8 100644 --- a/api-server/run.py +++ b/api-server/run.py @@ -18,7 +18,7 @@ def serve(): print(f"Running with {workers} workers") uvicorn.run("app.main:app", workers=workers, host="0.0.0.0", port=8000) else: - raise ValueError(f"Invalid mode provided: {mode}") + raise ValueError(f"Invalid mode: {mode}") if __name__ == "__main__": serve() From 11447f8a060188187f728ba8a518ec6e221c4bda Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 10:50:56 +0530 Subject: [PATCH 08/14] test for ruff-check on non py files --- api-server/.dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/api-server/.dockerignore b/api-server/.dockerignore index ba4cefd6..44c06c22 100644 --- a/api-server/.dockerignore +++ b/api-server/.dockerignore @@ -14,6 +14,7 @@ __pycache__/ .venv/ # Git, CI and editor config + .git/ .github/ .vscode/ From 55cb3ffd149248112ea7b2ccb1e7d4bd79d0ef4c Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 10:53:02 +0530 Subject: [PATCH 09/14] check for a py file --- api-server/.dockerignore | 1 - api-server/app/main.py | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/api-server/.dockerignore b/api-server/.dockerignore index 44c06c22..ba4cefd6 100644 --- a/api-server/.dockerignore +++ b/api-server/.dockerignore @@ -14,7 +14,6 @@ __pycache__/ .venv/ # Git, CI and editor config - .git/ .github/ .vscode/ diff --git a/api-server/app/main.py b/api-server/app/main.py index 08a909fa..6a6475f4 100644 --- a/api-server/app/main.py +++ b/api-server/app/main.py @@ -1,6 +1,7 @@ """ main file for exosphere apis """ + import os from beanie import init_beanie from fastapi import FastAPI From 0d3d563760fe03aac527c111758b3e2242a6e20e Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 10:58:33 +0530 Subject: [PATCH 10/14] all pyhton files instead of just api-server and state-managerment --- .github/workflows/ruff-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ruff-check.yml b/.github/workflows/ruff-check.yml index 104738a9..b29db160 100644 --- a/.github/workflows/ruff-check.yml +++ b/.github/workflows/ruff-check.yml @@ -27,7 +27,7 @@ jobs: with: python-version: '3.12' - # 3. Determine changed Python files in api-server/ and state-manager/ + # 3. Determine changed Python files - name: Get changed Python files id: changed-files run: | @@ -41,7 +41,7 @@ jobs: # List all changed .py files in target directories FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA \ - | grep -E '^(api-server|state-manager)/.*\.py$' || true) + | grep -E '\.py$' || true) echo "files=$FILES" >> "$GITHUB_OUTPUT" From ad94753840945e9935a2c5550c229b9698110d72 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 11:00:42 +0530 Subject: [PATCH 11/14] test check for all changed py files --- python-sdk/exospherehost/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-sdk/exospherehost/__init__.py b/python-sdk/exospherehost/__init__.py index 73a44e0c..dbeb0005 100644 --- a/python-sdk/exospherehost/__init__.py +++ b/python-sdk/exospherehost/__init__.py @@ -1,4 +1,4 @@ -from ._version import VERSION +from ._version import VERSION __version__ = VERSION From eca58d1bc48437df21082865421013b91af9f414 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 11:10:28 +0530 Subject: [PATCH 12/14] will check for all py files --- .github/workflows/ruff-check.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/ruff-check.yml b/.github/workflows/ruff-check.yml index 0c581f69..b29db160 100644 --- a/.github/workflows/ruff-check.yml +++ b/.github/workflows/ruff-check.yml @@ -27,9 +27,7 @@ jobs: with: python-version: '3.12' - # 3. Determine changed Python files - - name: Get changed Python files id: changed-files run: | @@ -43,8 +41,7 @@ jobs: # List all changed .py files in target directories FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA \ - - | grep -E '^(api-server|state-manager)/.*\.py$' || true) + | grep -E '\.py$' || true) echo "files=$FILES" >> "$GITHUB_OUTPUT" From d32da27883bea56eeae36573494d119f0fd74f61 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Wed, 30 Jul 2025 11:35:44 +0530 Subject: [PATCH 13/14] fixed init --- python-sdk/exospherehost/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python-sdk/exospherehost/__init__.py b/python-sdk/exospherehost/__init__.py index dbeb0005..73a44e0c 100644 --- a/python-sdk/exospherehost/__init__.py +++ b/python-sdk/exospherehost/__init__.py @@ -1,4 +1,4 @@ -from ._version import VERSION +from ._version import VERSION __version__ = VERSION From 4012cc700b33accc9f49c3b732cf521c395c2f65 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Thu, 31 Jul 2025 18:51:23 +0530 Subject: [PATCH 14/14] heredoc syntac used for multipline output --- .github/workflows/ruff-check.yml | 48 +++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ruff-check.yml b/.github/workflows/ruff-check.yml index b29db160..3bc0ff63 100644 --- a/.github/workflows/ruff-check.yml +++ b/.github/workflows/ruff-check.yml @@ -13,52 +13,66 @@ permissions: jobs: ruff-changed-files: runs-on: ubuntu-latest - + steps: # 1. Checkout entire history for accurate diffs - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - + # 2. Set up Python for Ruff - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' - + # 3. Determine changed Python files - name: Get changed Python files id: changed-files run: | if [[ "${{ github.event_name }}" == "pull_request" ]]; then BASE_SHA=${{ github.event.pull_request.base.sha }} - HEAD_SHA=${{ github.sha }} + HEAD_SHA=${{ github.event.pull_request.head.sha }} else BASE_SHA=${{ github.event.before }} - HEAD_SHA=${{ github.event.after }} + HEAD_SHA=${{ github.sha }} fi - - # List all changed .py files in target directories + + echo "BASE_SHA: $BASE_SHA" + echo "HEAD_SHA: $HEAD_SHA" + + # List all changed .py files FILES=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA $HEAD_SHA \ | grep -E '\.py$' || true) - - echo "files=$FILES" >> "$GITHUB_OUTPUT" - + + # Handle multi-line output properly for GitHub Actions + if [ -n "$FILES" ]; then + { + echo 'files<> "$GITHUB_OUTPUT" + echo "has_files=true" >> "$GITHUB_OUTPUT" + else + echo "files=" >> "$GITHUB_OUTPUT" + echo "has_files=false" >> "$GITHUB_OUTPUT" + fi - - # 4. Install and Run Ruff on changed files, if any - name: Run Ruff on changed files - if: steps.changed-files.outputs.files != '' + if: steps.changed-files.outputs.has_files == 'true' run: | pip install ruff echo "Linting the following Python files:" echo "${{ steps.changed-files.outputs.files }}" - ruff check ${{ steps.changed-files.outputs.files }} - + + # Convert multiline string to space-separated for ruff + FILES_ARGS=$(echo "${{ steps.changed-files.outputs.files }}" | tr '\n' ' ') + ruff check $FILES_ARGS + # 5. Skip Ruff when no relevant files changed - name: Skip Ruff if no files changed - if: steps.changed-files.outputs.files == '' + if: steps.changed-files.outputs.has_files == 'false' run: | - echo "No Python files changed in api-server/ or state-manager/. Skipping Ruff." + echo "No Python files changed. Skipping Ruff." \ No newline at end of file