-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_unity_version.sh
More file actions
40 lines (33 loc) · 1.24 KB
/
update_unity_version.sh
File metadata and controls
40 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
# This script is a shell-based custom updater for release-please.
# It reads/writes the bundleVersion in a Unity ProjectSettings.asset file.
#
# Usage (read): ./update_unity_version.sh <path_to_file>
# - Prints the current bundleVersion to stdout.
#
# Usage (write): ./update_unity_version.sh <path_to_file> <new_version>
# - Updates the bundleVersion in the file.
set -e # Exit immediately if a command exits with a non-zero status.
FILE_PATH="$1"
NEW_VERSION="$2"
if [ -z "$FILE_PATH" ]; then
echo "Error: Missing file path argument."
exit 1
fi
if [ ! -f "$FILE_PATH" ]; then
echo "Error: File not found at $FILE_PATH"
exit 1
fi
# --- Main Logic ---
if [ -n "$NEW_VERSION" ]; then
# --- WRITE MODE ---
# Use sed to find the line with "bundleVersion:" and replace everything
# after it with the new version. The '-i' flag edits the file in-place.
# The regex captures the "bundleVersion: " part and re-inserts it.
sed -i "s/\(bundleVersion:\s*\).*/\1$NEW_VERSION/" "$FILE_PATH"
echo "Successfully updated bundleVersion in $FILE_PATH to $NEW_VERSION"
else
# --- READ MODE ---
# Use grep to find the line, then sed to extract just the version string.
grep "bundleVersion:" "$FILE_PATH" | sed 's/.*bundleVersion:\s*//'
fi