Skip to content
Snippets Groups Projects
.gitlab-ci.yml 7.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • nd's avatar
    nd committed
    image: registry.git.cccv.de/uffd/docker-images/buster
    
    nd's avatar
    nd committed
    
    variables:
      DEBIAN_FRONTEND: noninteractive 
    
      GIT_SUBMODULE_STRATEGY: normal
      PYTHONPATH: deps/ldapalchemy
    
      APT_API_URL: https://packages.cccv.de
      APT_REPO: uffd
    
      PYLINT_PIN: pylint~=2.10.0
    
    nd's avatar
    nd committed
    
    before_script:
      - python3 -V
    
    nd's avatar
    nd committed
      - lsb_release -a
    
    nd's avatar
    nd committed
      - uname -a
    
      - python3 -m pylint --version
      - python3 -m coverage --version
    
    nd's avatar
    nd committed
      - echo "${CI_COMMIT_TAG}" | grep -qE "v[0-9]+[.][0-9]+[.][0-9]+.*" && export UFFD_PACKAGE_VERSION="${CI_COMMIT_TAG#v}" || export UFFD_PACKAGE_VERSION="${CI_COMMIT_SHA}"
    
    
    nd's avatar
    nd committed
    .build:
    
    nd's avatar
    nd committed
      stage: build
    
    nd's avatar
    nd committed
    
    build:pip:
      extends: .build
    
    nd's avatar
    nd committed
      script:
      - PACKAGE_VERSION="${UFFD_PACKAGE_VERSION}" python3 -m build
      artifacts:
        paths:
          - dist/*
    
    build:apt:
    
    nd's avatar
    nd committed
      extends: .build
    
    nd's avatar
    nd committed
      script:
    
      - ./debian/create_changelog.py uffd > debian/changelog
      - export PYBUILD_INSTALL_ARGS="--install-lib=/usr/share/uffd/ --install-scripts=/usr/share/uffd/"
      - dpkg-buildpackage -us -uc
      - mv ../*.deb ./
      - dpkg-deb -I *.deb
      - dpkg-deb -c *.deb
    
    nd's avatar
    nd committed
      artifacts:
        paths:
    
    nd's avatar
    nd committed
    
    
    Julian's avatar
    Julian committed
    db_migrations_updated:
      stage: test
      script:
    
      - FLASK_APP=uffd FLASK_ENV=testing flask db upgrade
      - FLASK_APP=uffd FLASK_ENV=testing flask db migrate 2>&1 | grep -q 'No changes in schema detected'
    
    Julian's avatar
    Julian committed
    
    
    test_db_migrations:sqlite:
      stage: test
      script:
      - python3 check_migrations.py sqlite
    
    test_db_migrations:mysql:
      stage: test
      script:
      - service mysql start
      - python3 check_migrations.py mysql
    
    
    linter:buster:
      image: registry.git.cccv.de/uffd/docker-images/buster
    
    nd's avatar
    nd committed
      stage: test
      script:
    
      - pip3 install $PYLINT_PIN pylint-gitlab pylint-flask-sqlalchemy # this force-updates jinja2 and some other packages!
    
      - python3 -m pylint --exit-zero --rcfile .pylintrc --output-format=pylint_gitlab.GitlabCodeClimateReporter uffd > codeclimate.json
      - python3 -m pylint --exit-zero --rcfile .pylintrc --output-format=pylint_gitlab.GitlabPagesHtmlReporter uffd > pylint.html
      - python3 -m pylint --rcfile .pylintrc --output-format=text uffd
    
    nd's avatar
    nd committed
      artifacts:
    
        when: always
        paths:
        - pylint.html
        reports:
          codequality: codeclimate.json
    
    nd's avatar
    nd committed
    
    
    linter:bullseye:
      image: registry.git.cccv.de/uffd/docker-images/bullseye
      stage: test
      script:
    
      - pip3 install $PYLINT_PIN pylint-gitlab pylint-flask-sqlalchemy # this force-updates jinja2 and some other packages!
    
      - python3 -m pylint --exit-zero --rcfile .pylintrc --output-format=pylint_gitlab.GitlabCodeClimateReporter uffd > codeclimate.json
      - python3 -m pylint --exit-zero --rcfile .pylintrc --output-format=pylint_gitlab.GitlabPagesHtmlReporter uffd > pylint.html
      - python3 -m pylint --rcfile .pylintrc --output-format=text uffd
      artifacts:
        when: always
        paths:
        - pylint.html
        reports:
          codequality: codeclimate.json
    
    unittests:buster:
      image: registry.git.cccv.de/uffd/docker-images/buster
    
      - service slapd start
    
      - UNITTEST_OPENLDAP=1 python3-coverage run --include 'uffd/*.py' -m pytest --junitxml=report.xml || true
    
      - python3-coverage report -m
      - python3-coverage html
      - python3-coverage xml
      artifacts:
        when: always
        paths:
        - htmlcov/index.html
        - htmlcov
        expose_as: 'Coverage Report'
        reports:
          cobertura: coverage.xml
          junit: report.xml
      coverage: '/^TOTAL.*\s+(\d+\%)$/'
    
    
    unittests:bullseye:
      image: registry.git.cccv.de/uffd/docker-images/bullseye
      stage: test
      script:
      - service slapd start
      - UNITTEST_OPENLDAP=1 python3-coverage run --include 'uffd/*.py' -m pytest --junitxml=report.xml || true
      #- python3-coverage report -m
      - python3-coverage html
      #- python3-coverage xml
      artifacts:
        when: always
        paths:
        - htmlcov/index.html
        - htmlcov
        expose_as: 'Coverage Report'
        reports:
          #cobertura: coverage.xml
          junit: report.xml
      #coverage: '/^TOTAL.*\s+(\d+\%)$/'
    
    
    html5validator:
      stage: test
      script:
      - rm -rf pages
      - mkdir -p pages
      - cp -r uffd/static pages/static
      - DUMP_PAGES=pages python3 -m unittest discover tests
      - sed -i -e 's/href="\/static\//href=".\/static\//g' -e 's/src="\/static\//src=".\/static\//g' pages/*.html
      - html5validator --root pages 2>&1 | tee html5validator.log
      artifacts:
        when: on_failure
        paths:
        - pages
        - html5validator.log
    
    nd's avatar
    nd committed
    .trans:
    
    nd's avatar
    nd committed
      - ./update_translations.sh $TRANSLATION_LANGUAGE
    
    nd's avatar
    nd committed
      coverage: '/^TOTAL.*\s+(\d+\%)$/'
    
    nd's avatar
    nd committed
    
    
    nd's avatar
    nd committed
    trans_de:
      extends: .trans
      variables:
        TRANSLATION_LANGUAGE: de
    
    
    test:package:pip:buster:
      image: registry.git.cccv.de/uffd/docker-images/buster
      stage: test
      script:
      - pip3 install dist/*.tar.gz
      dependencies:
      - build:pip
    
    test:package:pip:bullseye:
      image: registry.git.cccv.de/uffd/docker-images/bullseye
    
      stage: test
      script:
      - pip3 install dist/*.tar.gz
      dependencies:
      - build:pip
    
    
    test:package:apt:buster:
      image: registry.git.cccv.de/uffd/docker-images/buster
      stage: test
      script:
    
      - apt -y install ./*.deb
    
      - service uwsgi start uffd || ( service uwsgi status uffd ; sleep 15; cat /var/log/uwsgi/app/uffd.log; )
      - echo "server { listen 127.0.0.1:5000 default_server;  include /etc/uffd/nginx.include.conf; }" > /etc/nginx/sites-enabled/uffd.ini
      - service nginx start || ( service nginx status; nginx -t; exit 1; )
      - uffd-admin routes
      - curl -Lv 127.0.0.1:5000
      dependencies:
      - build:apt
    
    test:package:apt:bullseye:
      image: registry.git.cccv.de/uffd/docker-images/bullseye
    
      - apt -y install ./*.deb
    
    nd's avatar
    nd committed
      - service uwsgi start uffd || ( service uwsgi status uffd ; sleep 15; cat /var/log/uwsgi/app/uffd.log; )
      - echo "server { listen 127.0.0.1:5000 default_server;  include /etc/uffd/nginx.include.conf; }" > /etc/nginx/sites-enabled/uffd.ini
      - service nginx start || ( service nginx status; nginx -t; exit 1; )
    
    nd's avatar
    nd committed
      - curl -Lv 127.0.0.1:5000
    
      dependencies:
      - build:apt
    
    
    nd's avatar
    nd committed
    .publish:
    
    nd's avatar
    nd committed
      stage: deploy
    
    nd's avatar
    nd committed
      rules:
        - if: '$CI_COMMIT_TAG =~ /v[0-9]+[.][0-9]+[.][0-9]+.*/'
    
    publish:pip:
      extends: .publish
    
    nd's avatar
    nd committed
      script:
      - TWINE_USERNAME="${GITLABPKGS_USERNAME}" TWINE_PASSWORD="${GITLABPKGS_PASSWORD}" python3 -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
      - TWINE_USERNAME="${PYPI_USERNAME}" TWINE_PASSWORD="${PYPI_PASSWORD}" python3 -m twine upload dist/*
    
    nd's avatar
    nd committed
      dependencies:
      - build:pip
    
    publish:apt:
    
    nd's avatar
    nd committed
      extends: .publish
    
    nd's avatar
    nd committed
      script:
    
      - export DEBPATH="$(echo *.deb)"
    
      - echo Upload deb file, add it to repo and clean up upload
      - curl --user "${APTLY_API_USER}:${APTLY_API_PW}" -X POST -F file=@"$DEBPATH" "${APT_API_URL}/api/files/${APT_REPO}-ci-upload-${CI_JOB_ID}"
      - curl --user "${APTLY_API_USER}:${APTLY_API_PW}" -X POST "${APT_API_URL}/api/repos/${APT_REPO}/file/${APT_REPO}-ci-upload-${CI_JOB_ID}"
      - curl --user "${APTLY_API_USER}:${APTLY_API_PW}" -X DELETE "${APT_API_URL}/api/files/${APT_REPO}-ci-upload-${CI_JOB_ID}"
      - echo Update published repo for all distros
      - 'curl --user "${APTLY_API_USER}:${APTLY_API_PW}" -X PUT -H "Content-Type: application/json" --data "{ }" "${APT_API_URL}/api/publish/uffd/buster"'
      - 'curl --user "${APTLY_API_USER}:${APTLY_API_PW}" -X PUT -H "Content-Type: application/json" --data "{ }" "${APT_API_URL}/api/publish/uffd/bullseye"'
    
    nd's avatar
    nd committed
      dependencies:
      - build:apt