-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathupdate_meta.sh
More file actions
executable file
·131 lines (108 loc) · 3.7 KB
/
update_meta.sh
File metadata and controls
executable file
·131 lines (108 loc) · 3.7 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
set -e
# Set env vars for local testing
export GITHUB_REF_NAME=${GITHUB_REF_NAME:-$(git branch --show-current)}
export VERSION=${VERSION:-$GITHUB_REF_NAME}
echo "=== Metadata Update Script ==="
echo "Current VERSION: $VERSION"
echo "GITHUB_REF_NAME: $GITHUB_REF_NAME"
# Validate version format
if [[ "$VERSION" == "dev" ]]; then
VERSION_CODE=0
echo "Dev version detected, VERSION_CODE set to 0"
elif [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+ ]]; then
NUM=$(echo "$VERSION" | sed 's/v//')
VERSION_CODE=$(echo "$NUM" | awk '{print int($1 * 1000)}')
echo "Release version: $VERSION, VERSION_CODE: $VERSION_CODE"
else
echo "ERROR: Invalid version format: $VERSION"
echo "Expected format: vX.Y or dev"
exit 1
fi
# Update JSON files
echo "Updating JSON files..."
python3 -c "
import json
import sys
import re
for suffix in ['-GUI', '-CLI']:
filename = f'update{suffix}.json'
try:
with open(filename) as f:
data = json.load(f)
data['version'] = '$VERSION'
data['versionCode'] = $VERSION_CODE
data['zipUrl'] = re.sub(r'/download/[^/]+/', f'/download/$VERSION/', data['zipUrl'])
with open(filename, 'w') as f:
json.dump(data, f, indent=2)
f.write('\n') # Add newline at end
print(f'Updated {filename}')
except FileNotFoundError:
print(f'Warning: {filename} not found', file=sys.stderr)
except Exception as e:
print(f'Error updating {filename}: {e}', file=sys.stderr)
sys.exit(1)
"
if [ $? -ne 0 ]; then
echo "ERROR: Failed to update JSON files"
exit 1
fi
# === Changelog Generation ===
echo ""
echo "=== Generating Changelog ==="
# Synchronize tags with remote (prune local, fetch all remote)
echo "Synchronizing tags with remote..."
git fetch origin --prune --prune-tags --tags 2>/dev/null || true
echo "Tags synchronized"
# Get all tags sorted by version
ALL_TAGS=$(git tag --sort=-version:refname)
echo "Available tags:"
echo "$ALL_TAGS"
# Get the previous tag (skip current version if it exists)
CURRENT_TAG="$VERSION"
PREV_TAG=$(echo "$ALL_TAGS" | grep -v "^${CURRENT_TAG}$" | head -1)
if [ -z "$PREV_TAG" ]; then
echo "No previous tag found - this is the first release"
RANGE_SPEC=""
else
echo "Previous tag: $PREV_TAG"
echo "Current tag: $CURRENT_TAG"
RANGE_SPEC="$PREV_TAG.."
fi
# Get commits from main branch only (from previous tag to HEAD, since current tag doesn't exist yet)
echo ""
echo "Getting commits from main branch..."
if [ -z "$RANGE_SPEC" ]; then
# First release - get all commits
ALL_COMMITS=$(git log origin/main --oneline --pretty=format:"- %s" 2>/dev/null || git log --oneline --pretty=format:"- %s")
else
# Get commits between previous tag and HEAD (current tag will be created during release)
# Use HEAD instead of CURRENT_TAG since the tag doesn't exist yet
ALL_COMMITS=$(git log --oneline --pretty=format:"- %s" ${PREV_TAG}..HEAD 2>/dev/null || echo "")
fi
# Filter out metadata update commits
ALL_COMMITS=$(echo "$ALL_COMMITS" | grep -v "Update metadata for" || echo "$ALL_COMMITS")
# Count commits
COMMIT_COUNT=$(echo "$ALL_COMMITS" | grep -c '^' || echo "0")
echo "Total unique commits: $COMMIT_COUNT"
if [ "$COMMIT_COUNT" -eq 0 ]; then
echo "Warning: No commits found between $PREV_TAG and current state"
ALL_COMMITS="- No changes recorded"
fi
# Generate new changelog (clear and recreate)
echo ""
echo "Writing new CHANGELOG.md..."
cat > CHANGELOG.md << EOF
# Changelog
## $VERSION ($(date +%Y-%m-%d))
$ALL_COMMITS
EOF
echo ""
echo "=== Metadata update complete ==="
echo "Updated files:"
echo " - update-GUI.json"
echo " - update-CLI.json"
echo " - CHANGELOG.md"
echo ""
echo "Changelog preview:"
head -n 20 CHANGELOG.md