aboutsummaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: abd8bf61a34728e097047c92757da6239a780c85 (plain)
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
image: studip/studip:tests-php7.2

variables:
  GIT_DEPTH: 1
  MYSQL_RANDOM_ROOT_PASSWORD: "true"
  MYSQL_DATABASE: studip_db
  MYSQL_USER: studip_user
  MYSQL_PASSWORD: studip_password
  MYSQL_HOST: mariadb
  DEMO_DATA: "true"
  MAIL_TRANSPORT: debug
  PHPSTAN_LEVEL: 0
  # Optimize caching
  FF_USE_FASTZIP: "true"
  CACHE_COMPRESSION_LEVEL: "fast"
  # Use faster docker driver
  DOCKER_DRIVER: overlay2
  # Images
  NODE_IMAGE: node:14-slim
  # Directories
  CACHE_DIR: .caches
  REPORT_DIR: .reports

stages:
  - checks
  - analyse
  - test
  - packaging
  - release
  - build

.scripts:
  mkdir-caches: &mkdir-caches
    - mkdir -p $CACHE_DIR
  mkdir-reports: &mkdir-reports
    - mkdir -p $REPORT_DIR
  install-composer: &install-composer
    - make composer-dev
  configure-studip: &configure-studip
    - *install-composer
    - cp docker/studip/config_local.php config/config_local.inc.php
    - cp config/config.inc.php.dist config/config.inc.php
  initialize-studip-database: &initialize-studip-database
    - *configure-studip
    - chmod +x .gitlab/scripts/install_db.sh
    - .gitlab/scripts/install_db.sh
    - cli/studip migrate

