Merge pull request #4 from 0hAodha/cd
[workflows]: Download AWS CLI directly from Amazon
This commit is contained in:
27
.github/workflows/ci.yml
vendored
27
.github/workflows/ci.yml
vendored
@ -17,23 +17,19 @@ jobs:
|
|||||||
python-version: [3.13]
|
python-version: [3.13]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Checkout the code
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
# Set up Python
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v4
|
uses: actions/setup-python@v4
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
|
|
||||||
# Install dependencies
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
pip install -r server/src/requirements.txt
|
pip install -r server/src/requirements.txt
|
||||||
|
|
||||||
# Set AWS region and mock credentials
|
|
||||||
- name: Configure AWS Credentials for Tests
|
- name: Configure AWS Credentials for Tests
|
||||||
run: |
|
run: |
|
||||||
echo "Setting AWS region and mock credentials..."
|
echo "Setting AWS region and mock credentials..."
|
||||||
@ -42,13 +38,11 @@ jobs:
|
|||||||
export AWS_SECRET_ACCESS_KEY=fake_secret_key
|
export AWS_SECRET_ACCESS_KEY=fake_secret_key
|
||||||
export AWS_DEFAULT_REGION=us-east-1
|
export AWS_DEFAULT_REGION=us-east-1
|
||||||
|
|
||||||
# Run tests and generate coverage report
|
|
||||||
- name: Run tests with coverage
|
- name: Run tests with coverage
|
||||||
run: |
|
run: |
|
||||||
export PYTHONPATH=$(pwd)/server/src
|
export PYTHONPATH=$(pwd)/server/src
|
||||||
pytest --cov=src/functions --cov=server/src --cov-report=term-missing --cov-report=xml --cov-report=html
|
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)
|
- name: Upload coverage report (HTML)
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
@ -56,7 +50,6 @@ jobs:
|
|||||||
name: coverage-report-html
|
name: coverage-report-html
|
||||||
path: htmlcov/
|
path: htmlcov/
|
||||||
|
|
||||||
# Upload XML coverage report for CI tools
|
|
||||||
- name: Upload coverage report (XML)
|
- name: Upload coverage report (XML)
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
@ -64,12 +57,10 @@ jobs:
|
|||||||
name: coverage-report-xml
|
name: coverage-report-xml
|
||||||
path: coverage.xml
|
path: coverage.xml
|
||||||
|
|
||||||
# Show coverage summary in logs
|
|
||||||
- name: Show coverage summary
|
- name: Show coverage summary
|
||||||
run: cat coverage.xml
|
run: cat coverage.xml
|
||||||
|
|
||||||
|
|
||||||
# Step 2: Continuous Deployment (CD) - Deploy multiple AWS Lambda functions
|
|
||||||
deploy:
|
deploy:
|
||||||
needs: test # Ensures deployment happens only if tests pass
|
needs: test # Ensures deployment happens only if tests pass
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@ -88,33 +79,33 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
python-version: '3.13'
|
python-version: '3.13'
|
||||||
|
|
||||||
# Install AWS CLI manually
|
# ✅ Correct AWS CLI installation
|
||||||
- name: Install AWS CLI
|
- name: Install AWS CLI (Official AWS Method)
|
||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
|
||||||
sudo apt-get install -y awscli
|
unzip awscliv2.zip
|
||||||
|
sudo ./aws/install
|
||||||
|
|
||||||
|
- name: Verify AWS CLI installation
|
||||||
|
run: aws --version
|
||||||
|
|
||||||
# Configure AWS credentials
|
|
||||||
- name: Configure AWS CLI
|
- name: Configure AWS CLI
|
||||||
run: |
|
run: |
|
||||||
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
|
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 aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||||
aws configure set region ${{ secrets.AWS_REGION }}
|
aws configure set region ${{ secrets.AWS_REGION }}
|
||||||
|
|
||||||
# Install dependencies for Lambda function
|
- name: Install dependencies for Lambda function
|
||||||
- name: Install dependencies
|
|
||||||
run: |
|
run: |
|
||||||
mkdir -p package/
|
mkdir -p package/
|
||||||
pip install -r server/src/requirements.txt -t package/
|
pip install -r server/src/requirements.txt -t package/
|
||||||
cp -r package/* server/src/functions/${{ matrix.function_name }}/
|
cp -r package/* server/src/functions/${{ matrix.function_name }}/
|
||||||
|
|
||||||
# Zip each Lambda function separately
|
|
||||||
- name: Zip Lambda function
|
- name: Zip Lambda function
|
||||||
run: |
|
run: |
|
||||||
cd server/src/functions/${{ matrix.function_name }}/
|
cd server/src/functions/${{ matrix.function_name }}/
|
||||||
zip -r ../../../../${{ matrix.function_name }}.zip . -x "*.git*" "*tests*" "*.github*" "*README.md*" "requirements.txt"
|
zip -r ../../../../${{ matrix.function_name }}.zip . -x "*.git*" "*tests*" "*.github*" "*README.md*" "requirements.txt"
|
||||||
|
|
||||||
# Deploy Lambda function using AWS CLI
|
|
||||||
- name: Deploy to AWS Lambda
|
- name: Deploy to AWS Lambda
|
||||||
run: |
|
run: |
|
||||||
aws lambda update-function-code --function-name ${{ matrix.function_name }} --zip-file fileb://${{ matrix.function_name }}.zip
|
aws lambda update-function-code --function-name ${{ matrix.function_name }} --zip-file fileb://${{ matrix.function_name }}.zip
|
||||||
|
Reference in New Issue
Block a user