-
Mateusz Żebrak authoredMateusz Żebrak authored
python_projects.gitlab-ci.yml 8.97 KiB
include:
- local: templates/base.gitlab-ci.yml
variables:
PACKAGES_TO_CHECK: "" # required to set when using linter-specific job templates
PYPROJECT_CONFIG_PATH: "" # may be set when using linter-specific job templates
# tests:
PYTEST_NUMBER_OF_PROCESSES: "auto" # will use nproc to determine number of processes, override on specific project CI/job level
PYTEST_LOG_DURATIONS: 0 # do not log test durations by default
PYTEST_JUNIT_REPORT: "report.xml" # junit report location, used by GitLab
# registries:
# uses registry.gitlab.syncad.com/hive/hive/ci-base-image:ubuntu22.04-10
PYTHON_IMAGE_TAG: "@sha256:080b16fd53013aeb9b89b00a8dfc90fecf886173f46448b05f45cee376c43330"
PYTHON_IMAGE: "registry.gitlab.syncad.com/hive/hive/ci-base-image${PYTHON_IMAGE_TAG}"
# colors:
TXT_GREEN: "\e[1;32m"
TXT_BLUE: "\e[1;34m"
TXT_CLEAR: "\e[0m"
.configuration_template:
extends: .job-defaults
image: "${PYTHON_IMAGE}"
variables:
PYPROJECT_DIR: "$(pwd)"
before_script:
- poetry -C "${PYPROJECT_DIR}" env use python3 # create virtualenv if not exists
- source $(poetry -C "${PYPROJECT_DIR}" env info --path)/bin/activate # activate that virtualenv
- python3 -V
- poetry -C "${PYPROJECT_DIR}" -V
- pip list
.project_develop_configuration_template:
extends: .configuration_template
before_script:
- !reference [.configuration_template, before_script]
- poetry install
- pip list
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| STATIC CODE ANALYSIS |>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.pre_commit_checks_template:
extends: .project_develop_configuration_template
script:
- pushd . && cd /tmp && poetry self update && popd # Bump poetry version so `poetry lock --no-update` will use the latest one; doing it in different directory to avoid `poetry.lock` and `pyproject.toml` changes
- poetry -V
- echo -e "${TXT_BLUE}Checking all files with pre-commit hooks...${TXT_CLEAR}" &&
pre-commit run --all-files
artifacts:
when: always
expire_in: 1 week
paths:
- poetry.lock
.lint_code_with_ruff_template:
extends: .project_develop_configuration_template
script:
- if [ -z "${PYPROJECT_CONFIG_PATH}" ]; then MAYBE_EXPLICIT_CONFIG=""; else MAYBE_EXPLICIT_CONFIG="--config ${PYPROJECT_CONFIG_PATH}"; fi
- echo -e "${TXT_BLUE}Linting all sources with Ruff (check)...${TXT_CLEAR}" &&
ruff ${MAYBE_EXPLICIT_CONFIG} ${PACKAGES_TO_CHECK}
- echo -e "${TXT_BLUE}Linting all sources with Ruff (diff)...${TXT_CLEAR}" &&
ruff --diff ${MAYBE_EXPLICIT_CONFIG} ${PACKAGES_TO_CHECK}
.formatting_with_black_check_template:
extends: .project_develop_configuration_template
script: