From 8adacc5d76092bb30b293861f0864763b7b09978 Mon Sep 17 00:00:00 2001 From: bhaveshAswani112 Date: Tue, 29 Jul 2025 20:19:45 +0530 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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()