From 64ed4186b3f3390226030e90b7a74f6b6d219ce8 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 29 Apr 2024 10:58:37 +0200 Subject: [PATCH] refactor --- cd.sh | 57 ++++++++++++++++++++++++--------------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/cd.sh b/cd.sh index 7a49275..fa39bf9 100644 --- a/cd.sh +++ b/cd.sh @@ -49,41 +49,30 @@ cd_set_environment () { exit 1 ;; esac - # project / branch - [ "${CI_COMMIT_BRANCH}" ] && CD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}" - [ "${GITHUB_REF_NAME}" ] && CD_PROJECT_BRANCH="${GITHUB_REF_NAME}" - if [ ! "${CD_PROJECT_BRANCH}" ] ; then - echo "CD_PROJECT_BRANCH" - exit 3 - fi - # project / name - [ "${CI_PROJECT_PATH}" ] \ - && CD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")" - [ "${GITHUB_REPOSITORY}" ] \ - && CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")" - if [ ! "${CD_PROJECT_NAME}" ] ; then - echo "CD_PROJECT_NAME" - exit 3 - fi - # projects / group - [ "${CI_PROJECT_PATH}" ] \ - && CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")" - [ "${GITHUB_REPOSITORY}" ] \ - && CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")" - if [ ! "${CD_PROJECTS_GROUP}" ] ; then - echo "CD_PROJECTS_GROUP" - exit 3 - fi - # projects / url - [ "${CI_SERVER_URL}" ] && CD_PROJECTS_URL="${CI_SERVER_URL}" - [ "${GITHUB_SERVER_URL}" ] && CD_PROJECTS_URL="${GITHUB_SERVER_URL}" - if [ "${CD_PROJECTS_URL}" ] ; then - CD_PROJECTS_URL="${CD_PROJECTS_URL}/${CD_PROJECTS_GROUP}" + # ci / github + if [ "${GITHUB_ACTIONS}" ] ; then + CD_SERVER_URL="${GITHUB_SERVER_URL}" + CD_PROJECT_BRANCH="${GITHUB_REF_NAME}" + CD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")" + CD_PROJECTS_GROUP="$(dirname "${GITHUB_REPOSITORY}")" + # ci / gitlab + elif [ "${GITLAB_CI}" ] ; then + CD_SERVER_URL="${CI_SERVER_URL}" + CD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}" + CD_PROJECT_NAME="$(basename "${CI_PROJECT_PATH}")" + CD_PROJECTS_GROUP="$(dirname "${CI_PROJECT_PATH}")" + # ci / none else - echo "CD_PROJECTS_URL" + echo "CI" exit 3 fi - # project / url + # + [ "${CD_SERVER_URL}" ] || echo "CD_SERVER_URL" && exit 3 + [ "${CD_PROJECT_BRANCH}" ] || echo "CD_PROJECT_BRANCH" && exit 3 + [ "${CD_PROJECT_NAME}" ] || echo "CD_PROJECT_NAME" && exit 3 + [ "${CD_PROJECTS_GROUP}" ] || echo "CD_PROJECTS_GROUP" && exit 3 + # + CD_PROJECTS_URL="${CD_SERVER_URL}/${CD_PROJECTS_GROUP}" CD_PROJECT_URL="${CD_PROJECTS_URL}/${CD_PROJECT_NAME}" # echo -n "\ @@ -95,11 +84,13 @@ CD_DNS_FILE=${CD_DNS_FILE} CD_PYTHON_COMMAND=${CD_PYTHON_COMMAND} CD_PYTHON_PACKAGES=${CD_PYTHON_PACKAGES} # +CD_SERVER_URL=${CD_SERVER_URL} CD_PROJECT_BRANCH=${CD_PROJECT_BRANCH} CD_PROJECT_NAME=${CD_PROJECT_NAME} -CD_PROJECT_URL=${CD_PROJECT_URL} CD_PROJECTS_GROUP=${CD_PROJECTS_GROUP} +# CD_PROJECTS_URL=${CD_PROJECTS_URL} +CD_PROJECT_URL=${CD_PROJECT_URL} " }