Skip to content

Commit 1d808b7

Browse files
committed
new CI
1 parent 3c48ee3 commit 1d808b7

File tree

3 files changed

+202
-0
lines changed

3 files changed

+202
-0
lines changed

.gitlab/.gitlab-ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
variables:
2+
CURRENT_BRANCH_NAME: sk_content-external-template #"${INFRA_BRANCH}"
3+
4+
include:
5+
- file: .gitlab/ci/content-external-template/.gitlab-ci.yml
6+
ref: sk_content-external-template #"${INFRA_BRANCH}"
7+
project: "${CI_PROJECT_NAMESPACE}/infra"

.gitlab/helper_functions.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
CYAN="\e[0;36m"
4+
CLEAR="\e[0m"
5+
RED='\033[0;31m'
6+
GREEN='\033[0;32m'
7+
BLUE='\033[0;34m'
8+
NC='\033[0m'
9+
10+
SECTION_START="\e[0Ksection_start:the_time:section_id\r\e[0K${CYAN}section_header${CLEAR}"
11+
SECTION_END="\e[0Ksection_end:the_time:section_id\r\e[0K"
12+
13+
section_start() {
14+
local section_header section_id start
15+
start="$SECTION_START"
16+
if [[ "$#" -eq 1 ]]; then
17+
section_header="$1"
18+
section_id="$(echo "$1" | tr -c '[:alnum:]\n\r' '_')"
19+
elif [[ "$#" -eq 2 ]]; then
20+
if [[ "$2" =~ -{0,2}collapsed ]]; then
21+
start="${start/section_id/section_id[collapsed=true]}"
22+
section_header="$1"
23+
section_id="$(echo "$1" | tr -c '[:alnum:]\n\r' '_')"
24+
else
25+
section_header="$2"
26+
section_id="$1"
27+
fi
28+
elif [[ "$#" -eq 3 && "$3" =~ /^-{0,2}collapsed$/ ]]; then
29+
start="${start/section_id/section_id[collapsed=true]}"
30+
section_header="$2"
31+
section_id="$1"
32+
else
33+
echo "section_start should be called with 1-3 args but it was called with $# args"
34+
echo "acceptable usages:"
35+
echo " 1. section_start \"<section-header>\""
36+
echo " 2. section_start \"<section-start-id>\" \"<section-header>\""
37+
echo " 3. section_start \"<section-header>\" --collapse"
38+
echo " 4. section_start \"<section-start-id>\" \"<section-header>\" --collapse"
39+
echo "where <section-start-id> is only alphanumeric characters and underscore and"
40+
echo "--collapse indicates that you would like those log steps to be collapsed in the job log output by default"
41+
exit 9
42+
fi
43+
start_time=$(date +%s)
44+
start="$(echo "$start" | sed -e "s/the_time/$start_time/" -e "s/section_id/$section_id/" -e "s/section_header/$section_header/")"
45+
echo -e "$start"
46+
date +"[%Y-%m-%dT%H:%M:%S.%3N] section start"
47+
}
48+
49+
section_end() {
50+
local section_id end
51+
date +"[%Y-%m-%dT%H:%M:%S.%3N] section end"
52+
end="$SECTION_END"
53+
if [[ "$#" -eq 1 ]]; then
54+
section_id="$(echo "$1" | tr -c '[:alnum:]\n\r' '_')"
55+
else
56+
echo "section_end should be called with 1 arg but it was called with $# args"
57+
echo "acceptable usage:"
58+
echo " 1. section_end \"<section-start-id>\""
59+
echo " 2. section_end \"<section-header>\""
60+
echo "where <section-start-id> or <section-header> is the id of the section this marks the end of"
61+
exit 9
62+
fi
63+
end_time=$(date +%s)
64+
end="$(echo "$end" | sed -e "s/the_time/$end_time/" -e "s/section_id/$section_id/")"
65+
echo -e "$end"
66+
}
67+
68+
job-done() {
69+
mkdir -p "${PIPELINE_JOBS_FOLDER}"
70+
echo "creating file ${PIPELINE_JOBS_FOLDER}/${CI_JOB_NAME}.txt"
71+
echo "done" > "${PIPELINE_JOBS_FOLDER}/${CI_JOB_NAME}.txt"
72+
echo "finished writing to file ${PIPELINE_JOBS_FOLDER}/${CI_JOB_NAME}.txt"
73+
}
74+
75+
sleep-with-progress() {
76+
local sleep_time=${1:-10}
77+
local sleep_interval=${2:-1}
78+
local sleep_message=${3:-"Sleeping... "}
79+
local columns=${4:-$(tput cols)}
80+
local sleep_step=$((sleep_time / sleep_interval))
81+
for ((i=0; i< sleep_step;i++)); do echo "${sleep_interval}";sleep "${sleep_interval}"; done | poetry run tqdm --total ${sleep_time} --unit seconds --leave --update --colour green -ncols ${columns} --desc "${sleep_message}" 1> /dev/null
82+
}

