From 2ea72f84215eb0e42da5f12a7d1c10eb19cde444 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Tue, 29 Aug 2023 14:17:52 +0300 Subject: [PATCH] Update push_build script to select which version part to bump --- ci_scripts/ci_post_clone.sh | 62 ++++++++++++++++++++++++++++++++++--- scripts/push_build | 42 +++++++++++++++++++------ 2 files changed, 90 insertions(+), 14 deletions(-) diff --git a/ci_scripts/ci_post_clone.sh b/ci_scripts/ci_post_clone.sh index 4d6222848..2d97da5be 100755 --- a/ci_scripts/ci_post_clone.sh +++ b/ci_scripts/ci_post_clone.sh @@ -24,11 +24,65 @@ versionString=$(echo "$response" | jq -r '.data[0].attributes.versionString') if [[ "$versionString" == "null" ]]; then echo "Error: versionString is null" exit 1 +elif [[ ! "$versionString" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: versionString is not in 'major.minor.patch' format" + exit 1 fi -# Increment version string -newVersionString=$(awk -F. -v OFS=. '{$NF = $NF + 1; print}' <<< "$versionString") +bump_version() { + local version="$1" + local part="$2" + + # Split the version string into major, minor, and patch parts + IFS='.' read -r -a version_parts <<< "$version" + + case "$part" in + "major") + ((version_parts[0]++)) + version_parts[1]=0 + version_parts[2]=0 + ;; + "minor") + ((version_parts[1]++)) + version_parts[2]=0 + ;; + "patch") + ((version_parts[2]++)) + ;; + *) + echo "Error: Invalid version part $part" + exit 1 + ;; + esac + + echo "${version_parts[0]}.${version_parts[1]}.${version_parts[2]}" +} + +# Bump version string according to trigger tag +case "$CI_TAG" in + "trigger-build-bump-patch") + newVersionString=$(bump_version "$versionString" "patch") + ;; + "trigger-build-bump-minor") + newVersionString=$(bump_version "$versionString" "minor") + ;; + "trigger-build-bump-major") + newVersionString=$(bump_version "$versionString" "major") + ;; + *) + echo "Error: Invalid CI_TAG value $CI_TAG" + exit 1 + ;; +esac + +#test +echo "newVersionString = $newVersionString" + +# Cleanup trigger tag from origin +git push $github_pat_repo_url --delete $CI_TAG # Update Info.plist files -/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $newVersionString" ../Zotero/Info.plist -/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $newVersionString" ../ZShare/Info.plist +/usr/libexec/PlistBuddy -c "Set :CFBundleShortversionString $newVersionString" ../Zotero/Info.plist +/usr/libexec/PlistBuddy -c "Set :CFBundleShortversionString $newVersionString" ../ZShare/Info.plist + +exit 2 diff --git a/scripts/push_build b/scripts/push_build index 0bceaf553..c18a426eb 100755 --- a/scripts/push_build +++ b/scripts/push_build @@ -1,16 +1,38 @@ #!/bin/bash set -euo pipefail -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -ROOT_DIR="$(dirname "$SCRIPT_DIR")" +push_tag() { + TAG=$1 + git tag $TAG -m "$TAG" + git push origin $TAG + git tag -d $TAG + CURRENT_BRANCH=$(git symbolic-ref --short HEAD) + COMMIT=$(git log -n 1 --pretty=format:"%h") + echo "Pushed tag '$TAG' to branch '$CURRENT_BRANCH' at commit '$COMMIT'." +} -LAST_TAG=`git describe --tags $(git rev-list --tags --max-count=1)` -PARTS=(${LAST_TAG//-/ }) -NEW_VERSION=$(cat "$ROOT_DIR/Zotero.xcodeproj/project.pbxproj" | grep MARKETING_VERSION | head -n 1 | sed -E 's/.+([0-9]+\.[0-9]+\.[0-9]+).+/\1/') -NEW_BUILD=$((${PARTS[1]}+1)) +DEFAULT_TAG="trigger-build-bump-patch" -TAG="$NEW_VERSION-$NEW_BUILD" +if [ $# -eq 0 ]; then + TAG=$DEFAULT_TAG +else + case $1 in + "minor"|"major"|"patch") + TAG="trigger-build-bump-$1" + ;; + *) + echo "Invalid tag argument. Usage: $0 [patch (default)|minor|major]" + exit 1 + ;; + esac +fi -echo "Pushing tag: $TAG" -git tag -a ${TAG} -m "$TAG" -git push origin ${TAG} +if [ "$TAG" != "$DEFAULT_TAG" ]; then + read -p "Are you sure you want to push tag '$TAG'? (y/n): " choice + if [ "$choice" != "y" ]; then + echo "Operation canceled." + exit 0 + fi +fi + +push_tag $TAG \ No newline at end of file