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 6af8ec4
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 18 deletions.
69 changes: 61 additions & 8 deletions ci_scripts/ci_post_clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,69 @@ pip3 install joserfc
jwt_token=$(./generate_jtw_token.py)

# App Store Connect API request
response=$(curl -s --header "Authorization: Bearer $jwt_token" "https://api.appstoreconnect.apple.com/v1/apps/$zotero_app_id/appStoreVersions?filter%5BappStoreState%5D=READY_FOR_SALE&fields%5BappStoreVersions%5D=versionString")
versionString=$(echo "$response" | jq -r '.data[0].attributes.versionString')
if [[ "$versionString" == "null" ]]; then
echo "Error: versionString is null"
response=$(curl -s --header "Authorization: Bearer $jwt_token" "https://api.appstoreconnect.apple.com/v1/apps/$zotero_app_id/appStoreVersions?filter%5BappStoreState%5D=READY_FOR_SALE&fields%5BappStoreVersions%5D=version_string")
version_string=$(echo "$response" | jq -r '.data[0].attributes.versionString')
if [[ "$version_string" == "null" ]]; then
echo "Error: version_string is null"
exit 1
elif [[ ! "$version_string" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: version_string 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")
new_version_string=$(increment_version "$version_string" "patch")
;;
"trigger-build-bump-minor")
new_version_string=$(increment_version "$version_string" "minor")
;;
"trigger-build-bump-major")
new_version_string=$(increment_version "$version_string" "major")
;;
*)
echo "Error: Invalid CI_TAG value $CI_TAG"
exit 1
;;
esac

# Cleanup trigger tag from origin
git push origin --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 :CFBundleShortversion_string $new_version_string" ../Zotero/Info.plist
/usr/libexec/PlistBuddy -c "Set :CFBundleShortversion_string $new_version_string" ../ZShare/Info.plist

#test
echo "new_version_string = $new_version_string"
exit 2
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 6af8ec4

Please sign in to comment.