[workflows]: Only run tests and deploy if Python files changed
This commit is contained in:
38
.github/workflows/ci.yml
vendored
38
.github/workflows/ci.yml
vendored
@ -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"
|
||||
|
||||
|
Reference in New Issue
Block a user