-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
162 lines (150 loc) · 5 KB
/
.gitlab-ci.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
157
158
159
160
161
162
# This file is a template, and might need editing before it works on your project.
# This example is for testing Django with MySQL.
#
# The test CI/CD variables MYSQL_DB, MYSQL_USER and MYSQL_PASS can be set in the project settings at:
# Settings --> CI/CD --> Variables
#
# The Django settings in settings.py, used in tests, might look similar to:
#
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.mysql',
# 'NAME': os.environ.get('MYSQL_DATABASE'),
# 'USER': os.environ.get('MYSQL_USER'),
# 'PASSWORD': os.environ.get('MYSQL_PASSWORD'),
# 'HOST': 'mysql',
# 'PORT': '3306',
# 'CONN_MAX_AGE':60,
# },
# }
#
# It is possible to use '--settings' to specify a custom settings file on the command line below or use an environment
# variable to trigger an include on the bottom of your settings.py:
# if os.environ.get('DJANGO_CONFIG')=='test':
# from .settings_test import *
#
# It is also possible to hardcode the database name and credentials in the settings.py file and in the .gitlab-ci.yml file.
#
# The mysql service needs some variables too. See https://hub.docker.com/_/mysql for possible mysql env variables
# Note that when using a service in GitLab CI/CD that needs environment variables to run, only variables defined in
# .gitlab-ci.yml are passed to the service and variables defined in the GitLab UI are not.
# https://gitlab.com/gitlab-org/gitlab/-/issues/30178
# save minutes by select run from web
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
variables:
# DJANGO_CONFIG: "test"
PIP_CACHE_DIR: $CI_PROJECT_DIR/.cache/pip
DEV_DB_NAME: $DEV_DB_NAME
DEV_DB_USER: $DEV_DB_USER
DEV_DB_PASS: $DEV_DB_PASS
DEV_DB_HOST: $DEV_DB_HOST
DEV_DB_PORT: $DEV_DB_PORT
default:
# image: ubuntu:20.04
image: python:3.10
#
# Pick zero or more services to be used on all builds.
# Only needed when using a docker container to run your tests in.
# Check out: http://docs.gitlab.com/ee/ci/docker/using_docker_images.html#what-is-a-service
# services:
# - mysql:8.0
#
# This folder is cached between builds
# http://docs.gitlab.com/ee/ci/yaml/README.html#cache
cache:
paths:
# - ~/.cache/pip/
- .cache/pip
- venv/
before_script:
# - export DEBIAN_FRONTEND=noninteractive
# - cd ./DjangoWebProject1
# - cd ./DjangoWebProject1
# - apt -y update
# - apt -y install apt-utils
# - apt -y install net-tools python3.8-tk python3-pip mysql-client libmysqlclient-dev # mysql
# - apt -y install libpq-dev # postgres
# - apt -y upgrade
# - python3.8 -m pip install -r requirements.txt
- python -V # Print out python version for debugging
- pip install virtualenv
- virtualenv venv
- ls
- source venv/bin/activate
- ls
timeout: 5m
stages: # List of stages for jobs, and their order of execution
- build
- code
- test
- deploy
# migrations:
# stage: build
# script:
# - python3 manage.py makemigrations
# # - python3 manage.py makemigrations myapp
# - python3 manage.py migrate
# - python3 manage.py check
python-build:
stage: build
allow_failure: false
script:
# python3.8 --version
# python3.8 -m pip show flake
# python3.8 -m pip show django
- python --version
- python -m pip install -r requirements.txt
- python -m pip show django
- python -m pip show flake8
timeout: 5m
flake-check:
stage: code
allow_failure: true
script:
# - flake8
- python -m flake8
timeout: 5m
# django-tests:
# stage: test
# script:
# # The MYSQL user only gets permissions for MYSQL_DB, so Django can't create a test database.
# # - echo "GRANT ALL on *.* to '${MYSQL_USER}';"| mysql -u root --password="${MYSQL_ROOT_PASSWORD}" -h mysql
# # use python3 explicitly. see https://wiki.ubuntu.com/Python/3
# - python DjangoWebProject1/DjangoWebProject1/ manage.py test
# timeout: 10m
model-tests:
allow_failure: true
stage: test
variables:
TEST_NAME: $CI_JOB_NAME
script:
# The MYSQL user only gets permissions for MYSQL_DB, so Django can't create a test database.
# - echo "GRANT ALL on *.* to '${MYSQL_USER}';"| mysql -u root --password="${MYSQL_ROOT_PASSWORD}" -h mysql
# use python3 explicitly. see https://wiki.ubuntu.com/Python/3
- python manage.py test tests.test_models
timeout: 5m
permission-tests:
allow_failure: true
stage: test
variables:
TEST_NAME: $CI_JOB_NAME
script:
- python manage.py test tests.test_permission
timeout: 10m
browser-tests:
allow_failure: true
stage: test
variables:
TEST_NAME: $CI_JOB_NAME
script:
- python manage.py test tests.test_browser
timeout: 5m
deploy-check:
allow_failure: true
stage: deploy
script:
- python manage.py check --deploy
timeout: 5m