From 4ce96df772a035bcb40ca8f52d48f33d2795f04f Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 15 Mar 2025 02:07:43 +0000 Subject: [PATCH] [workflows]: Only run tests and deploy if Python files changed --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4475779..fe56a79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,31 @@ on: - main jobs: + check_python_changes: + runs-on: ubuntu-latest + outputs: + run_tests: ${{ steps.check_files.outputs.run_tests }} + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Check if Python files changed + id: check_files + run: | + git fetch origin ${{ github.event.before }} + if git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep -q '\.py$'; then + echo "Python files changed" + echo "run_tests=true" >> $GITHUB_ENV + echo "::set-output name=run_tests::true" + else + echo "No Python files changed, skipping tests" + echo "run_tests=false" >> $GITHUB_ENV + echo "::set-output name=run_tests::false" + test: + needs: check_python_changes + if: needs.check_python_changes.outputs.run_tests == 'true' runs-on: ubuntu-latest strategy: @@ -30,14 +54,6 @@ jobs: python -m pip install --upgrade pip pip install -r server/src/requirements.txt - - name: Configure AWS Credentials for Tests - run: | - echo "Setting AWS region and mock credentials..." - export AWS_REGION=us-east-1 - export AWS_ACCESS_KEY_ID=fake_access_key - export AWS_SECRET_ACCESS_KEY=fake_secret_key - export AWS_DEFAULT_REGION=us-east-1 - - name: Run tests with coverage run: | export PYTHONPATH=$(pwd)/server/src @@ -60,11 +76,10 @@ jobs: - name: Show coverage summary run: cat coverage.xml - deploy: - needs: test # Ensures deployment happens only if tests pass + needs: test + if: success() || needs.check_python_changes.outputs.run_tests == 'false' # Deploy if tests pass OR no Python changes runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' # Deploy only from main branch strategy: matrix: @@ -79,7 +94,6 @@ jobs: with: python-version: '3.13' - # ✅ Check if AWS CLI is installed and update it instead of reinstalling - name: Check AWS CLI version run: aws --version || echo "AWS CLI not found"