Skip to content

Commit 808bcd6

Browse files
author
David Crow
committed
improve version utils
1 parent 90392a3 commit 808bcd6

File tree

2 files changed

+182
-40
lines changed

2 files changed

+182
-40
lines changed

scripts/lib/version_utils.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,86 @@ get_latest_release_version() {
6868

6969
echo "$result"
7070
}
71+
72+
# Get proxy version from a plugin's latest release
73+
# Uses GitHub API to fetch file contents from the release tag
74+
# Args: $1 = repo (e.g., "urbanairship/react-native-airship"), $2 = plugin type
75+
get_proxy_version_from_release() {
76+
local repo="$1"
77+
local plugin="$2"
78+
79+
# Get latest release tag
80+
local tag=$(gh api "repos/${repo}/releases/latest" --jq '.tag_name' 2>/dev/null)
81+
if [ -z "$tag" ]; then
82+
# Fallback to tags if no releases
83+
tag=$(gh api "repos/${repo}/tags" --jq '.[0].name' 2>/dev/null)
84+
fi
85+
86+
if [ -z "$tag" ]; then
87+
echo "0.0.0" # Default if no releases found
88+
return 0
89+
fi
90+
91+
# Fetch proxy version from appropriate file based on plugin type
92+
local proxy_version=""
93+
case "$plugin" in
94+
react-native)
95+
# From react-native-airship.podspec: s.dependency "AirshipFrameworkProxy", "X.Y.Z"
96+
proxy_version=$(gh api "repos/${repo}/contents/react-native-airship.podspec?ref=${tag}" \
97+
--jq '.content' 2>/dev/null | base64 -d | \
98+
grep -o 'AirshipFrameworkProxy.*"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"' | \
99+
grep -o '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*' | head -1)
100+
;;
101+
cordova)
102+
# From cordova-airship/plugin.xml: pod name="AirshipFrameworkProxy" spec="X.Y.Z"
103+
proxy_version=$(gh api "repos/${repo}/contents/cordova-airship/plugin.xml?ref=${tag}" \
104+
--jq '.content' 2>/dev/null | base64 -d | \
105+
grep -o 'AirshipFrameworkProxy.*spec="[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"' | \
106+
grep -o '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*' | head -1)
107+
;;
108+
flutter)
109+
# From ios/airship_flutter.podspec: s.dependency "AirshipFrameworkProxy", "X.Y.Z"
110+
proxy_version=$(gh api "repos/${repo}/contents/ios/airship_flutter.podspec?ref=${tag}" \
111+
--jq '.content' 2>/dev/null | base64 -d | \
112+
grep -o 'AirshipFrameworkProxy.*"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"' | \
113+
grep -o '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*' | head -1)
114+
;;
115+
capacitor)
116+
# From UaCapacitorAirship.podspec: s.dependency "AirshipFrameworkProxy", "X.Y.Z"
117+
proxy_version=$(gh api "repos/${repo}/contents/UaCapacitorAirship.podspec?ref=${tag}" \
118+
--jq '.content' 2>/dev/null | base64 -d | \
119+
grep -o 'AirshipFrameworkProxy.*"[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"' | \
120+
grep -o '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*' | head -1)
121+
;;
122+
esac
123+
124+
if [ -z "$proxy_version" ]; then
125+
echo "0.0.0" # Default if parsing failed
126+
else
127+
echo "$proxy_version"
128+
fi
129+
}
130+
131+
# Determine plugin bump type based on proxy major version change
132+
# Compares proxy version at plugin's last release vs current proxy version
133+
# Args: $1 = old proxy version, $2 = new proxy version
134+
determine_plugin_bump_type() {
135+
local old_proxy="$1"
136+
local new_proxy="$2"
137+
138+
IFS='.' read -r old_major old_minor old_patch <<< "$old_proxy"
139+
IFS='.' read -r new_major new_minor new_patch <<< "$new_proxy"
140+
141+
# Major version change in proxy = major bump for plugin
142+
if [ "$new_major" -gt "$old_major" ]; then
143+
echo "major"
144+
# Minor version change in proxy = minor bump for plugin
145+
elif [ "$new_minor" -gt "$old_minor" ]; then
146+
echo "minor"
147+
# Patch version change in proxy = patch bump for plugin
148+
elif [ "$new_patch" -gt "$old_patch" ]; then
149+
echo "patch"
150+
else
151+
echo "none"
152+
fi
153+
}

scripts/update_all_plugins.sh

Lines changed: 99 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,18 @@ should_skip_plugin() {
172172
}
173173

174174
# Check if a branch exists on remote
175+
# Returns: 0 if exists, 1 if doesn't exist, 2 on error
175176
branch_exists_remote() {
176177
local branch="$1"
177-
git ls-remote --heads origin "$branch" 2>/dev/null | grep -q "refs/heads/${branch}$"
178+
local output
179+
180+
output=$(git ls-remote --heads origin "$branch" 2>&1)
181+
if [ $? -ne 0 ]; then
182+
echo " ⚠️ Cannot check remote: $output" >&2
183+
return 2 # Error - caller should abort
184+
fi
185+
186+
echo "$output" | grep -q "refs/heads/${branch}$"
178187
}
179188

