_common.yml•4.61 kB
variables:
GREEN: '\033[0;32m'
NC: '\033[0m'
WERF_RELEASES_HISTORY_MAX: 3
.unittest:
image: $CI_REGISTRY_IMAGE:app-$CI_COMMIT_REF_SLUG-latest
services:
- postgres:15.1-alpine
variables:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
NODE_ENV: test
CI: "true"
before_script:
- npm ci
script:
- npm run lint
- npm run format:check
- npm run build
- npm run test
except:
- schedules
.werf:
before_script:
- curl -sSL https://werf.io/install.sh | bash -s -- --ci
- source $(~/bin/trdl use werf ${WERF_VERSION_GLOBAL:-$WERF_VERSION})
- source $(werf ci-env gitlab --as-file)
.chart:
script:
- |
if [ ! -f ~/bin/yq ]; then
wget https://github.com/mikefarah/yq/releases/download/v4.27.5/yq_linux_amd64 -O ~/bin/yq
chmod 0755 ~/bin/yq
fi
- |
~/bin/yq -r '.dependencies [] | select(.repository|test("fox.flant.com")) | .name + " " + .repository' .helm/Chart.yaml |
while IFS= read -r name repository; do
werf helm repo add --username client-access-to-charts --password ${HELM_CHARTS_TOKEN} $name $repository
done || true
- |
~/bin/yq -r '.dependencies [] | select(.repository|test("fox") | not) | .name + " " + .repository' .helm/Chart.yaml |
while IFS= read -r name repository; do
werf helm repo add $name $repository
done || true
after_script:
- !reference [.werf, before_script]
- |
~/bin/yq -r '.dependencies [] | .name' .helm/Chart.yaml |
while read -r name; do
werf helm repo remove $name
done || true
.flags:
script:
- |
werf_flags=()
for val in "values" "secret-values"; do
for path in \
".helm/${val}.${WERF_ENV}.yaml" \
".helm/${WERF_ENV}/${val}.yaml"
do
if [ -f "${path}" ]; then
werf_flags+=("--${val}=${path}")
fi
done
done
if [ ${#werf_flags[@]} -gt 0 ]; then
echo -e "${GREEN}Append werf flags: ${werf_flags[*]}${NC}"
fi
.plan:
stage: plan
before_script:
- !reference [.werf, before_script]
script:
- !reference [.chart, script]
- !reference [.flags, script]
- werf plan "${werf_flags[@]}"
after_script:
- !reference [.chart, after_script]
except:
- schedules
- merge_requests
tags:
- werf
allow_failure: true
.converge:
stage: converge
before_script:
- !reference [.werf, before_script]
script:
- !reference [.chart, script]
- !reference [.flags, script]
- werf converge "${werf_flags[@]}"
after_script:
- !reference [.chart, after_script]
except:
- schedules
- merge_requests
tags:
- werf
when: manual
.cleanup:
stage: cleanup
before_script:
- !reference [.werf, before_script]
- docker login -u nobody -p ${WERF_IMAGES_CLEANUP_PASSWORD} ${WERF_REPO}
script:
- werf cleanup
after_script:
- docker logout
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
tags:
- werf
.cimr:
stage: checkapproves
tags:
- docker
script:
- echo "APPROVAL_AUTHORS '${APPROVAL_AUTHORS}'"
- echo "CI_MERGE_REQUEST_TARGET_BRANCH_NAME '${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}'"
- |
MR_INFO=$(curl --silent --request GET --header "PRIVATE-TOKEN: $GITLAB_TOKEN_FOR_CI" \
${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests | jq -c ".[] \
| select(.sha == \"${CI_COMMIT_SHA}\" and .state == \"opened\" and .target_branch == \"${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}\")")
- MR_ID=$(echo $MR_INFO | jq '.iid')
- |
APPROVALS=$(curl --silent --request GET --header "PRIVATE-TOKEN: ${GITLAB_TOKEN_FOR_CI}" \
"${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/merge_requests/${MR_ID}/approvals")
- echo "${APPROVALS}"
- |
APPROVAL_AUTHORS_ARRAY=(${APPROVAL_AUTHORS//,/ })
APPROVED=false
for AUTHOR in "${APPROVAL_AUTHORS_ARRAY[@]}"; do
if echo "${APPROVALS}" | jq -e ".approved_by[] | select(.user.username == \"${AUTHOR}\")" > /dev/null; then
APPROVED=true
break
fi
done
- |
if [ "${APPROVED}" = true ]; then
echo "Great job! Your merge request has been approved!";
else
echo "Almost there! Please get approval from one of the following users: ${APPROVAL_AUTHORS//,/, } to proceed.";
exit 1;
fi
image: laptevss/gitlab-api-util
rules:
- if: >
($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "prod20" ||
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "testing" ||
$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop") &&
$CI_PROJECT_NAME == "radius-mcp-server"