aboutsummaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: 00e8712d928e595456c226a0f13ab5f54bdc6f2a (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
image: studip/studip:tests

variables:
  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
  # Optimize caching
  FF_USE_FASTZIP: "true"
  CACHE_COMPRESSION_LEVEL: "fast"
  # User faster docker driver
  DOCKER_DRIVER: overlay2

stages:
  - checks
  - tests
  - packaging
  - release
  - build

.scripts:
  install-composer:
    - make composer-dev
  configure-studip:
    - !reference [.scripts, 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:
    - !reference [.scripts, configure-studip]
    - chmod +x .gitlab/scripts/install_db.sh
    - .gitlab/scripts/install_db.sh
    - cli/studip migrate
  remove-absolute-path-in-report:
    - sed -i "s%$PWD/%%" tests/_output/report.xml

.artifacts:
  common: &common-artifacts
    when: always
    expire_in: 1 week
  tests: &test-artifacts
    <<: *common-artifacts
    paths:
      - tests/_output
    reports:
      junit: tests/_output/report.xml

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

lint-php:
  stage: checks
  needs: []
  cache: *composer-cache
  allow_failure: false
  interruptible: true
  before_script:
    - !reference [.scripts, install-composer]
    - mkdir -p .reports
  script:
    - php -d memory_limit=-1 composer/bin/phplint --xml .reports/phplint-report.xml --cache=.caches/phplint-cache
  artifacts:
    <<: *common-artifacts
    paths:
      - .reports/phplint-report.xml
    reports:
      junit: .reports/phplint-report.xml

lint-js:
  stage: checks
  needs: []
  cache: *npm-cache
  allow_failure: false
  interruptible: true
  before_script:
    - make npm
  script:
    - npm run lint -- --cache --cache-location .caches/eslint-cache --format ./node_modules/eslint-junit/index.js
  only:
    changes:
      - resources/assets/javascripts/**/*
      - resources/vue/**/*
  artifacts:
    <<: *common-artifacts
    paths:
      - .reports/eslint-report.xml
    reports:
       junit: .reports/eslint-report.xml

lint-css:
  stage: checks
  needs: []
  cache: *npm-cache
  allow_failure: false
  interruptible: true
  before_script:
    - make npm
  script:
    - npm run css-lint -s -- --cache --cache-location .caches/stylelint-cache --custom-formatter node_modules/stylelint-junit-formatter --output-file .reports/stylelint-report.xml
  only:
    changes:
      - resources/assets/stylesheets/**/*
  artifacts:
    <<: *common-artifacts
    paths:
      - .reports/stylelint-report.xml
    reports:
      junit: .reports/stylelint-report.xml

test-unit:
  stage: tests
  needs: [lint-php]
  cache:
    <<: *composer-cache
    policy: pull
  allow_failure: false
  interruptible: true
  before_script:
    - !reference [.scripts, configure-studip]
  script:
    - composer/bin/codecept run unit --xml
    - !reference [.scripts, remove-absolute-path-in-report]
  artifacts:
    <<: *test-artifacts

test-functional:
  stage: tests
  needs: [lint-php]
  cache:
    <<: *composer-cache
    policy: pull
  services:
    - mariadb
  allow_failure: false
  interruptible: true
  before_script:
    - !reference [.scripts, initialize-studip-database]
  script:
    - composer/bin/codecept run functional --xml
    - !reference [.scripts, remove-absolute-path-in-report]
  artifacts:
   <<: *test-artifacts

test-jsonapi:
  stage: tests
  needs: [lint-php]
  cache:
    <<: *composer-cache
    policy: pull
  services:
    - mariadb
  allow_failure: false
  interruptible: true
  before_script:
    - !reference [.scripts, initialize-studip-database]
  script:
    - composer/bin/codecept run jsonapi --xml
    - !reference [.scripts, remove-absolute-path-in-report]
  artifacts:
    <<: *test-artifacts
    when: always
    expire_in: 1 week
    paths:
      - tests/_output
    reports:
      junit: tests/_output/report.xml

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-release-$CI_COMMIT_TAG.zip *
    - tar -czf .pkg/studip-release-$CI_COMMIT_TAG.tar.gz *
  artifacts:
    untracked: true
    name: 'Stud.IP-Release-$CI_COMMIT_TAG'
    paths:
      - .pkg/studip-release.zip
      - .pkg/studip-release.tar.gz
    reports:
      dotenv: .packaging.env

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: "Stud.IP-Release-$CI_COMMIT_TAG"
    description: "Created using the release"
    tag_name: "$CI_COMMIT_TAG"
    assets:
      links:
        - name: "Stud.IP-Release-$CI_COMMIT_TAG.zip"
          url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${GE_JOB_ID}/artifacts/.pkg/studip-release-$CI_COMMIT_TAG.zip"
          link_type: package
        - name: "Stud.IP-Release-$CI_COMMIT_TAG.tar.gz"
          url: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/jobs/${GE_JOB_ID}/artifacts/.pkg/studip-release-$CI_COMMIT_TAG.tar.gz"
          link_type: package