From d939b9962822378c448316a7475ad045752233f9 Mon Sep 17 00:00:00 2001 From: purian23 Date: Wed, 10 Dec 2025 12:27:10 -0500 Subject: [PATCH] Workflow build increment logic --- distro/scripts/obs-upload.sh | 39 +++++++++++++++++++++++---- distro/scripts/ppa-build.sh | 52 +++++++++++++++++++++++------------- 2 files changed, 67 insertions(+), 24 deletions(-) diff --git a/distro/scripts/obs-upload.sh b/distro/scripts/obs-upload.sh index d0137357..d6da1846 100755 --- a/distro/scripts/obs-upload.sh +++ b/distro/scripts/obs-upload.sh @@ -672,7 +672,20 @@ if [[ "$UPLOAD_DEBIAN" == true ]] && [[ "$SOURCE_FORMAT" == *"native"* ]] && [[ if [[ "$IS_MANUAL" == true ]]; then echo "==> Detected rebuild of same base version $CHANGELOG_BASE, incrementing version" - if [[ "$CHANGELOG_VERSION" =~ ^([0-9.]+)\+git$ ]]; then + # If REBUILD_RELEASE is set, use that number directly + if [[ -n "${REBUILD_RELEASE:-}" ]]; then + if [[ "$CHANGELOG_VERSION" =~ ^([0-9.]+)\+git([0-9]+)(\.[a-f0-9]+)?$ ]]; then + BASE_VERSION="${BASH_REMATCH[1]}" + GIT_NUM="${BASH_REMATCH[2]}" + GIT_HASH="${BASH_REMATCH[3]}" + NEW_VERSION="${BASE_VERSION}+git${GIT_NUM}${GIT_HASH}ppa${REBUILD_RELEASE}" + echo " Using REBUILD_RELEASE=$REBUILD_RELEASE: $CHANGELOG_VERSION -> $NEW_VERSION" + else + BASE_VERSION=$(echo "$CHANGELOG_VERSION" | sed 's/ppa[0-9]*$//') + NEW_VERSION="${BASE_VERSION}ppa${REBUILD_RELEASE}" + echo " Using REBUILD_RELEASE=$REBUILD_RELEASE: $CHANGELOG_VERSION -> $NEW_VERSION" + fi + elif [[ "$CHANGELOG_VERSION" =~ ^([0-9.]+)\+git$ ]]; then BASE_VERSION="${BASH_REMATCH[1]}" NEW_VERSION="${BASE_VERSION}+gitppa1" echo " Adding PPA number: $CHANGELOG_VERSION -> $NEW_VERSION" @@ -704,11 +717,27 @@ if [[ "$UPLOAD_DEBIAN" == true ]] && [[ "$SOURCE_FORMAT" == *"native"* ]] && [[ fi elif [[ "$CHANGELOG_VERSION" =~ ^([0-9.]+)(-([0-9]+))?$ ]]; then BASE_VERSION="${BASH_REMATCH[1]}" - NEW_VERSION="${BASE_VERSION}ppa1" - echo " Warning: Native format cannot have Debian revision, converting to PPA format: $CHANGELOG_VERSION -> $NEW_VERSION" + # Check if old DSC has ppa suffix even if changelog doesn't + if [[ "$OLD_DSC_VERSION" =~ ppa([0-9]+)$ ]]; then + OLD_PPA_NUM="${BASH_REMATCH[1]}" + NEW_PPA_NUM=$((OLD_PPA_NUM + 1)) + NEW_VERSION="${BASE_VERSION}ppa${NEW_PPA_NUM}" + echo " Incrementing PPA number from old DSC: $OLD_DSC_VERSION -> $NEW_VERSION" + else + NEW_VERSION="${BASE_VERSION}ppa1" + echo " Adding PPA number: $CHANGELOG_VERSION -> $NEW_VERSION" + fi else - NEW_VERSION="${CHANGELOG_VERSION}ppa1" - echo " Warning: Could not parse version format, appending ppa1: $CHANGELOG_VERSION -> $NEW_VERSION" + # Check if old DSC has ppa suffix for unknown formats + if [[ "$OLD_DSC_VERSION" =~ ppa([0-9]+)$ ]]; then + OLD_PPA_NUM="${BASH_REMATCH[1]}" + NEW_PPA_NUM=$((OLD_PPA_NUM + 1)) + NEW_VERSION="${CHANGELOG_VERSION}ppa${NEW_PPA_NUM}" + echo " Incrementing PPA number from old DSC: $OLD_DSC_VERSION -> $NEW_VERSION" + else + NEW_VERSION="${CHANGELOG_VERSION}ppa1" + echo " Warning: Could not parse version format, appending ppa1: $CHANGELOG_VERSION -> $NEW_VERSION" + fi fi if [[ -z "$SOURCE_DIR" ]] || [[ ! -d "$SOURCE_DIR" ]] || [[ ! -d "$SOURCE_DIR/debian" ]]; then diff --git a/distro/scripts/ppa-build.sh b/distro/scripts/ppa-build.sh index 3cd2f1c2..39164568 100755 --- a/distro/scripts/ppa-build.sh +++ b/distro/scripts/ppa-build.sh @@ -283,22 +283,29 @@ if [ "$IS_GIT_PACKAGE" = true ] && [ -n "$GIT_REPO" ]; then # Check if we're rebuilding the same commit (increment PPA number if so) BASE_VERSION="${UPSTREAM_VERSION}+git${GIT_COMMIT_COUNT}.${GIT_COMMIT_HASH}" CURRENT_VERSION=$(dpkg-parsechangelog -S Version 2>/dev/null || echo "") - PPA_NUM=1 - # If current version matches the base version, increment PPA number - # Escape special regex characters in BASE_VERSION for pattern matching - ESCAPED_BASE=$(echo "$BASE_VERSION" | sed 's/\./\\./g' | sed 's/+/\\+/g') - if [[ "$CURRENT_VERSION" =~ ^${ESCAPED_BASE}ppa([0-9]+)$ ]]; then - PPA_NUM=$((BASH_REMATCH[1] + 1)) - if [[ "$IS_MANUAL" == true ]]; then - info "Detected rebuild of same commit (current: $CURRENT_VERSION), incrementing PPA number to $PPA_NUM" - else - info "Detected rebuild of same commit (current: $CURRENT_VERSION). Not a manual run, skipping." - success "No changes needed (commit matches)." - exit 0 - fi + # Use REBUILD_RELEASE if provided, otherwise auto-increment + if [[ -n "${REBUILD_RELEASE:-}" ]]; then + PPA_NUM=$REBUILD_RELEASE + info "Using REBUILD_RELEASE=$REBUILD_RELEASE for PPA number" else - info "New commit or first build, using PPA number $PPA_NUM" + PPA_NUM=1 + + # If current version matches the base version, increment PPA number + # Escape special regex characters in BASE_VERSION for pattern matching + ESCAPED_BASE=$(echo "$BASE_VERSION" | sed 's/\./\\./g' | sed 's/+/\\+/g') + if [[ "$CURRENT_VERSION" =~ ^${ESCAPED_BASE}ppa([0-9]+)$ ]]; then + PPA_NUM=$((BASH_REMATCH[1] + 1)) + if [[ "$IS_MANUAL" == true ]]; then + info "Detected rebuild of same commit (current: $CURRENT_VERSION), incrementing PPA number to $PPA_NUM" + else + info "Detected rebuild of same commit (current: $CURRENT_VERSION). Not a manual run, skipping." + success "No changes needed (commit matches)." + exit 0 + fi + else + info "New commit or first build, using PPA number $PPA_NUM" + fi fi NEW_VERSION="${BASE_VERSION}ppa${PPA_NUM}" @@ -429,16 +436,23 @@ elif [ -n "$GIT_REPO" ]; then # Get current version to check if we need to increment PPA number CURRENT_VERSION=$(dpkg-parsechangelog -S Version 2>/dev/null || echo "") - PPA_NUM=1 + + # Use REBUILD_RELEASE if provided, otherwise auto-increment + if [[ -n "${REBUILD_RELEASE:-}" ]]; then + PPA_NUM=$REBUILD_RELEASE + info "Using REBUILD_RELEASE=$REBUILD_RELEASE for PPA number" + else + PPA_NUM=1 + fi if [[ "$SOURCE_FORMAT" == *"native"* ]]; then # Native format: 0.2.1ppa1 (no dash, no revision) BASE_VERSION="${LATEST_TAG}" # Check if we're rebuilding the same version (increment PPA number if so) - if [[ "$CURRENT_VERSION" =~ ^${LATEST_TAG}ppa([0-9]+)$ ]]; then + if [[ -z "${REBUILD_RELEASE:-}" ]] && [[ "$CURRENT_VERSION" =~ ^${LATEST_TAG}ppa([0-9]+)$ ]]; then PPA_NUM=$((BASH_REMATCH[1] + 1)) info "Detected rebuild of same version (current: $CURRENT_VERSION), incrementing PPA number to $PPA_NUM" - else + elif [[ -z "${REBUILD_RELEASE:-}" ]]; then info "New version or first build, using PPA number $PPA_NUM" fi NEW_VERSION="${BASE_VERSION}ppa${PPA_NUM}" @@ -447,7 +461,7 @@ elif [ -n "$GIT_REPO" ]; then BASE_VERSION="${LATEST_TAG}-1" # Check if we're rebuilding the same version (increment PPA number if so) ESCAPED_BASE=$(echo "$BASE_VERSION" | sed 's/\./\\./g' | sed 's/-/\\-/g') - if [[ "$CURRENT_VERSION" =~ ^${ESCAPED_BASE}ppa([0-9]+)$ ]]; then + if [[ -z "${REBUILD_RELEASE:-}" ]] && [[ "$CURRENT_VERSION" =~ ^${ESCAPED_BASE}ppa([0-9]+)$ ]]; then PPA_NUM=$((BASH_REMATCH[1] + 1)) if [[ "$IS_MANUAL" == true ]]; then info "Detected rebuild of same version (current: $CURRENT_VERSION), incrementing PPA number to $PPA_NUM" @@ -456,7 +470,7 @@ elif [ -n "$GIT_REPO" ]; then success "No changes needed (version matches)." exit 0 fi - else + elif [[ -z "${REBUILD_RELEASE:-}" ]]; then info "New version or first build, using PPA number $PPA_NUM" fi NEW_VERSION="${BASE_VERSION}ppa${PPA_NUM}"