-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (122 loc) · 3.9 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
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: Install UV
uses: astral-sh/setup-uv@v2
with:
version: "latest"
enable-cache: true
- name: Install Python 3.11
run: uv python install 3.11
- name: Run Ruff + Safety
run: |
uv tool run ruff check .
uv tool run 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: Install UV
uses: astral-sh/setup-uv@v4
with:
version: "latest"
enable-cache: true
- name: Install Python 3.11 and deps
run: uv python install 3.11
- 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: uv sync
- name: Set up log dir and DB config
run: |
mkdir log
echo "DATABASE_URL=postgres://portail_dev_limited_rw:portail_psswd@localhost:5432/portail_test" >> $GITHUB_ENV
- name: Run Django migrations
run: |
cp .conf/.test.env admin_cohort/.env
uv run python manage.py migrate
- name: Run tests
run: |
uv run coverage run --source='.' --omit="*/test*","*/migrations/*" manage.py test
uv run coverage xml --omit="*/test*","*/migrations/*" -o coverage.xml
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
sonar:
needs: test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v4
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: Retrieve version
run: |
VERSION=$(grep '^version =' pyproject.toml | sed -E 's/version = "(.*)"/\1/')
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
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) }}