Fakultas Ilmu Komputer UI

.gitlab-ci1.yml 2.88 KB
Newer Older
Ryan Karyadiputera's avatar
test  
Ryan Karyadiputera committed
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
stages:
    - test
    - flake8
    - build
    - sonarqube
    - deploy
    
variables:
  PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"

image: python:latest

cache:
  key: test
  paths:
    - .cache/pip
    - venv/

before_script:
  - python3 -V
  - pip3 install virtualenv
  - virtualenv venv
  - source venv/bin/activate
  - pip3 install -r requirements.txt
  - echo "DJANGO_SECRET_KEY=$DJANGO_SECRET_KEY" > sip/settings/.env
  - echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> sip/settings/.env
  - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> sip/settings/.env
  - echo "AWS_STORAGE_BUCKET_NAME=$AWS_STORAGE_BUCKET_NAME" >> sip/settings/.env

dev-test:
  stage: test
  script:
    - python3 manage.py collectstatic --settings=sip.settings.staging --no-input
    - python3 manage.py makemigrations --settings=sip.settings.dev
    - python3 manage.py migrate --settings=sip.settings.dev
    - python3 manage.py test --settings=sip.settings.dev
  only:
    - development
    - /^.*PBI-.*$/

staging-test:
  stage: test
  script:
    - python3 manage.py collectstatic --settings=sip.settings.staging --no-input
    - python3 manage.py makemigrations --settings=sip.settings.staging
    - python3 manage.py migrate --settings=sip.settings.staging
    - python3 manage.py test --settings=sip.settings.staging
  only:
    - staging

lint:
  stage: flake8
  script:
    - flake8
  allow_failure: true
  except:
    - CI-CD

sonarqube:
  image: nuga99/sonar-scanner-python
  stage: sonarqube
  cache:
    key: sonarqube
    paths:
      - .cache/pip
  before_script:
    - python3 -V
    - pip3 install -r requirements.txt
    - echo "DJANGO_SECRET_KEY=$DJANGO_SECRET_KEY" > sip/settings/.env
    - echo "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" >> sip/settings/.env
    - echo "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" >> sip/settings/.env
    - echo "AWS_STORAGE_BUCKET_NAME=$AWS_STORAGE_BUCKET_NAME" >> sip/settings/.env
  script:
    - if [[ $CI_COMMIT_REF_NAME == staging ]]; then ENVIRON="sip.settings.staging"; else ENVIRON="sip.settings.dev"; fi
    - coverage run --omit='manage.py,**/venv/*,**/python3*/**,core/**,laporan_praktikum/error_message/**,laporan_praktikum/custom_module/**,authentication/cas_wrapper.py,/usr/**' manage.py test --settings=${ENVIRON}
    - coverage report -m
    - coverage xml -i
    - sonar-scanner
      -Dsonar.host.url=https://pmpl.cs.ui.ac.id/sonarqube
      -Dsonar.projectKey=$SONARQUBE_PROJECT_KEY
      -Dsonar.login=$SONARQUBE_TOKEN
      -Dsonar.branch.name=$CI_COMMIT_REF_NAME
  only:
    - master
    - staging
    - development
    - /^.*PBI-.*$/

heroku-deploy:
  image: ruby:2.4
  stage: deploy
  cache: {}
  before_script:
    - gem install dpl
    - wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
  script:
    - dpl --provider=heroku --app=$HEROKU_APPNAME --api-key=$HEROKU_APIKEY
    - export HEROKU_API_KEY=$HEROKU_APIKEY
  only:
    - staging
    - /^.*URGENT-.*$/