From 82f604057015615cf788514c6078a8c69a848b4b Mon Sep 17 00:00:00 2001 From: Simon Desnoe <simon.desnoe@beebryte.com> Date: Wed, 6 Sep 2023 16:58:01 +0200 Subject: [PATCH] refactor: use python_install for depandabot --- .../depandabot/depandabot.yml | 80 +++++++++---------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/templates/python/dependancy_management/depandabot/depandabot.yml b/templates/python/dependancy_management/depandabot/depandabot.yml index ea6f75b..3f7576f 100644 --- a/templates/python/dependancy_management/depandabot/depandabot.yml +++ b/templates/python/dependancy_management/depandabot/depandabot.yml @@ -1,46 +1,44 @@ -depandabot: - stage: dependency_management - image: python:${IMAGE_TAG} - - variables: - PROJECT_PATH: "." - REQUIREMENTS_FILE_PATH: "${PROJECT_PATH}/requirements.txt" - IMAGE_TAG: "latest" - GITLAB_API_URL: "${CI_SERVER_HOST}" +include: + - remote: 'https://api.r2devops.io/job/r/gitlab/dorianturba/r2devops_catalog/r2_metadata/python_install@latest.yaml' - before_script: - - python --version ; pip --version # debugging - - python -m venv venv --upgrade-deps || python -m venv venv - - source venv/bin/activate - - pip install pip-tools +depandabot: + extends: + - .python_install + stage: build + image: python:${IMAGE_TAG} - script: - - DEPS_BRANCH="depandabot/requirements-txt/$(date +%s)" - - | - COMMIT_MESSAGE="build(deps): bump new versions" - - $([ -f ${REQUIREMENTS_FILE_PATH} ]) && ACTION="update" || ACTION="create" - - pip-compile --quiet -o ${REQUIREMENTS_FILE_PATH} - - if [ -n "$(git status --porcelain ${REQUIREMENTS_FILE_PATH})" ]; then - - | - curl --header "Authorization: Bearer ${DEPANDABOT_TOKEN}" \ - --form "branch=$DEPS_BRANCH" \ - --form "ref=${CI_DEFAULT_BRANCH}" \ - "https://${GITLAB_API_URL}/api/v4/projects/${CI_PROJECT_ID}/repository/branches" - - | - curl --header "Authorization: Bearer ${DEPANDABOT_TOKEN}" \ - --form "branch=$DEPS_BRANCH" \ - --form "commit_message=$COMMIT_MESSAGE" \ - --form "actions[][action]=$ACTION" \ - --form "actions[][file_path]=${REQUIREMENTS_FILE_PATH}" \ - --form "actions[][content]=<${REQUIREMENTS_FILE_PATH}" \ - "https://${GITLAB_API_URL}/api/v4/projects/${CI_PROJECT_ID}/repository/commits" - - | - curl --header "Authorization: Bearer ${DEPANDABOT_TOKEN}" \ - --form "source_branch=$DEPS_BRANCH" \ - --form "target_branch=${CI_DEFAULT_BRANCH}" \ - --form "title=$COMMIT_MESSAGE" \ - "https://${GITLAB_API_URL}/api/v4/projects/${CI_PROJECT_ID}/merge_requests" - - fi + variables: + PYTHON_SETUP: pip install pip-tools + GITLAB_API_URL: "${CI_SERVER_HOST}" + + script: + - !reference [.python_install, script] + - DEPS_BRANCH="depandabot/requirements-txt/$(date +%s)" + - | + COMMIT_MESSAGE="build(deps): bump new versions" + - $([ -f ${REQUIREMENTS_FILE_PATH} ]) && ACTION="update" || ACTION="create" + - pip-compile --quiet -o ${REQUIREMENTS_FILE_PATH} + - if [ -n "$(git status --porcelain ${REQUIREMENTS_FILE_PATH})" ]; then + - | + curl --header "Authorization: Bearer ${DEPANDABOT_TOKEN}" \ + --form "branch=$DEPS_BRANCH" \ + --form "ref=${CI_DEFAULT_BRANCH}" \ + "https://${GITLAB_API_URL}/api/v4/projects/${CI_PROJECT_ID}/repository/branches" + - | + curl --header "Authorization: Bearer ${DEPANDABOT_TOKEN}" \ + --form "branch=$DEPS_BRANCH" \ + --form "commit_message=$COMMIT_MESSAGE" \ + --form "actions[][action]=$ACTION" \ + --form "actions[][file_path]=${REQUIREMENTS_FILE_PATH}" \ + --form "actions[][content]=<${REQUIREMENTS_FILE_PATH}" \ + "https://${GITLAB_API_URL}/api/v4/projects/${CI_PROJECT_ID}/repository/commits" + - | + curl --header "Authorization: Bearer ${DEPANDABOT_TOKEN}" \ + --form "source_branch=$DEPS_BRANCH" \ + --form "target_branch=${CI_DEFAULT_BRANCH}" \ + --form "title=$COMMIT_MESSAGE" \ + "https://${GITLAB_API_URL}/api/v4/projects/${CI_PROJECT_ID}/merge_requests" + - fi -- GitLab