.hooks/bootstrap

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# Bootstraps a development environment.
5+
#
6+
# This includes:
7+
# * install pre-commit hooks
8+
# * setup virtualenv
9+
10+
function exit_on_error {
11+
if [ "${1}" -ne 0 ]; then
12+
echo "ERROR: ${2}, exiting with code ${1}" 1>&2
13+
exit "${1}"
14+
fi
15+
}
16+
17+
# poetry is installed in ~/.local/bin
18+
PATH=~/.local/bin:$PATH
19+
20+
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
21+
cat << __EOF__
22+
Setup development environment (run with no arguments):
23+
* install pre-commit hooks (set NO_HOOKS=1 to skip)
24+
__EOF__
25+
exit 0
26+
fi
27+
28+
if [ ! "${PWD}" == "$(git rev-parse --show-toplevel)" ]; then
29+
cat >&2 <<__EOF__
30+
ERROR: this script must be run at the root of the source tree
31+
__EOF__
32+
exit 1
33+
fi
34+
35+
echo "======================="
36+
if [ -z "${INSTALL_POETRY}" ]; then
37+
if ! command -v poetry >/dev/null 2>&1; then
38+
echo "ERROR: poetry is missing. Please run the following command to install it:
39+
curl -sSL https://install.python-poetry.org | python3 -" 1>&2
40+
exit 1
41+
fi
42+
else
43+
should_install_poetry="yes"
44+
if command -v poetry >/dev/null 2>&1; then
45+
if [[ "$(poetry --version)" == "Poetry (version ${POETRY_VERSION})" ]]; then
46+
echo "Poetry is already installed with the correct version: $(poetry --version)"
47+
should_install_poetry="no"
48+
else
49+
echo "Poetry is already installed with a different version: $(poetry --version), required version: ${POETRY_VERSION}"
50+
fi
51+
else
52+
echo "Poetry isn't installed"
53+
fi
54+
if [[ "${should_install_poetry}" == "yes" ]]; then
55+
echo "Installing Poetry version:${POETRY_VERSION}"
56+
curl -sSL https://install.python-poetry.org | python3 - --version "${POETRY_VERSION}"
57+
error_code=$?
58+
if ! command -v poetry >/dev/null 2>&1; then
59+
exit_on_error $? "Poetry isn't installed"
60+
fi
61+
if [[ "$(poetry --version)" == "Poetry (version ${POETRY_VERSION})" ]]; then
62+
echo "Poetry version ${POETRY_VERSION} installed successfully"
63+
else
64+
exit_on_error 1 "Poetry version $(poetry --version) doesn't match the required version: ${POETRY_VERSION}"
65+
fi
66+
if [ -n "${ARTIFACTS_FOLDER}" ] && [ "${error_code}" -ne 0 ]; then
67+
cp "${PWD}"/poetry-installer-error-*.log "${ARTIFACTS_FOLDER}"
68+
fi
69+
exit_on_error $error_code "Failed to install Poetry version:${POETRY_VERSION}"
70+
fi
71+
fi
72+
73+
if [ -n "${NO_HOOKS}" ]; then
74+
echo "Skipping hooks setup as environment variable NO_HOOKS is set"
75+
else
76+
GIT_HOOKS_DIR="${PWD}/.git/hooks"
77+
if [ ! -e "${GIT_HOOKS_DIR}/pre-commit" ]; then
78+
echo "Installing 'pre-commit' hooks"
79+
poetry run pre-commit install
80+
exit_on_error $? "Failed to install pre-commit hook"
81+
else
82+
echo "Skipping install of pre-commit hook as it already exists."
83+
echo "If you want to re-install: 'rm ${GIT_HOOKS_DIR}/pre-commit' and then run this script again."
84+
exit 1
85+
fi
86+
fi
87+
88+
if [ -n "${CI}" ]; then
89+
echo "Detected CI environment"
90+
echo "Checking whether poetry files are valid"
91+
poetry check --no-interaction
92+
exit_on_error $? "Failed to check poetry files"
93+
echo "Installing dependencies..."
94+
poetry install --no-interaction
95+
exit_on_error $? "Failed to install dependencies"
96+
else
97+
echo "Detected local environment"
98+
echo "Check if poetry files are valid"
99+
poetry check
100+
exit_on_error $? "Failed to check poetry files"
101+
echo "Installing dependencies..."
102+
poetry install
103+
exit_on_error $? "Failed to install dependencies"
104+
fi
105+
106+
echo "=========================="
107+
echo "Done setting up virtualenv with poetry"
108+
echo "Activate the virtualenv by running: poetry shell"
109+
echo "Deactivate by running: deactivate"
110+
echo "======================="
111+
112+
echo "Finished setting up the environment."
113+
exit 0

0 commit comments

Comments
 (0)