Files
sendico/ci/scripts/common/bump_version.sh
Stephan D 71a67e1f6d
Some checks failed
ci/woodpecker/push/billing_fees Pipeline was successful
ci/woodpecker/push/bff Pipeline was successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/chain_gateway Pipeline was successful
ci/woodpecker/push/fx_ingestor Pipeline was successful
ci/woodpecker/push/frontend Pipeline was successful
ci/woodpecker/push/fx_oracle Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful
ci/woodpecker/push/ledger Pipeline was successful
ci/woodpecker/push/notification Pipeline was successful
ci/woodpecker/push/payments_orchestrator Pipeline was successful
ci/woodpecker/push/bump_version Pipeline failed
removed trash
2025-11-18 17:33:01 +01:00

118 lines
3.5 KiB
Bash
Executable File

#!/bin/sh
set -eu
START_DIR="$(pwd)"
echo "[bump-version] invoked from ${START_DIR}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
REPO_ROOT=""
if command -v git >/dev/null 2>&1; then
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || true)"
fi
if [ -z "${REPO_ROOT}" ]; then
REPO_ROOT="$(cd "${SCRIPT_DIR}/../../.." && pwd)"
fi
echo "[bump-version] repo root resolved to ${REPO_ROOT}"
cd "${REPO_ROOT}"
VERSION_FILE="./version"
if [ ! -f "${VERSION_FILE}" ]; then
if git cat-file -e "HEAD:version" 2>/dev/null; then
echo "[bump-version] version file missing in workspace, restoring from HEAD" >&2
git show "HEAD:version" > "${VERSION_FILE}"
else
echo "[bump-version] version file not found: ${VERSION_FILE}" >&2
exit 1
fi
fi
CURRENT_VERSION="$(cat "${VERSION_FILE}")"
NEXT_VERSION="$(printf '%s' "${CURRENT_VERSION}" | awk -F. -v OFS=. '
function pad(value, width, result, i) {
result=value ""
if (length(result) >= width) {
return result
}
i = width - length(result)
while (i-- > 0) {
result = "0" result
}
return result
}
NF==1 { print ++$NF; next }
{
last = $NF + 1
$NF = pad(last, length($NF))
print
}')"
printf '%s\n' "${NEXT_VERSION}" > "${VERSION_FILE}"
echo "[bump-version] ${CURRENT_VERSION} -> ${NEXT_VERSION}"
git add "${VERSION_FILE}"
if git diff --cached --quiet; then
echo "[bump-version] no changes staged, skipping commit"
exit 0
fi
AUTHOR_NAME="${GIT_AUTHOR_NAME:-woodpecker}"
AUTHOR_EMAIL="${GIT_AUTHOR_EMAIL:-ci@sendico.io}"
git config user.name "${AUTHOR_NAME}"
git config user.email "${AUTHOR_EMAIL}"
git commit -m "chore(ci): bump version to ${NEXT_VERSION}"
BRANCH="${WOODPECKER_BRANCH:-}"
if [ -z "${BRANCH}" ] || [ "${BRANCH}" = "HEAD" ]; then
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
fi
REMOTE_URL="${CI_REPO_REMOTE:-${WOODPECKER_GIT_REMOTE:-${DRONE_REMOTE_URL:-}}}"
if [ -z "${REMOTE_URL}" ]; then
REMOTE_URL="$(git config --get remote.origin.url 2>/dev/null || true)"
fi
# Normalize machine to a bare hostname so .netrc matches HTTPS requests.
normalize_machine() {
value="$1"
if [ -z "${value}" ]; then
printf '%s' ""
return
fi
printf '%s' "${value}" | sed -E '
s#^[[:alpha:]][[:alnum:]+.-]*://##;
s#^[^@]*@##;
s#/.*$##;
s#:[0-9]+$##;
'
}
NETRC_MACHINE="${CI_NETRC_MACHINE:-${WOODPECKER_NETRC_MACHINE:-${DRONE_NETRC_MACHINE:-}}}"
NETRC_USERNAME="${CI_NETRC_USERNAME:-${WOODPECKER_NETRC_USERNAME:-${DRONE_NETRC_USERNAME:-${CI_NETRC_LOGIN:-${WOODPECKER_NETRC_LOGIN:-${DRONE_NETRC_LOGIN:-}}}}}}"
NETRC_PASSWORD="${CI_NETRC_PASSWORD:-${WOODPECKER_NETRC_PASSWORD:-${DRONE_NETRC_PASSWORD:-}}}"
NETRC_MACHINE="$(normalize_machine "${NETRC_MACHINE}")"
if [ -z "${NETRC_MACHINE}" ] && [ -n "${REMOTE_URL}" ]; then
NETRC_MACHINE="$(normalize_machine "${REMOTE_URL}")"
fi
if [ -n "${NETRC_MACHINE}" ] && [ -n "${NETRC_USERNAME}" ] && [ -n "${NETRC_PASSWORD}" ]; then
MASKED_USER="$(printf '%s' "${NETRC_USERNAME}" | cut -c1-2)***"
echo "[bump-version] configuring credentials for ${NETRC_MACHINE} (user ${MASKED_USER})"
NETRC_FILE="${HOME:-/root}/.netrc"
{
printf 'machine %s\n' "${NETRC_MACHINE}"
printf 'login %s\n' "${NETRC_USERNAME}"
printf 'password %s\n' "${NETRC_PASSWORD}"
} > "${NETRC_FILE}"
chmod 600 "${NETRC_FILE}"
else
echo "[bump-version] no netrc credentials available"
fi
if [ -n "${REMOTE_URL}" ]; then
echo "[bump-version] using remote ${REMOTE_URL}"
git remote set-url origin "${REMOTE_URL}"
fi
git push origin "HEAD:${BRANCH}"