name: Continuous Integration / Continuous Deployment on: pull_request: branches: - main push: branches: - main jobs: test: runs-on: ubuntu-latest strategy: matrix: python-version: [3.13] steps: # Checkout the code - name: Checkout code uses: actions/checkout@v3 # Set up Python - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} # Install dependencies - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r server/src/requirements.txt # Set AWS region and mock credentials - 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 # Run tests and generate coverage report - 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 # Upload coverage report as an artifact - name: Upload coverage report (HTML) if: always() uses: actions/upload-artifact@v4 with: name: coverage-report-html path: htmlcov/ # Upload XML coverage report for CI tools - name: Upload coverage report (XML) if: always() uses: actions/upload-artifact@v4 with: name: coverage-report-xml path: coverage.xml # Show coverage summary in logs - name: Show coverage summary run: cat coverage.xml # Step 2: Continuous Deployment (CD) - Deploy multiple AWS Lambda functions deploy: needs: test # Ensures deployment happens only if tests pass runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' # Deploy only from main branch strategy: matrix: function_name: [permanent_data, transient_data, return_all_data, return_newest_data, return_luas_data, return_station_data] steps: - name: Checkout repository uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.13.1' - name: Install dependencies run: | 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 uses: aws-actions/aws-cli-action@v1 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_REGION }} command: | aws lambda update-function-code --function-name ${{ matrix.function_name }} --zip-file fileb://${{ matrix.function_name }}.zip