From 90120cd9fc6d298e900c61e6cd456b3d22c8942c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Anguita=20L=C3=B3pez?= Date: Mon, 29 Jun 2026 16:23:39 +0200 Subject: [PATCH] add input tag and adapt logic --- .github/workflows/5_bumper_repository.yml | 20 ++-- tools/repository_bumper.sh | 136 +++++++++++++--------- 2 files changed, 92 insertions(+), 64 deletions(-) diff --git a/.github/workflows/5_bumper_repository.yml b/.github/workflows/5_bumper_repository.yml index ae1b3e63..81d2913c 100644 --- a/.github/workflows/5_bumper_repository.yml +++ b/.github/workflows/5_bumper_repository.yml @@ -96,18 +96,22 @@ jobs: version=${{ env.VERSION }} stage=${{ env.STAGE }} tag=${{ env.TAG }} - set_as_main=${{ inputs.set_as_main }} - if [[ "$set_as_main" == "true" ]]; then - script_params="--set-as-main" + if [[ -n "$version" && -n "$stage" && "$tag" != "true" ]]; then + 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 - # Both version and stage provided - if [[ -n "$version" && -n "$stage" && "$tag" != "true" ]]; then - script_params+=" --version ${version} --stage ${stage}" - elif [[ -n "$version" && -n "$stage" && "$tag" == "true" ]]; then - script_params+=" --version ${version} --stage ${stage} --tag ${tag}" + if [[ "$set_as_main" == "true" ]]; then + if [[ -z "$version" || -z "$stage" ]]; then + echo "Error: set_as_main requires both version and stage inputs." + exit 1 + fi + script_params="${script_params} --set-as-main" fi issue_number=$(echo "${{ inputs.issue-link }}" | awk -F'/' '{print $NF}') diff --git a/tools/repository_bumper.sh b/tools/repository_bumper.sh index 4712761a..6c8d2be9 100644 --- a/tools/repository_bumper.sh +++ b/tools/repository_bumper.sh @@ -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" VERSION="" STAGE="" +TAG="" +REFERENCE="" 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"' @@ -74,40 +76,44 @@ update_stage_in_files() { FILES_EDITED+=("${file}") fi done +} - if [ $STAGE != "alpha0" ]; then - version_tag_string=": 'v${VERSION}'" - files_tag=( $(grep_command "${version_tag_string}" "${DIR}") ) - for file in "${files_tag[@]}"; do - sed -i -E "s/(: )'v${VERSION}'/\1'v${VERSION}-${STAGE}'/g" "${file}" - if [[ $(git diff --name-only "${file}") ]]; then - FILES_EDITED+=("${file}") - fi - done - - version_number_string=": '${VERSION}'" - files_version=( $(grep -RlE ": '[0-9]\.[0-9]+\.[0-9]+'" "${DIR}") ) - for file in "${files_version[@]}"; do - sed -i -E "s/(: )'${VERSION}'/\1'v${VERSION}-${STAGE}'/g" "${file}" - if [[ $(git diff --name-only "${file}") ]]; then - FILES_EDITED+=("${file}") - fi - done +# Compute the value written into branch reference defaults (": '...'"). +# Without --tag, references stay branch-like (e.g. 5.0.0). +# With --tag, references become tag-like (e.g. v5.0.0-beta3), or a plain release +# tag (e.g. v5.0.0) when no stage is provided. +build_reference() { + if [[ -n "$TAG" ]]; then + if [[ -z "$STAGE" ]]; then + REFERENCE="v${VERSION}" + else + REFERENCE="v${VERSION}-${STAGE}" + fi + else + REFERENCE="${VERSION}" fi } +# Tag mode only: normalize every reference to the current version +# (branch-like "5.0.0", "v5.0.0" or "v5.0.0-") into ${REFERENCE}. +# Matching is restricted to ": '...'" 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() { - if [[ $STAGE == "alpha0" ]]; then - bump_value="${VERSION}" - else - bump_value="v${VERSION}" - fi - main_string=": 'main'" + local main_string=": 'main'" files=( $(grep_command "${main_string}" "${DIR}") ) for file in "${files[@]}"; do - if [[ "$skip_urls" != "yes" ]]; then - sed -Ei "s/(:[[:space:]])'main'/\1'${bump_value}'/g" "${file}" - fi + sed -Ei "s/(:[[:space:]])'main'/\1'${REFERENCE}'/g" "${file}" if [[ $(git diff --name-only "${file}") ]]; then FILES_EDITED+=("${file}") fi @@ -141,8 +147,8 @@ main() { shift 2 ;; --tag) - TAG="$2" - shift 2 + TAG="yes" + shift 1 ;; --set-as-main) set_as_main="yes" @@ -155,15 +161,33 @@ main() { esac done - # Validate arguments - if [[ -z "${VERSION}" ]]; then - echo "Error: --version argument is required." | tee -a "${LOG_FILE}" + # --tag rewrites branch references into tag-like references (e.g. v5.0.0-beta3) + # and re-tags the Docker images accordingly. It is mutually exclusive with + # --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 fi - if [[ -z "${STAGE}" ]]; then - echo "Error: --stage argument is required." | tee -a "${LOG_FILE}" - exit 1 + # Read the current version/stage early: tag scenarios may omit --version and/or + # --stage and reuse the values already stored in VERSION.json. + 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 # Validate if version is in the correct format @@ -172,28 +196,25 @@ main() { exit 1 fi - # Validate if stage is in the correct format - STAGE=$(echo "${STAGE}" | tr '[:upper:]' '[:lower:]') - if ! [[ "${STAGE}" =~ ^(alpha[0-9]*|beta[0-9]*|rc[0-9]*|stable)$ ]]; then - echo "Error: Stage must be one of the following examples: alpha1, beta1, rc1, stable." | tee -a "${LOG_FILE}" - exit 1 + # Validate if stage is in the correct format (when provided) + if [[ -n "${STAGE}" ]]; then + STAGE=$(echo "${STAGE}" | tr '[:upper:]' '[:lower:]') + if ! [[ "${STAGE}" =~ ^(alpha[0-9]*|beta[0-9]*|rc[0-9]*|stable)$ ]]; then + echo "Error: Stage must be one of the following examples: alpha1, beta1, rc1, stable." | tee -a "${LOG_FILE}" + exit 1 + 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 - echo "Updating version from main to $VERSION" | tee -a "${LOG_FILE}" - update_main_in_files "$VERSION" "$STAGE" + echo "Updating 'main' references to ${REFERENCE}" | tee -a "${LOG_FILE}" + update_main_in_files 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 echo "Updating version from ${OLD_VERSION} to ${VERSION}" | tee -a "${LOG_FILE}" update_version_in_files "${VERSION}" @@ -203,10 +224,13 @@ main() { update_stage_in_files "$VERSION" "$STAGE" fi - # Update Docker images tag if tag is true - if [[ "${TAG}" == "true" ]]; then - echo "Updating Docker images tag to ${VERSION}-${STAGE}" | tee -a "${LOG_FILE}" - update_docker_images_tag "${VERSION}-${STAGE}" + # Tag mode: normalize remaining version references and re-tag the Docker images + # (image tags carry no leading 'v', e.g. 5.0.0-beta3). + if [[ -n "$TAG" ]]; then + 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