.caches:
  php: &composer-cache
    key: "php-$CI_COMMIT_REF_SLUG"
    paths:
      - composer/
      - $CACHE_DIR/phplint-cache
      - $CACHE_DIR/resultCache.php
      - $CACHE_DIR/cache/*
      - $CACHE_DIR/resultCaches/*
  js: &npm-cache
    key: "js-$CI_COMMIT_REF_SLUG"
    paths:
      - node_modules/
      - $CACHE_DIR/eslint-cache
      - $CACHE_DIR/stylelint-cache

lint-php:
  stage: checks
  needs: []
  cache: *composer-cache
  variables:
    PHPLINT_JSON_REPORT: $REPORT_DIR/phplint-report.json
    PHPLINT_CODE_QUALITY_REPORT: $REPORT_DIR/phplint-codequality.json
  interruptible: true
  before_script:
    - *mkdir-caches
    - *mkdir-reports
    - *install-composer
  script:
    - php -d memory_limit=-1
      composer/bin/phplint
      --json $PHPLINT_JSON_REPORT
      --cache=$CACHE_DIR/phplint-cache
  after_script:
    - ./.gitlab/scripts/convert-phplint-report $PHPLINT_JSON_REPORT > $PHPLINT_CODE_QUALITY_REPORT
  artifacts:
    reports:
      codequality: $PHPLINT_CODE_QUALITY_REPORT

lint-js:
  stage: checks
  needs: []
  image: $NODE_IMAGE
  variables:
    ESLINT_CODE_QUALITY_REPORT: $REPORT_DIR/eslint-codequality.json
  interruptible: true
  before_script:
    - *mkdir-reports
    - npm install
      --no-save --no-audit --no-fund
      --loglevel=error
      eslint eslint-formatter-gitlab
  script:
    - npx eslint
      --ext .js,.vue
      --format gitlab
      resources/assets/javascripts resources/vue
  artifacts:
    reports:
      codequality: $ESLINT_CODE_QUALITY_REPORT

lint-css:
  stage: checks
  needs: []
  image: $NODE_IMAGE
  variables:
    STYLELINT_CODE_QUALITY_REPORT: $REPORT_DIR/stylelint-codequality.json
  interruptible: true
  before_script:
    - *mkdir-reports
    - npm install
      --no-save --no-audit --no-fund
      --loglevel=error 
      stylelint@^14.9.1
      stylelint-config-standard@^26.0.0
      stylelint-formatter-gitlab
  script:
    - npx
      stylelint
      --custom-formatter=node_modules/stylelint-formatter-gitlab 
      resources/assets/stylesheets
  artifacts:
    reports:
      codequality: $STYLELINT_CODE_QUALITY_REPORT

phpstan:
  stage: analyse
  needs: [lint-php]
  variables:
    PHPSTAN_CODE_QUALITY_REPORT: $REPORT_DIR/phpstan-codequality.json
  allow_failure: true
  interruptible: true
  when: manual
  cache: *composer-cache
  before_script:
    - *mkdir-reports
    - *install-composer
  script:
    - php
      composer/bin/phpstan analyse 
      --memory-limit=1G 
      --no-progress 
      --level=$PHPSTAN_LEVEL
      --error-format=gitlab > $PHPSTAN_CODE_QUALITY_REPORT
  artifacts:
    reports:
      codequality: $PHPSTAN_CODE_QUALITY_REPORT

test-unit:
  stage: test
  needs: [lint-php]
  variables:
    PHPUNIT_XML_REPORT: $REPORT_DIR/phpunit-report.xml
  cache:
    <<: *composer-cache
    policy: pull
  allow_failure: false
  interruptible: true
  before_script:
    - *mkdir-reports
    - *configure-studip
  script:
    - 'composer/bin/codecept
      run unit
      --xml=$PHPUNIT_XML_REPORT
      -o "paths: output: ."'
  after_script:
    - sed -i "s%$PWD/%%" $PHPUNIT_XML_REPORT
  artifacts:
    reports:
      junit: $PHPUNIT_XML_REPORT

test-functional:
  stage: test
  needs: [lint-php]
  variables:
    FUNCTIONAL_XML_REPORT: $REPORT_DIR/functional-report.xml
    FUNCTIONAL_CODE_QUALITY_REPORT: $REPORT_DIR/functional-codequality.json
  cache:
    <<: *composer-cache
    policy: pull
  services:
    - mariadb
  allow_failure: false
  interruptible: true
  before_script:
    - *mkdir-reports
    - *initialize-studip-database
  script:
    - 'composer/bin/codecept
      run functional
      --xml=$FUNCTIONAL_XML_REPORT
      -o "paths: output: ."'
  after_script:
    - sed -i "s%$PWD/%%" $FUNCTIONAL_XML_REPORT
  artifacts:
    reports:
      junit: $FUNCTIONAL_XML_REPORT

test-jsonapi:
  stage: test
  needs: [lint-php]
  cache:
    <<: *composer-cache
    policy: pull
  services:
    - mariadb
  variables:
    JSONAPI_XML_REPORT: $REPORT_DIR/jsonapi-report.xml
  interruptible: true
  before_script:
    - *mkdir-reports
    - *initialize-studip-database
  script:
    - 'composer/bin/codecept
      run jsonapi
      --xml=$JSONAPI_XML_REPORT
      -o "paths: output: ."'
  after_script:
    - sed -i "s%$PWD/%%" $JSONAPI_XML_REPORT
  artifacts:
    reports:
      junit: $JSONAPI_XML_REPORT

test-assets:
  stage: test
  needs: []
  image: $NODE_IMAGE
  cache: *npm-cache
  interruptible: true
  before_script:
    - npm install
  script:
    - npm run webpack-dev

packaging:
  stage: packaging
  cache: []
  rules:
    - if: $CI_COMMIT_TAG
  before_script:
    - echo GE_JOB_ID=$CI_JOB_ID >> .packaging.env
    - mkdir .pkg
  script:
    - echo 'Running packaging job'
    - make build clean-npm
    - zip -r9 .pkg/studip-$CI_COMMIT_TAG.zip *
    - tar -czf .pkg/studip-$CI_COMMIT_TAG.tar.gz *
  artifacts:
    name: 'Stud.IP-Release-$CI_COMMIT_TAG'
    paths:
      - .pkg/studip-$CI_COMMIT_TAG.zip
      - .pkg/studip-$CI_COMMIT_TAG.tar.gz
    reports:
      dotenv: .packaging.env
    expire_in: never

release:
  stage: release
  image: studip/release-cli
  cache: []
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - echo 'Running release job'
  needs:
    - job: packaging
      artifacts: true
  release:
    name: "$CI_COMMIT_TAG"
    description: "https://gitlab.studip.de/studip/studip/-/blob/${CI_COMMIT_TAG}/ChangeLog"
    tag_name: "$CI_COMMIT_TAG"
    assets:
      links:
        - name: "studip-$CI_COMMIT_TAG.zip"
          url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${GE_JOB_ID}/artifacts/.pkg/studip-$CI_COMMIT_TAG.zip"
          link_type: package
        - name: "studip-$CI_COMMIT_TAG.tar.gz"
          url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${GE_JOB_ID}/artifacts/.pkg/studip-$CI_COMMIT_TAG.tar.gz"
          link_type: package