# This job will create or update a version badge containing the latest tag
# This job will create or update a version badge containing the latest tag.
# It requires a Project Access Token set as a CI/CD variable called GL_TOKEN
# Also make sure you have set a protected tags wildcard as "v*"
# If you want to disable badges, set a global variable called "I_DONT_LIKE_BADGES"
semantic-release:badge:
image:bash:latest
stage:deploy
script:
-|
if [[ ! ${CI_COMMIT_TAG} =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then
echo "[!] Not a version tag in format v#.#.#."
if [ -z ${GL_TOKEN} ]; then
echo '$GL_TOKEN is not set. Did you add a Project Access Token with api scope as GL_TOKEN to the CI/CD Variables? If so, it may be set as Protected. You need to add a protected tag wildcard as "v*" for this project.'
exit 1
fi
-apk add --no-cache curl jq
-|
BADGE_ID=$(curl --silent --header "PRIVATE-TOKEN: ${GL_TOKEN}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/badges" | jq '.[] | select(.name=="version") | .id') || echo "[-] Unable to get current badge id."