name: Continuous Integration / Continuous Deployment on: pull_request: branches: - main push: branches: - 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: matrix: python-version: [3.13] steps: - name: Checkout code uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r server/src/requirements.txt - name: Run tests with coverage run: | export PYTHONPATH=$(pwd)/server/src pytest --cov=src/functions --cov=server/src --cov-report=term-missing --cov-report=xml --cov-report=html - name: Upload coverage report (HTML) if: always() uses: actions/upload-artifact@v4 with: name: coverage-report-html path: htmlcov/ - name: Upload coverage report (XML) if: always() uses: actions/upload-artifact@v4 with: name: coverage-report-xml path: coverage.xml - name: Show coverage summary run: cat coverage.xml deploy: needs: test if: success() || needs.check_python_changes.outputs.run_tests == 'false' # Deploy if tests pass OR no Python changes runs-on: ubuntu-latest strategy: matrix: function_name: [fetch_permanent_data, return_luas_data, return_station_data, fetch_transient_data, return_permanent_data, return_transient_data] steps: - name: Checkout repository uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.13' - name: Check AWS CLI version run: aws --version || echo "AWS CLI not found" - name: Update AWS CLI run: | curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" unzip -o awscliv2.zip sudo ./aws/install --update - name: Verify AWS CLI installation run: aws --version - name: Configure AWS CLI run: | aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws configure set region ${{ secrets.AWS_REGION }} - name: Install dependencies for Lambda function run: | mkdir -p package/ pip install -r server/src/requirements.txt -t package/ cp -r package/* server/src/functions/${{ matrix.function_name }}/ - name: Zip Lambda function run: | cd server/src/functions/${{ matrix.function_name }}/ zip -r ../../../../${{ matrix.function_name }}.zip . -x "*.git*" "*tests*" "*.github*" "*README.md*" "requirements.txt" - name: Deploy to AWS Lambda run: | aws lambda update-function-code --function-name ${{ matrix.function_name }} --zip-file fileb://${{ matrix.function_name }}.zip