add input tag and adapt logic

This commit is contained in:
Carlos Anguita López
2026-06-29 16:23:39 +02:00
parent f92b6b1e8a
commit 90120cd9fc
2 changed files with 92 additions and 64 deletions
+12 -8
View File
@@ -96,18 +96,22 @@ jobs:
version=${{ env.VERSION }} version=${{ env.VERSION }}
stage=${{ env.STAGE }} stage=${{ env.STAGE }}
tag=${{ env.TAG }} tag=${{ env.TAG }}
set_as_main=${{ inputs.set_as_main }} set_as_main=${{ inputs.set_as_main }}
if [[ "$set_as_main" == "true" ]]; then if [[ -n "$version" && -n "$stage" && "$tag" != "true" ]]; then
script_params="--set-as-main" script_params="--version ${version} --stage ${stage}"
elif [[ -z "$version" && -n "$stage" && "$tag" == "true" ]]; then
script_params="--stage ${stage} --tag"
elif [[ -z "$version" && -z "$stage" && "$tag" == "true" ]]; then
script_params="--tag"
fi fi
# Both version and stage provided if [[ "$set_as_main" == "true" ]]; then
if [[ -n "$version" && -n "$stage" && "$tag" != "true" ]]; then if [[ -z "$version" || -z "$stage" ]]; then
script_params+=" --version ${version} --stage ${stage}" echo "Error: set_as_main requires both version and stage inputs."
elif [[ -n "$version" && -n "$stage" && "$tag" == "true" ]]; then exit 1
script_params+=" --version ${version} --stage ${stage} --tag ${tag}" fi
script_params="${script_params} --set-as-main"
fi fi
issue_number=$(echo "${{ inputs.issue-link }}" | awk -F'/' '{print $NF}') issue_number=$(echo "${{ inputs.issue-link }}" | awk -F'/' '{print $NF}')
+80 -56
View File
@@ -9,6 +9,8 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
LOG_FILE="${DIR}/tools/repository_bumper_$(date +"%Y-%m-%d_%H-%M-%S-%3N").log" LOG_FILE="${DIR}/tools/repository_bumper_$(date +"%Y-%m-%d_%H-%M-%S-%3N").log"
VERSION="" VERSION=""
STAGE="" STAGE=""
TAG=""
REFERENCE=""
FILES_EDITED=() FILES_EDITED=()
FILES_EXCLUDED='--exclude="repository_bumper_*.log" --exclude="CHANGELOG.md" --exclude="repository_bumper.sh" --exclude="*_bumper_repository.yml" --exclude="mermaid-init.js" --exclude="mermaid.min.js"' FILES_EXCLUDED='--exclude="repository_bumper_*.log" --exclude="CHANGELOG.md" --exclude="repository_bumper.sh" --exclude="*_bumper_repository.yml" --exclude="mermaid-init.js" --exclude="mermaid.min.js"'
@@ -74,40 +76,44 @@ update_stage_in_files() {
FILES_EDITED+=("${file}") FILES_EDITED+=("${file}")
fi fi
done done
}
if [ $STAGE != "alpha0" ]; then # Compute the value written into branch reference defaults ("<key>: '...'").
version_tag_string=": 'v${VERSION}'" # Without --tag, references stay branch-like (e.g. 5.0.0).
files_tag=( $(grep_command "${version_tag_string}" "${DIR}") ) # With --tag, references become tag-like (e.g. v5.0.0-beta3), or a plain release
for file in "${files_tag[@]}"; do # tag (e.g. v5.0.0) when no stage is provided.
sed -i -E "s/(: )'v${VERSION}'/\1'v${VERSION}-${STAGE}'/g" "${file}" build_reference() {
if [[ $(git diff --name-only "${file}") ]]; then if [[ -n "$TAG" ]]; then
FILES_EDITED+=("${file}") if [[ -z "$STAGE" ]]; then
fi REFERENCE="v${VERSION}"
done else
REFERENCE="v${VERSION}-${STAGE}"
version_number_string=": '${VERSION}'" fi
files_version=( $(grep -RlE ": '[0-9]\.[0-9]+\.[0-9]+'" "${DIR}") ) else
for file in "${files_version[@]}"; do REFERENCE="${VERSION}"
sed -i -E "s/(: )'${VERSION}'/\1'v${VERSION}-${STAGE}'/g" "${file}"
if [[ $(git diff --name-only "${file}") ]]; then
FILES_EDITED+=("${file}")
fi
done
fi fi
} }
# Tag mode only: normalize every reference to the current version
# (branch-like "5.0.0", "v5.0.0" or "v5.0.0-<stage>") into ${REFERENCE}.
# Matching is restricted to "<key>: '...'" entries so plain version strings
# elsewhere in the repository are left untouched.
update_tag_references() {
local V_ESC="${VERSION//./\\.}"
files=( $(grep_command "${VERSION}" "${DIR}") )
for file in "${files[@]}"; do
sed -Ei "s/(:[[:space:]]*')v?${V_ESC}(-[A-Za-z0-9]+)?(')/\1${REFERENCE}\3/g" "${file}"
if [[ $(git diff --name-only "${file}") ]]; then
FILES_EDITED+=("${file}")
fi
done
}
update_main_in_files() { update_main_in_files() {
if [[ $STAGE == "alpha0" ]]; then local main_string=": 'main'"
bump_value="${VERSION}"
else
bump_value="v${VERSION}"
fi
main_string=": 'main'"
files=( $(grep_command "${main_string}" "${DIR}") ) files=( $(grep_command "${main_string}" "${DIR}") )
for file in "${files[@]}"; do for file in "${files[@]}"; do
if [[ "$skip_urls" != "yes" ]]; then sed -Ei "s/(:[[:space:]])'main'/\1'${REFERENCE}'/g" "${file}"
sed -Ei "s/(:[[:space:]])'main'/\1'${bump_value}'/g" "${file}"
fi
if [[ $(git diff --name-only "${file}") ]]; then if [[ $(git diff --name-only "${file}") ]]; then
FILES_EDITED+=("${file}") FILES_EDITED+=("${file}")
fi fi
@@ -141,8 +147,8 @@ main() {
shift 2 shift 2
;; ;;
--tag) --tag)
TAG="$2" TAG="yes"
shift 2 shift 1
;; ;;
--set-as-main) --set-as-main)
set_as_main="yes" set_as_main="yes"
@@ -155,15 +161,33 @@ main() {
esac esac
done done
# Validate arguments # --tag rewrites branch references into tag-like references (e.g. v5.0.0-beta3)
if [[ -z "${VERSION}" ]]; then # and re-tags the Docker images accordingly. It is mutually exclusive with
echo "Error: --version argument is required." | tee -a "${LOG_FILE}" # --set-as-main, which keeps references on main.
if [[ -n "$TAG" && -n "$set_as_main" ]]; then
echo "Error: --tag cannot be combined with --set-as-main." | tee -a "${LOG_FILE}"
exit 1 exit 1
fi fi
if [[ -z "${STAGE}" ]]; then # Read the current version/stage early: tag scenarios may omit --version and/or
echo "Error: --stage argument is required." | tee -a "${LOG_FILE}" # --stage and reuse the values already stored in VERSION.json.
exit 1 get_old_version_and_stage
# Resolve and validate arguments depending on the mode
if [[ -n "$TAG" ]]; then
# Tag mode: version defaults to the current one; stage is optional
# (absent yields a release tag without a stage suffix).
[[ -z "$VERSION" ]] && VERSION="$OLD_VERSION"
else
# Branch mode: a full version + stage bump is required
if [[ -z "${VERSION}" ]]; then
echo "Error: --version argument is required." | tee -a "${LOG_FILE}"
exit 1
fi
if [[ -z "${STAGE}" ]]; then
echo "Error: --stage argument is required." | tee -a "${LOG_FILE}"
exit 1
fi
fi fi
# Validate if version is in the correct format # Validate if version is in the correct format
@@ -172,28 +196,25 @@ main() {
exit 1 exit 1
fi fi
# Validate if stage is in the correct format # Validate if stage is in the correct format (when provided)
STAGE=$(echo "${STAGE}" | tr '[:upper:]' '[:lower:]') if [[ -n "${STAGE}" ]]; then
if ! [[ "${STAGE}" =~ ^(alpha[0-9]*|beta[0-9]*|rc[0-9]*|stable)$ ]]; then STAGE=$(echo "${STAGE}" | tr '[:upper:]' '[:lower:]')
echo "Error: Stage must be one of the following examples: alpha1, beta1, rc1, stable." | tee -a "${LOG_FILE}" if ! [[ "${STAGE}" =~ ^(alpha[0-9]*|beta[0-9]*|rc[0-9]*|stable)$ ]]; then
exit 1 echo "Error: Stage must be one of the following examples: alpha1, beta1, rc1, stable." | tee -a "${LOG_FILE}"
exit 1
fi
fi fi
# Set skip_urls variable based on set_as_main flag # Compute the value written into branch reference defaults
build_reference
echo "Reference for branch defaults: ${REFERENCE}" | tee -a "${LOG_FILE}"
# Convert 'main' references unless they must keep pointing to main (set-as-main)
if [[ -z "$set_as_main" ]]; then if [[ -z "$set_as_main" ]]; then
echo "Updating version from main to $VERSION" | tee -a "${LOG_FILE}" echo "Updating 'main' references to ${REFERENCE}" | tee -a "${LOG_FILE}"
update_main_in_files "$VERSION" "$STAGE" update_main_in_files
fi fi
# Validate if tag is true or false
if [[ -n "${TAG}" && ! "${TAG}" =~ ^(true|false)$ ]]; then
echo "Error: --tag must be either true or false." | tee -a "${LOG_FILE}"
exit 1
fi
# Get old version and stage
get_old_version_and_stage
if [[ "${OLD_VERSION}" != "${VERSION}" ]]; then if [[ "${OLD_VERSION}" != "${VERSION}" ]]; then
echo "Updating version from ${OLD_VERSION} to ${VERSION}" | tee -a "${LOG_FILE}" echo "Updating version from ${OLD_VERSION} to ${VERSION}" | tee -a "${LOG_FILE}"
update_version_in_files "${VERSION}" update_version_in_files "${VERSION}"
@@ -203,10 +224,13 @@ main() {
update_stage_in_files "$VERSION" "$STAGE" update_stage_in_files "$VERSION" "$STAGE"
fi fi
# Update Docker images tag if tag is true # Tag mode: normalize remaining version references and re-tag the Docker images
if [[ "${TAG}" == "true" ]]; then # (image tags carry no leading 'v', e.g. 5.0.0-beta3).
echo "Updating Docker images tag to ${VERSION}-${STAGE}" | tee -a "${LOG_FILE}" if [[ -n "$TAG" ]]; then
update_docker_images_tag "${VERSION}-${STAGE}" echo "Updating version references to tag reference ${REFERENCE}" | tee -a "${LOG_FILE}"
update_tag_references
echo "Updating Docker images tag to ${REFERENCE#v}" | tee -a "${LOG_FILE}"
update_docker_images_tag "${REFERENCE#v}"
fi fi