180189
# Check if a branch exists locally
@@ -186,6 +195,7 @@ branch_exists_local() {
186195
# Get unique branch name for the release
187196
# In test mode: release-X.Y.Z-test, release-X.Y.Z-test-2, release-X.Y.Z-test-3, ...
188197
# In non-test mode: release-X.Y.Z (fails if exists - real releases shouldn't have duplicates)
198+
# Returns: 0 success, 1 no available branch, 2 on error
189199
get_unique_branch_name() {
190200
local plugin="$1"
191201
local version="$2"
@@ -197,22 +207,29 @@ get_unique_branch_name() {
197207
local attempt=2
198208
local max_attempts=20
199209

200-
while branch_exists_remote "$candidate" || branch_exists_local "$candidate"; do
210+
while true; do
211+
branch_exists_remote "$candidate"
212+
local status=$?
213+
214+
[ $status -eq 2 ] && return 2 # Propagate error
215+
216+
if [ $status -eq 1 ] && ! branch_exists_local "$candidate"; then
217+
echo "$candidate"
218+
return 0
219+
fi
220+
201221
candidate="${base_name}-test-${attempt}"
202222
attempt=$((attempt + 1))
203-
if [ $attempt -gt $max_attempts ]; then
204-
echo ""
205-
return 1
206-
fi
223+
[ $attempt -gt $max_attempts ] && return 1
207224
done
208-
209-
echo "$candidate"
210225
else
211-
# Non-test mode: use base name, return empty if exists
212-
if branch_exists_remote "$base_name"; then
213-
echo ""
214-
return 1
215-
fi
226+
# Non-test mode: use base name, fail if exists
227+
branch_exists_remote "$base_name"
228+
local status=$?
229+
230+
[ $status -eq 2 ] && return 2 # Propagate error
231+
[ $status -eq 0 ] && return 1 # Branch exists
232+
216233
echo "$base_name"
217234
fi
218235
}
@@ -241,39 +258,47 @@ validate_inputs() {
241258
fi
242259
}
243260

244-
# Calculate new plugin versions
261+
# Calculate new plugin versions using smart proxy-based bumping
262+
# For each plugin:
263+
# 1. Get the plugin's latest release version
264+
# 2. Get the proxy version that release was built with
265+
# 3. Compare proxy major version changes to determine bump type
245266
calculate_plugin_versions() {
246-
echo -e "${BLUE}Calculating plugin versions...${NC}"
247-
248-
# Get current proxy version to determine bump type
249-
CURRENT_PROXY_VERSION=$(grep "s.version" "$REPO_ROOT/AirshipFrameworkProxy.podspec" | grep -o "[0-9]*\.[0-9]*\.[0-9]*")
250-
BUMP_TYPE=$(determine_bump_type "$CURRENT_PROXY_VERSION" "$PROXY_VERSION")
251-
252-
echo -e "Current proxy: ${BOLD}${CURRENT_PROXY_VERSION}${NC}"
253-
echo -e "New proxy: ${BOLD}${PROXY_VERSION}${NC}"
254-
echo -e "Bump type: ${BOLD}${BUMP_TYPE}${NC}"
267+
echo -e "${BLUE}Calculating plugin versions (smart proxy-based bumping)...${NC}"
255268
echo ""
256269

257-
if [ "$BUMP_TYPE" = "none" ]; then
258-
echo -e "${RED}Error: No version bump detected${NC}"
259-
exit 1
260-
fi
261-
262-
# Fetch latest versions for each plugin and calculate new versions
263270
for plugin in "${PLUGIN_KEYS[@]}"; do
264271
local repo=$(get_repo_name "$plugin")
272+
local full_repo="urbanairship/${repo}"
265273

266-
# Fetch latest version (uses shared function from version_utils.sh)
267-
local latest_version=$(get_latest_release_version "urbanairship/${repo}")
274+
# Get plugin's latest release version
275+
local latest_version=$(get_latest_release_version "$full_repo")
268276
if [ $? -ne 0 ] || [ -z "$latest_version" ]; then
269277
echo -e "${RED}Failed to fetch version for ${repo}${NC}"
270278
exit 1
271279
fi
272280

273-
IFS='.' read -r major minor patch <<< "$latest_version"
281+
# Get proxy version from that release
282+
local release_proxy_version=$(get_proxy_version_from_release "$full_repo" "$plugin")
283+
284+
echo -e "${BOLD}${plugin}${NC}"
285+
echo -e " Current version: ${latest_version}"
286+
echo -e " Release proxy: ${release_proxy_version}"
287+
echo -e " New proxy: ${PROXY_VERSION}"
288+
289+
# Determine bump type based on proxy version change
290+
local bump_type=$(determine_plugin_bump_type "$release_proxy_version" "$PROXY_VERSION")
274291

275-
# Apply bump type
276-
case "$BUMP_TYPE" in
292+
if [ "$bump_type" = "none" ]; then
293+
echo -e " Bump: ${YELLOW}none (skipping - already up to date)${NC}"
294+
set_new_version "$plugin" ""
295+
echo ""
296+
continue
297+
fi
298+
299+
# Apply bump to plugin version
300+
IFS='.' read -r major minor patch <<< "$latest_version"
301+
case "$bump_type" in
277302
major)
278303
major=$((major + 1))
279304
minor=0
@@ -290,9 +315,25 @@ calculate_plugin_versions() {
290315

291316
local new_version="${major}.${minor}.${patch}"
292317
set_new_version "$plugin" "$new_version"
293-
echo -e "${plugin}: ${latest_version}${BOLD}${new_version}${NC}"
318+
319+
echo -e " Bump: ${GREEN}${bump_type}${NC}"
320+
echo -e " New version: ${BOLD}${new_version}${NC}"
321+
echo ""
294322
done
295-
echo ""
323+
324+
# Check if any plugins need updating
325+
local any_update=false
326+
for plugin in "${PLUGIN_KEYS[@]}"; do
327+
if [ -n "$(get_new_version "$plugin")" ]; then
328+
any_update=true
329+
break
330+
fi
331+
done
332+
333+
if [ "$any_update" = false ]; then
334+
echo -e "${YELLOW}No plugins need updating - all are already on proxy ${PROXY_VERSION}${NC}"
335+
exit 0
336+
fi
296337
}
297338

298339
# Clone plugin repositories
@@ -524,6 +565,13 @@ update_plugin() {
524565
# Get unique branch name (handles test mode auto-increment)
525566
local branch_name
526567
branch_name=$(get_unique_branch_name "$plugin" "$plugin_version")
568+
local branch_status=$?
569+
570+
if [ $branch_status -eq 2 ]; then
571+
echo " ✗ Cannot verify branch availability (network/auth error)"
572+
echo " Fix the error above and retry"
573+
return 1
574+
fi
527575

528576
if [ -z "$branch_name" ]; then
529577
if [ "$TEST_MODE" = true ]; then
@@ -684,17 +732,24 @@ main() {
684732
# Disable exit-on-error for plugin updates so one failure doesn't kill all
685733
set +e
686734
for plugin in "${PLUGIN_KEYS[@]}"; do
687-
# Skip if plugin is disabled
735+
# Skip if plugin is disabled via CLI flag
688736
if should_skip_plugin "$plugin"; then
689737
set_pr_url "$plugin" "SKIPPED"
690738
continue
691739
fi
692740

741+
# Skip if no version update needed (empty version = already up to date)
742+
local plugin_version="$(get_new_version "$plugin")"
743+
if [ -z "$plugin_version" ]; then
744+
set_pr_url "$plugin" "UP-TO-DATE"
745+
continue
746+
fi
747+
693748
echo ""
694749

695750
# Update plugin (with error handling)
696751
local error_file=$(mktemp)
697-
if pr_url=$(update_plugin "$plugin" "$(get_new_version "$plugin")" "$WORK_DIR/$(get_repo_name "$plugin")" 2>"$error_file"); then
752+
if pr_url=$(update_plugin "$plugin" "$plugin_version" "$WORK_DIR/$(get_repo_name "$plugin")" 2>"$error_file"); then
698753
set_pr_url "$plugin" "$pr_url"
699754
echo -e " ${GREEN}✓ PR created: $pr_url${NC}"
700755
else
@@ -715,6 +770,7 @@ main() {
715770

716771
for plugin in "${PLUGIN_KEYS[@]}"; do
717772
local pr_url="$(get_pr_url "$plugin")"
773+
local plugin_version="$(get_new_version "$plugin")"
718774
local status_icon=""
719775
local color="$GREEN"
720776
if [ "$pr_url" = "FAILED" ]; then
@@ -723,8 +779,11 @@ main() {
723779
elif [ "$pr_url" = "SKIPPED" ]; then
724780
status_icon=""
725781
color="$YELLOW"
782+
elif [ "$pr_url" = "UP-TO-DATE" ]; then
783+
status_icon="="
784+
color="$BLUE"
726785
fi
727-
echo -e "${color}${status_icon} $(get_display_name "$plugin") $(get_new_version "$plugin"): ${pr_url}${NC}"
786+
echo -e "${color}${status_icon} $(get_display_name "$plugin") ${plugin_version:-current}: ${pr_url}${NC}"
728787
done
729788

730789
echo ""
@@ -737,7 +796,7 @@ main() {
737796
done
738797
fi
739798

740-
# Check if any plugins succeeded
799+
# Check if any plugins succeeded (UP-TO-DATE counts as success)
741800
local any_success=false
742801
for plugin in "${PLUGIN_KEYS[@]}"; do
743802
local url="$(get_pr_url "$plugin")"

0 commit comments

Comments
 (0)