Skip to content

Commit

Permalink
Update push_build script to select which version part to bump
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Aug 29, 2023
1 parent 935b672 commit 4851382
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 13 deletions.
57 changes: 54 additions & 3 deletions ci_scripts/ci_post_clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,62 @@ 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

# Cleanup trigger tag from origin
echo "Removing trigger tag $CI_TAG from origin"
git push $github_pat_repo_url --delete $CI_TAG

# Update Info.plist files
echo "Setting version to $newVersionString"
/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" ../ZShare/Info.plist
42 changes: 32 additions & 10 deletions scripts/push_build
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4851382

Please sign in to comment.