include: - project: emfollow/gitlab-ci-templates file: lint.yml - project: emfollow/gitlab-ci-templates file: sccb.yml - project: emfollow/gitlab-ci-templates file: ssh.yml variables: # Allow Celery to run as root, because everything runs as root under Docker. C_FORCE_ROOT: 'true' # Checking out the source is the exception rather than the rule because # most of our CI jobs run from tarballs or wheels or don't require the source # at all. GIT_STRATEGY: none .in-tmpdir: &in-tmpdir before_script: - WORKING_DIRECTORY="$(mktemp -d)" - cd "${WORKING_DIRECTORY}" after_script: - cd "${CI_PROJECT_DIR}" - rm -rf "${WORKING_DIRECTORY}" stages: - dist - test - deploy # Build source distribution sdist: image: python:slim stage: dist variables: GIT_STRATEGY: fetch before_script: # Versioneer will need access to the git tool. - apt-get -q update - apt-get -yq install --no-install-recommends git script: - python setup.py sdist - mv dist/* . artifacts: paths: - '*.tar.gz' # Build binary distribution bdist: image: python:slim stage: test <<: *in-tmpdir script: - tar --strip-components 1 -xf ${CI_PROJECT_DIR}/*.tar.* - python setup.py bdist_wheel --dist-dir ${CI_PROJECT_DIR} dependencies: - sdist artifacts: paths: - '*.whl' # Build Docker container for dependencies .dependencies: &dependencies stage: dist variables: GIT_STRATEGY: fetch IMAGE_TAG: $CI_REGISTRY_IMAGE/$CI_JOB_NAME:$CI_COMMIT_REF_NAME script: - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - | cat < Dockerfile FROM python:${CI_JOB_NAME#*python} COPY requirements.txt . RUN pip --no-cache-dir install -r requirements.txt RUN rm -f requirements.txt EOF - docker build -t $IMAGE_TAG . - docker push $IMAGE_TAG - if [ "${CI_COMMIT_TAG:0:1}" = "v" ]; then docker tag $IMAGE_TAG ${IMAGE_TAG%:*}:latest; docker push ${IMAGE_TAG%:*}:latest; fi only: changes: - requirements.txt dependencies/python3.7: <<: *dependencies dependencies/python3.8: <<: *dependencies # Run unit tests and coverage measurement .test: &test stage: test coverage: '/^TOTAL\s+.*\s+(\d+\.?\d*)%/' <<: *in-tmpdir script: - apt-get update -qq && apt-get install -y -qq redis-server - tar --strip-components 1 -xf ${CI_PROJECT_DIR}/*.tar.* - pip install pytest-cov - python setup.py test --addopts="-vv --cov --cov-report=html:${CI_PROJECT_DIR}/htmlcov --cov-report=term --junit-xml=${CI_PROJECT_DIR}/junit.xml" dependencies: - sdist artifacts: paths: - htmlcov/ reports: junit: junit.xml test/python3.7: image: $CI_REGISTRY_IMAGE/dependencies/python3.7:$CI_COMMIT_REF_NAME <<: *test test/python3.8: image: $CI_REGISTRY_IMAGE/dependencies/python3.8:$CI_COMMIT_REF_NAME <<: *test lint: image: $CI_REGISTRY_IMAGE/dependencies/python3.8:$CI_COMMIT_REF_NAME stage: test variables: GIT_STRATEGY: fetch dependencies: - sdist associate commits in Sentry: stage: test dependencies: - sdist variables: GIT_STRATEGY: fetch only: - master@emfollow/gwcelery - tags@emfollow/gwcelery image: name: getsentry/sentry-cli entrypoint: [""] script: - SENTRY_VERSION=$(echo *.tar.* | sed 's/\.tar\..*//') - sentry-cli releases new ${SENTRY_VERSION} - sentry-cli releases set-commits --auto ${SENTRY_VERSION} # Build docker container for application itself .docker: &docker stage: deploy script: - IMAGE_TAG=$CI_REGISTRY_IMAGE/${CI_JOB_NAME#*/}:$CI_COMMIT_REF_NAME - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY - | cat < Dockerfile FROM $CI_REGISTRY_IMAGE/dependencies/${CI_JOB_NAME#*/}:$CI_COMMIT_REF_NAME COPY *.whl . RUN pip install *.whl RUN rm -f *.whl USER nobody WORKDIR /tmp ENTRYPOINT ["gwcelery"] EOF - docker build -t $IMAGE_TAG . - docker push $IMAGE_TAG - if [ "${CI_COMMIT_TAG:0:1}" = "v" ]; then docker tag $IMAGE_TAG ${IMAGE_TAG%:*}:latest; docker push ${IMAGE_TAG%:*}:latest; fi dependencies: - bdist docker/python3.7: <<: *docker docker/python3.8: <<: *docker # Generate documentation doc: image: python:slim stage: test <<: *in-tmpdir script: - apt-get update -qq && apt-get install -y -qq graphviz - tar --strip-components 1 -xf ${CI_PROJECT_DIR}/*.tar.* - pip install -r docs-requirements.txt - python setup.py build_sphinx dependencies: - sdist # SCCB request sccb: stage: deploy # Publish coverage pages: stage: deploy script: - mv htmlcov public/ artifacts: paths: - public expire_in: 30 days only: - master dependencies: - test/python3.7 # Upload package to PyPI pypi: stage: deploy image: python:slim script: - pip install twine - twine upload *.tar.* *.whl dependencies: - sdist - bdist only: - tags@emfollow/gwcelery # Create a release in GitLab release: stage: deploy image: python variables: GIT_STRATEGY: fetch script: - PACKAGE_NAME="$(python setup.py --name)" - PACKAGE_VERSION="$(python setup.py --version)" - CHANGES_FILENAME="$(echo CHANGES.*)" - | tee json <