-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (85 loc) · 2.99 KB
/
CI_CD_pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: CI/CD Pipeline
run-name: Running CI/CD Pipeline
on: [push, pull_request]
permissions:
id-token: write
contents: read
jobs:
Run-Tests:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
strategy:
matrix:
# Run in all these versions of Python
python-version: [ "3.11" ]
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest
pip install pytest-django
pip install pytest-cov
- name: Run tests
run: |
python -m pytest \
--cov=core \
--cov=accounts \
--cov=stapi \
--cov-config=.coveragerc \
--cov-report=term > coverage.txt
env:
DJANGO_SETTINGS_MODULE: hydroserver.settings
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
- name: Parse coverage report
id: coverage
run: |
coverage=$(awk '/TOTAL/ {print $4}' coverage.txt | sed 's/%//')
if (( $(echo "$coverage < 50" | bc -l) )); then
echo "Test Coverage is below 50%: $coverage%"
exit 1
fi
echo "Test Coverage is $coverage%"
Deploy-Dev:
name: Deploy to AWS S3 Dev
needs: [Run-Tests]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/${{ vars.AWS_IAM_ROLE }}
role-session-name: deploy-hydroserver-dev
aws-region: ${{ vars.AWS_REGION }}
- name: Create deployment package
run: zip -r deploy_package.zip ./
- name: Upload deployment package to S3
run: aws s3 cp deploy_package.zip s3://${{ vars.AWS_DJANGO_DEV_BUCKET }}/deploy_package_${{ github.sha }}.zip
- name: Create ElasticBeanstalk Application Version
run: |
aws elasticbeanstalk create-application-version \
--application-name ${{ vars.AWS_DJANGO_DEV_NAME }} \
--source-bundle S3Bucket="${{ vars.AWS_DJANGO_DEV_BUCKET }}",S3Key="deploy_package_${{ github.sha }}.zip" \
--version-label "${{ github.sha }}" \
--description "commit-sha-${{ github.sha }}"
- name: Deploy ElasticBeanstalk Application Version
run: |
aws elasticbeanstalk update-environment \
--environment-name ${{ vars.AWS_DJANGO_DEV_NAME }}-env \
--version-label "${{ github.sha }}"