From 72e50dbc309388b6b84091d1d8b6b990cf14f96b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 15 Mar 2025 01:15:29 +0000 Subject: [PATCH] [workflows]: Add Continuous Deployment --- .github/workflows/ci.yml | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 141c75a..b903274 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Continuous Integration +name: Continuous Integration / Continuous Deployment on: pull_request: @@ -67,3 +67,42 @@ jobs: # 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