-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathupdate_version.sh
More file actions
executable file
·37 lines (26 loc) · 1.01 KB
/
Copy pathupdate_version.sh
File metadata and controls
executable file
·37 lines (26 loc) · 1.01 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_JS="script.js"
INDEX_HTML="index.html"
if [[ ! -f "$SCRIPT_JS" ]]; then
echo "Error: $SCRIPT_JS not found" >&2
exit 1
fi
if [[ ! -f "$INDEX_HTML" ]]; then
echo "Error: $INDEX_HTML not found" >&2
exit 1
fi
current_version=$(grep "^// Version" "$SCRIPT_JS" | sed 's/^\/\/ Version //')
if [[ ! $current_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Invalid version format '$current_version'. Expected major.minor.patch" >&2
exit 1
fi
IFS='.' read -r major minor patch <<< "$current_version"
new_patch=$((patch + 1))
new_version="$major.$minor.$new_patch"
echo "Updating version: $current_version -> $new_version"
sed -i.bak "s/^\/\/ Version .*/\/\/ Version $new_version/" "$SCRIPT_JS"
sed -i.bak "s/this\.version = '[^']*';/this.version = '$new_version';/" "$SCRIPT_JS"
sed -i.bak "s/Version [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*/Version $new_version/" "$INDEX_HTML"
rm -f "$SCRIPT_JS.bak" "$INDEX_HTML.bak"
echo "Version updated successfully!"