Files
gitea-ci-library/scripts/check-version.sh
T
moilanik 9400815a01
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 26s
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Successful in 1m10s
unit-tests Bats test report
CI Feature / Bats tests (push) Successful in 1m39s
CI Feature / Report Summary (push) Successful in 6s
check version script tiedostoon
2026-06-19 07:43:02 +03:00

60 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
RAW_VERSION=""
if [ -n "${VERSION_FILE}" ] && [ -f "${VERSION_FILE}" ]; then
if echo "${VERSION_FILE}" | grep -q -E '\.json$'; then
RAW_VERSION=$(jq -r '.version' "${VERSION_FILE}")
elif echo "${VERSION_FILE}" | grep -q -E '\.(ya?ml)$'; then
RAW_VERSION=$(grep -oP '^version:\s*\K\S+' "${VERSION_FILE}")
else
RAW_VERSION=$(cat "${VERSION_FILE}" | tr -d '[:space:]')
fi
fi
if [ -z "${RAW_VERSION}" ]; then
if [ -f VERSION ]; then
RAW_VERSION=$(cat VERSION | tr -d '[:space:]')
elif [ -f package.json ]; then
RAW_VERSION=$(jq -r '.version' package.json)
elif [ -f pom.xml ]; then
RAW_VERSION=$(grep -oP '<version>\K[^<]+' pom.xml | head -1)
elif [ -f Chart.yaml ]; then
RAW_VERSION=$(grep -oP '^version:\s*\K\S+' Chart.yaml)
else
echo "ERROR: No version source found (VERSION_FILE, VERSION, package.json, pom.xml, Chart.yaml)" >&2
exit 1
fi
fi
BASE_VERSION=$(echo "$RAW_VERSION" | cut -d'.' -f1-2)
echo "gitea-ci-library - Tunnistettu Major.Minor versio: $BASE_VERSION"
TAGS_JSON=$(curl -s -f -H "Authorization: token ${GITEA_TOKEN}" \
"${SERVER_URL}/api/v1/repos/${REPO}/tags")
TAG=$(echo "$TAGS_JSON" | jq -r --arg prefix "${GIT_TAG_PREFIX}" --arg sha "${SHA}" '
if type == "array" then
.[] | select(.commit.sha == $sha and (.name | startswith($prefix))) | .name
else empty end' | head -1)
mkdir -p /tmp/build-ctx
if [ -n "$TAG" ]; then
echo "ARTIFACT_EXISTS=true" > /tmp/build-ctx/build.env
echo "NEXT_VERSION=$TAG" >> /tmp/build-ctx/build.env
echo "gitea-ci-library - Artefakti löytyi jo tagilla: $TAG."
else
echo "ARTIFACT_EXISTS=false" > /tmp/build-ctx/build.env
HIGHEST_PATCH=$(echo "$TAGS_JSON" | jq -r --arg prefix "${GIT_TAG_PREFIX}" --arg bv "${GIT_TAG_PREFIX}${BASE_VERSION}." '
if type == "array" then .[] | .name | select(startswith($bv)) | sub($bv; "") | tonumber else empty end' | sort -rn | head -1)
if [ -z "$HIGHEST_PATCH" ]; then NEXT_PATCH=0; else NEXT_PATCH=$((HIGHEST_PATCH + 1)); fi
FULL_VERSION="${BASE_VERSION}.${NEXT_PATCH}"
echo "NEXT_VERSION=$FULL_VERSION" >> /tmp/build-ctx/build.env
echo "gitea-ci-library - Uusi vapaa versio: $FULL_VERSION"
fi