-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (134 loc) · 4.47 KB
/
main.yml
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: main
on:
pull_request:
branches:
- '*'
push:
branches:
- main
tags:
- '*'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install system deps
run: sudo apt-get update && sudo apt-get -y install gcc libkrb5-dev
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run linter
run: |
pip install ruff
ruff check .
- name: Run safety check
run: |
pip install safety
safety check -i 42240,66963,70612,65213
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
env:
POSTGRES_DB: portail_test
POSTGRES_USER: portail_dev_limited_rw
POSTGRES_PASSWORD: portail_psswd
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U testuser"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Cache Python packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install system deps
run: |
sudo apt-get update && sudo apt-get -y install gcc libkrb5-dev
sudo locale-gen fr_FR.utf8
sudo update-locale
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Set up Django environment variables and config
run: |
cp .conf/.test.env admin_cohort/.env
mkdir log
echo "DATABASE_URL=postgres://portail_dev_limited_rw:portail_psswd@localhost:5432/portail_test" >> $GITHUB_ENV
- name: Run Django migrations
run: |
python manage.py migrate
- name: Run tests
run: |
coverage run --source='.' --omit="*/test*","*/migrations/*" manage.py test
coverage xml --omit="*/test*","*/migrations/*" -o coverage.xml
coverage html --omit="*/test*","*/migrations/*" -d htmlcov
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
publish:
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Cache Python packages
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install system deps
run: sudo apt-get update && sudo apt-get -y install gcc libkrb5-dev
- name: Install dependencies
run: |
pip install -r requirements.txt
- name: Retrieve version
run: |
VERSION=$(head -n 20 ./admin_cohort/settings.py | grep VERSION | head -1 | awk -F'=' '{ print $2 }' | sed "s/[\"' ]//g")
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ github.ref == 'refs/heads/main' && format('aphpid/cohort360-backend:{0},aphpid/cohort360-backend:latest',env.VERSION) || format('aphpid/cohort360-backend:{0}',env.VERSION) }}