Compare commits
11 commits
4a2560d395
...
b2a882079a
Author | SHA1 | Date | |
---|---|---|---|
b2a882079a | |||
9a9f5b92d7 | |||
108c007872 | |||
88cb222ebe | |||
60f1a717c5 | |||
c031b07b0f | |||
1e1092235b | |||
6544d17f77 | |||
7de27df47b | |||
3922c14f69 | |||
0f7db5c612 |
1 changed files with 98 additions and 80 deletions
178
spcd.sh
178
spcd.sh
|
@ -1,6 +1,8 @@
|
|||
#! /usr/bin/env sh
|
||||
|
||||
# defaults
|
||||
[ -n "${SPCD_BRANCH_RELEASE}" ] || SPCD_BRANCH_RELEASE="main"
|
||||
[ -n "${SPCD_BRANCH_STAGING}" ] || SPCD_BRANCH_STAGING="dev"
|
||||
[ -n "${SPCD_DNS}" ] || SPCD_DNS="\
|
||||
9.9.9.9 \
|
||||
"
|
||||
|
@ -10,9 +12,10 @@
|
|||
# main
|
||||
spcd_main() {
|
||||
spcd_list_environment_variables
|
||||
spcd_set_environment_variables
|
||||
#
|
||||
spcd_list_working_directory
|
||||
#
|
||||
spcd_set_environment_variables
|
||||
spcd_set_packages_repositories
|
||||
spcd_set_packages_configuration
|
||||
#
|
||||
|
@ -38,7 +41,7 @@ spcd_main() {
|
|||
spcd_switch_to_python "${@}"
|
||||
}
|
||||
|
||||
# context
|
||||
# steps
|
||||
|
||||
spcd_list_environment_variables() {
|
||||
spcd_step "List environment variables"
|
||||
|
@ -49,16 +52,93 @@ spcd_list_environment_variables() {
|
|||
done
|
||||
}
|
||||
|
||||
spcd_list_working_directory() {
|
||||
spcd_step "List working directory"
|
||||
spcd_lwd__path="$(realpath .)"
|
||||
spcd_ls "${spcd_lwd__path}"
|
||||
}
|
||||
|
||||
# steps
|
||||
|
||||
spcd_set_environment_variables() {
|
||||
spcd_step "Set environment variables"
|
||||
# continuous integration / github → gitea → forgejo
|
||||
if [ -n "${GITHUB_ACTIONS}" ]; then
|
||||
# project branch
|
||||
if [ -n "${GITHUB_REF_NAME}" ]; then
|
||||
SPCD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
|
||||
else
|
||||
spcd_error_ci "GITHUB_REF_NAME"
|
||||
fi
|
||||
# project root
|
||||
if [ -n "${GITHUB_SERVER_URL}" ]; then
|
||||
SPCD_PROJECT_ROOT="$(dirname "${GITHUB_SERVER_URL}")//"
|
||||
[ -n "${GITHUB_TOKEN}" ] &&
|
||||
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}${GITHUB_TOKEN}@"
|
||||
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
|
||||
else
|
||||
spcd_error_ci "GITHUB_SERVER_URL"
|
||||
fi
|
||||
# project path & name
|
||||
if [ -n "${GITHUB_REPOSITORY}" ]; then
|
||||
# project path
|
||||
SPCD_PROJECT_PATH="$(dirname "${GITHUB_REPOSITORY}")"
|
||||
# project name
|
||||
SPCD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
|
||||
else
|
||||
spcd_error_ci "GITHUB_REPOSITORY"
|
||||
fi
|
||||
# continuous integration / gitlab
|
||||
elif [ -n "${GITLAB_CI}" ]; then
|
||||
# project branch
|
||||
if [ -n "${CI_COMMIT_BRANCH}" ]; then
|
||||
SPCD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
|
||||
else
|
||||
spcd_error_ci "CI_COMMIT_BRANCH"
|
||||
fi
|
||||
# project root / protocol
|
||||
if [ -n "${CI_SERVER_PROTOCOL}" ]; then
|
||||
# project root / login
|
||||
if [ -n "${CI_REGISTRY_USER}" ]; then
|
||||
# project root / password
|
||||
if [ -n "${CI_REGISTRY_PASSWORD}" ]; then
|
||||
# project root / host
|
||||
if [ -n "${CI_SERVER_FQDN}" ]; then
|
||||
# project root
|
||||
SPCD_PROJECT_ROOT="${CI_SERVER_PROTOCOL}\
|
||||
://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}"
|
||||
# project path
|
||||
if [ -n "${CI_PROJECT_NAMESPACE}" ]; then
|
||||
SPCD_PROJECT_PATH="${CI_PROJECT_NAMESPACE}"
|
||||
# project name
|
||||
if [ -n "${CI_PROJECT_NAME}" ]; then
|
||||
SPCD_PROJECT_NAME="${CI_PROJECT_NAME}"
|
||||
else
|
||||
spcd_error_ci "CI_PROJECT_NAME"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_PROJECT_NAMESPACE"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_SERVER_FQDN"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_REGISTRY_PASSWORD"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_REGISTRY_USER"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_SERVER_PROTOCOL"
|
||||
fi
|
||||
# continuous integration / unsupported
|
||||
else
|
||||
spcd_error_ci "ø"
|
||||
fi
|
||||
# check project variables
|
||||
case "${SPCD_PROJECT_BRANCH}" in
|
||||
"${SPCD_BRANCH_RELEASE}" | "${SPCD_BRANCH_STAGING}") ;;
|
||||
*) spcd_error_ci "SPCD_PROJECT_BRANCH" ;;
|
||||
esac
|
||||
[ -n "${SPCD_PROJECT_ROOT}" ] || spcd_error_ci "SPCD_PROJECT_ROOT"
|
||||
[ -n "${SPCD_PROJECT_PATH}" ] || spcd_error_ci "SPCD_PROJECT_PATH"
|
||||
[ -n "${SPCD_PROJECT_NAME}" ] || spcd_error_ci "SPCD_PROJECT_NAME"
|
||||
#
|
||||
spcd_split
|
||||
spcd_echo "SPCD_PROJECT_BRANCH" \
|
||||
"SPCD_PROJECT_ROOT" "SPCD_PROJECT_PATH" "SPCD_PROJECT_NAME"
|
||||
# set path
|
||||
SPCD_PATH="$(realpath "${0}")"
|
||||
spcd_echo "SPCD_PATH"
|
||||
|
@ -367,77 +447,9 @@ Acquire::https::Verify-Peer False;
|
|||
spcd_echo "SPCD_PYTHON_COMMAND" "SPCD_PYTHON_PACKAGE" "SPCD_PYTHON_PACKAGES"
|
||||
# variables
|
||||
[ -n "${SPCD_CA_1}" ] && SPCD_CA=true
|
||||
# continuous integration platform
|
||||
if [ -n "${GITHUB_ACTIONS}" ]; then
|
||||
# github → gitea → forgejo
|
||||
if [ -n "${GITHUB_SERVER_URL}" ]; then
|
||||
SPCD_PROJECT_ROOT="$(dirname "${GITHUB_SERVER_URL}")//"
|
||||
[ -n "${GITHUB_TOKEN}" ] &&
|
||||
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}${GITHUB_TOKEN}@"
|
||||
SPCD_PROJECT_ROOT="${SPCD_PROJECT_ROOT}$(basename "${GITHUB_SERVER_URL}")"
|
||||
else
|
||||
spcd_error_ci "GITHUB_SERVER_URL"
|
||||
fi
|
||||
if [ -n "${GITHUB_REPOSITORY}" ]; then
|
||||
SPCD_PROJECT_PATH="$(dirname "${GITHUB_REPOSITORY}")"
|
||||
SPCD_PROJECT_NAME="$(basename "${GITHUB_REPOSITORY}")"
|
||||
else
|
||||
spcd_error_ci "GITHUB_REPOSITORY"
|
||||
fi
|
||||
if [ -n "${GITHUB_REF_NAME}" ]; then
|
||||
SPCD_PROJECT_BRANCH="${GITHUB_REF_NAME}"
|
||||
else
|
||||
spcd_error_ci "GITHUB_REF_NAME"
|
||||
fi
|
||||
elif [ -n "${GITLAB_CI}" ]; then
|
||||
# gitlab
|
||||
if [ -n "${CI_SERVER_PROTOCOL}" ]; then
|
||||
if [ -n "${CI_REGISTRY_USER}" ]; then
|
||||
if [ -n "${CI_REGISTRY_PASSWORD}" ]; then
|
||||
if [ -n "${CI_SERVER_FQDN}" ]; then
|
||||
SPCD_PROJECT_ROOT="${CI_SERVER_PROTOCOL}\
|
||||
://${CI_REGISTRY_USER}:${CI_REGISTRY_PASSWORD}@${CI_SERVER_FQDN}"
|
||||
if [ -n "${CI_PROJECT_NAMESPACE}" ]; then
|
||||
SPCD_PROJECT_PATH="${CI_PROJECT_NAMESPACE}"
|
||||
if [ -n "${CI_PROJECT_NAME}" ]; then
|
||||
SPCD_PROJECT_NAME="${CI_PROJECT_NAME}"
|
||||
else
|
||||
spcd_error_ci "CI_PROJECT_NAME"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_PROJECT_NAMESPACE"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_SERVER_FQDN"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_REGISTRY_PASSWORD"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_REGISTRY_USER"
|
||||
fi
|
||||
else
|
||||
spcd_error_ci "CI_SERVER_PROTOCOL"
|
||||
fi
|
||||
if [ -n "${CI_COMMIT_BRANCH}" ]; then
|
||||
SPCD_PROJECT_BRANCH="${CI_COMMIT_BRANCH}"
|
||||
else
|
||||
spcd_error_ci "CI_COMMIT_BRANCH"
|
||||
fi
|
||||
else
|
||||
# unsupported
|
||||
spcd_error_ci "ø"
|
||||
fi
|
||||
[ -n "${SPCD_PROJECT_ROOT}" ] || spcd_error_ci "SPCD_PROJECT_ROOT"
|
||||
[ -n "${SPCD_PROJECT_PATH}" ] || spcd_error_ci "SPCD_PROJECT_PATH"
|
||||
[ -n "${SPCD_PROJECT_NAME}" ] || spcd_error_ci "SPCD_PROJECT_NAME"
|
||||
[ -n "${SPCD_PROJECT_BRANCH}" ] || spcd_error_ci "SPCD_PROJECT_BRANCH"
|
||||
#
|
||||
spcd_split
|
||||
spcd_echo "SPCD_CA"
|
||||
spcd_split
|
||||
spcd_echo "SPCD_PROJECT_ROOT" \
|
||||
"SPCD_PROJECT_PATH" "SPCD_PROJECT_NAME" "SPCD_PROJECT_BRANCH"
|
||||
# TODO move to Python
|
||||
case "${SPCD_PM}" in
|
||||
"${SPCD_PM_APK}" | "${SPCD_PM_APT}") SPCD_PKG_SSH="openssh-client" ;;
|
||||
|
@ -447,6 +459,12 @@ Acquire::https::Verify-Peer False;
|
|||
esac
|
||||
}
|
||||
|
||||
spcd_list_working_directory() {
|
||||
spcd_step "List working directory"
|
||||
spcd_lwd__path="$(realpath .)"
|
||||
spcd_ls "${spcd_lwd__path}"
|
||||
}
|
||||
|
||||
spcd_set_packages_repositories() {
|
||||
spcd_step "Set packages repositories"
|
||||
case "${SPCD_OS_ID}" in
|
||||
|
@ -808,8 +826,8 @@ SPCD_BOX_RIGHT="╶"
|
|||
SPCD_BOX_UP="╰"
|
||||
SPCD_BOX_VERTICAL="│"
|
||||
|
||||
SPCD_ERROR_CI=2
|
||||
SPCD_ERROR_OS=1
|
||||
SPCD_ERROR_CI=1
|
||||
SPCD_ERROR_OS=2
|
||||
|
||||
SPCD_OS_ALMA="alma"
|
||||
SPCD_OS_ALPINE="alpine"
|
||||
|
|
Loading…
Reference in a new issue