Skip to content
Snippets Groups Projects
.gitlab-ci.yml 12.8 KiB
Newer Older
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
image: studip/studip:tests-php8.3
variables:
  FF_NETWORK_PER_BUILD: 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"
  DOCKER_DRIVER: overlay2
  NODE_IMAGE: node:16-slim
  # Directories
  CACHE_DIR: .caches
  REPORT_DIR: .reports
  # Set npm cache directory
  npm_config_cache: $CI_PROJECT_DIR/.npm
  - analyse
  - packaging
  - release
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  mkdir-caches:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  mkdir-reports:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  install-composer:
    - make composer-dev
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  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
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  initialize-studip-database:
    - !reference [.scripts, configure-studip]
    - chmod +x .gitlab/scripts/install_db.sh
    - .gitlab/scripts/install_db.sh
    - cli/studip migrate
  composer: &composer-cache
    key:
      files:
        - composer.lock
    policy: pull
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  npm:
    key:
      files:
        - package-lock.json
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
.definitions:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  mariadb-service:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
   - name: mariadb
     command: [ "--sql_mode=","--character-set-client=utf8","--character-set-server=utf8","--collation-server=utf8_unicode_ci"]
  php-changed:
    - changes:
      - "**/*.php"
      - composer.lock
  css-changed:
    - changes:
      - "resources/assets/stylesheets/**/*"
      - package-lock.json
  js-changed:
    - changes:
      - "resources/assets/javascripts/**/*"
      - "resources/vue/**/*"
      - package-lock.json
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed

build-composer:
  stage: build
  needs: []
  rules:
    - !reference [.definitions, php-changed]
    -  when: manual
  interruptible: true
  variables:
    COMPOSER_CACHE: $CACHE_DIR/composer-cache
  before_script:
    - mkdir -p $COMPOSER_CACHE
  script:
    - composer install
  cache:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.caches, composer]
    - key: composer-package-cache
      paths:
        - $COMPOSER_CACHE
      policy: pull-push
  needs: [build-composer]
  rules:
    - !reference [.definitions, php-changed]
    CACHE_LOCATION: $CACHE_DIR/phplint-cache
    PHPLINT_JSON_REPORT: $REPORT_DIR/phplint-report.json
    PHPLINT_CODE_QUALITY_REPORT: $REPORT_DIR/phplint-codequality.json
  interruptible: true
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.caches, composer]
    - key: "$CI_JOB_NAME_SLUG:$CI_COMMIT_REF_SLUG"
      paths:
        - $CACHE_LOCATION
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-caches]
    - !reference [.scripts, mkdir-reports]
    - !reference [.scripts, install-composer]
  script:
    - COMPOSER_MEMORY_LIMIT=-1
      composer exec phplint
      --
      --cache=$CACHE_LOCATION
  after_script:
    - ./.gitlab/scripts/convert-phplint-report $PHPLINT_JSON_REPORT > $PHPLINT_CODE_QUALITY_REPORT
  artifacts:
    reports:
      codequality: $PHPLINT_CODE_QUALITY_REPORT
lint-php-7.4:
  image: studip/studip:tests-php8.2
  stage: checks
  needs: [build-composer]
  rules:
    - !reference [.definitions, php-changed]
  variables:
    CACHE_LOCATION: $CACHE_DIR/phplint-cache
    PHPLINT_JSON_REPORT: $REPORT_DIR/phplint-report-7.4.json
    PHPLINT_CODE_QUALITY_REPORT: $REPORT_DIR/phplint-codequality-7.4.json
  interruptible: true
  cache:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.caches, composer]
    - key: "$CI_JOB_NAME_SLUG:$CI_COMMIT_REF_SLUG"
      paths:
        - $CACHE_LOCATION
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-caches]
    - !reference [.scripts, mkdir-reports]
    - !reference [.scripts, install-composer]
  script:
    - COMPOSER_MEMORY_LIMIT=-1
      composer exec phplint
      --
      --json $PHPLINT_JSON_REPORT
      --cache=$CACHE_LOCATION
  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: []
  rules:
    - !reference [.definitions, js-changed]
    CACHE_LOCATION: $CACHE_DIR/eslint-cache
    ESLINT_CODE_QUALITY_REPORT: $REPORT_DIR/eslint-codequality.json
  cache:
    - key: "$CI_JOB_NAME_SLUG:$CI_COMMIT_REF_SLUG"
      paths:
        - $CACHE_LOCATION
  interruptible: true
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-reports]
    - npm install -g npm@7
    - npm install
      --no-save --no-audit --no-fund
      --loglevel=error
      eslint eslint-formatter-gitlab
      --cache --cache-location $CACHE_LOCATION
      --format gitlab
      resources/assets/javascripts resources/vue
      codequality: $ESLINT_CODE_QUALITY_REPORT
  rules:
    - !reference [.definitions, css-changed]
    CACHE_LOCATION: $CACHE_DIR/stylelint-cache
    STYLELINT_CODE_QUALITY_REPORT: $REPORT_DIR/stylelint-codequality.json
  cache:
    - key: "$CI_JOB_NAME_SLUG:CI_COMMIT_REF_SLUG"
      paths:
        - $CACHE_LOCATION
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, 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
      --cache --cache-location $CACHE_LOCATION
      --custom-formatter=node_modules/stylelint-formatter-gitlab 
      --output-file $STYLELINT_CODE_QUALITY_REPORT
      codequality: $STYLELINT_CODE_QUALITY_REPORT
phpstan:
  stage: analyse
  needs: [build-composer]
    CACHE_LOCATION: $CACHE_DIR/phpstan
    PHPSTAN_CODE_QUALITY_REPORT: $REPORT_DIR/phpstan-codequality.json
  allow_failure: true
  interruptible: true
  when: manual
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
   - !reference [.caches, composer]
   - key: "$CO_JOB_NAME_SLUG:$CI_COMMIT_REF_SLUG"
     paths:
       - $CACHE_LOCATION
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-caches]
    - !reference [.scripts, mkdir-reports]
    - !reference [.scripts, install-composer]
    - 'echo "includes:\n    - phpstan.neon.dist\n\nparameters:\n   tmpDir: $PHPSTAN_CACHE_PATH" > phpstan.neon'
  script:
    - php
      composer/bin/phpstan analyse 
      --memory-limit=1G 
      --no-progress 
      --level=$PHPSTAN_LEVEL
      --error-format=gitlab > $PHPSTAN_CODE_QUALITY_REPORT
  after_script:
    - rm phpstan.neon
  artifacts:
    reports:
      codequality: $PHPSTAN_CODE_QUALITY_REPORT
  rules:
    - !reference [.definitions, php-changed]
  variables:
    PHPUNIT_XML_REPORT: $REPORT_DIR/phpunit-report.xml
    policy: pull
  allow_failure: false
  interruptible: true
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-reports]
    - !reference [.scripts, configure-studip]
    - 'composer/bin/codecept
      run unit
      --xml=$PHPUNIT_XML_REPORT
      -o "paths: output: ."'
  after_script:
    - sed -i "s%$PWD/%%" $PHPUNIT_XML_REPORT
    reports:
      junit: $PHPUNIT_XML_REPORT
test-jest:
  stage: test
  needs: [lint-js]
  rules:
    - !reference [.definitions, js-changed]
  variables:
    JS_TEST_REPORT: $REPORT_DIR/jest.xml
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  cache:
    - !reference [.caches, npm]
  interruptible: true
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-reports]
    - npm install
  script:
    - JEST_JUNIT_OUTPUT_FILE="$JS_TEST_REPORT" npx jest tests/jest/ --ci --reporters=default --reporters=jest-junit
  artifacts:
    reports:
      junit: $JS_TEST_REPORT

  rules:
    - !reference [.definitions, php-changed]
  variables:
    FUNCTIONAL_XML_REPORT: $REPORT_DIR/functional-report.xml
    FUNCTIONAL_CODE_QUALITY_REPORT: $REPORT_DIR/functional-codequality.json
    policy: pull
  services:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.definitions, mariadb-service]
  allow_failure: false
  interruptible: true
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-reports]
    - !reference [.scripts, 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
    reports:
      junit: $FUNCTIONAL_XML_REPORT
  rules:
    - !reference [.definitions, php-changed]
    policy: pull
  services:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.definitions, mariadb-service]
  variables:
    JSONAPI_XML_REPORT: $REPORT_DIR/jsonapi-report.xml
  interruptible: true
  before_script:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-reports]
    - !reference [.scripts, 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:
  rules:
    - !reference [.definitions, js-changed]
    - !reference [.definitions, css-changed]
    -  when: manual
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
  cache:
    - !reference [.caches, npm]
  interruptible: true
  before_script:
test-e2e:
  stage: test
  #  needs: [lint-css, lint-js, lint-php]
  image: mcr.microsoft.com/playwright:v1.33.0-jammy
  services:
    - name: mariadb
      command: ["--sql_mode="]
  variables:
    PHP_WEBSERVER_URL: localhost:65432
    E2E_REPORT: $REPORT_DIR/e2e.xml
  interruptible: true
  when: manual
  cache:
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.caches, composer]
    - !reference [.caches, npm]
  before_script:
    - mkdir ./bin
    - apt-get update
    - apt -y install software-properties-common
    - add-apt-repository ppa:ondrej/php
    - apt-get update
    - DEBIAN_FRONTEND=noninteractive
      apt-get -yq install
      make zip unzip mariadb-client
      php7.4 libapache2-mod-php7.4 php7.4-common php7.4-curl php7.4-mbstring
      php7.4-xmlrpc php7.4-mysql php7.4-gd php7.4-xml php7.4-intl php7.4-ldap
      php7.4-imagick php7.4-json php7.4-cli
    - echo "short_open_tag=On" >> /etc/php/7.4/php.ini
    - echo "short_open_tag=On" >> /etc/php/7.4/cli/php.ini
    - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    - php composer-setup.php  --install-dir=./bin --filename=composer
    - export PATH="./bin:$PATH"
    - php -r "unlink('composer-setup.php');"
Jan-Hendrik Willms's avatar
Jan-Hendrik Willms committed
    - !reference [.scripts, mkdir-reports]
    - !reference [.scripts, initialize-studip-database]
    - ./cli/studip config:set SHOW_TERMS_ON_FIRST_LOGIN 0
    - npm install playwright
    - npm ci
    - npx playwright install --with-deps
  script:
    - php -S $PHP_WEBSERVER_URL -t public -q &
    - PHP_SERVER_PID=$!
    - PLAYWRIGHT_JUNIT_OUTPUT_NAME="$E2E_REPORT"
      PLAYWRIGHT_BASE_URL="http://$PHP_WEBSERVER_URL"
      npx playwright test --reporter=junit --grep-invert a11y
    - kill -3 $PHP_SERVER_PID
  artifacts:
    reports:
      junit: $E2E_REPORT

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
build_image:
  image: 
    name: gcr.io/kaniko-project/executor:debug
    entrypoint: [""]
  stage: build
  variables:
    IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
  script:
    - /kaniko/executor --context=dir://${CI_PROJECT_DIR} --dockerfile ${CI_PROJECT_DIR}/docker/studip/Dockerfile --destination ${IMAGE_TAG} --cache=true

release:
  stage: release
  image: studip/release-cli
  rules:
    - if: $CI_COMMIT_TAG
  script:
    - echo 'Running release job'
  needs:
      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"