-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathupdate_metadata.sh
executable file
·87 lines (71 loc) · 2.64 KB
/
update_metadata.sh
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
#!/bin/sh
changelog_file="CHANGELOG.md"
output_dir="metadata/en-US/changelogs"
temp_dir="$output_dir/temp"
metainfo_file="metadata/io.naox.InnerBreeze.metainfo.xml"
# Create output and temporary directories if they don't exist
mkdir -p "$output_dir"
mkdir -p "$temp_dir"
# Initialize variables
version_number=0
inside_version=0
output=""
xml_output=""
xml_releases=""
# Read the changelog file line by line
while IFS= read -r line
do
if [[ $line =~ ^\#\#\ \[(.*)\]\ -\ (.*)$ ]]; then
if [[ $inside_version -eq 1 ]]; then
version_number=$((version_number+1))
echo -e "$output" > "$temp_dir/$version_number.txt"
xml_releases+=" <release version=\"$version\" date=\"$date\">\n"
xml_releases+=" <description>\n <ul>\n"
xml_releases+="$xml_output"
xml_releases+=" </ul>\n </description>\n"
xml_releases+=" </release>\n"
output=""
xml_output=""
fi
inside_version=1
version="${BASH_REMATCH[1]}"
date="${BASH_REMATCH[2]}"
elif [[ $inside_version -eq 1 ]]; then
if [[ $line =~ ^- ]]; then
list_item="${line:2}"
output+="* $list_item\n"
xml_output+=" <li>$list_item</li>\n"
fi
fi
done < "$changelog_file"
if [[ -n $output ]]; then
version_number=$((version_number+1))
echo -e "$output" > "$temp_dir/$version_number.txt"
xml_releases+=" <release version=\"$version\" date=\"$date\">\n"
xml_releases+=" <description>\n <ul>\n"
xml_releases+="$xml_output"
xml_releases+=" </ul>\n </description>\n"
xml_releases+=" </release>\n"
fi
highest_version=$version_number
for ((i=1; i<=highest_version; i++)); do
target_version=$((highest_version - i + 1))
mv "$temp_dir/$i.txt" "$output_dir/$target_version.txt"
done
rm -rf "$temp_dir"
cp "$metainfo_file" "$metainfo_file.bak"
# Update release version
sed -i "/<releases>/,/<\/releases>/c\<releases>\n$xml_releases<\/releases>" "$metainfo_file"
latest_version=$(grep -m 1 '## \[' "$changelog_file" | sed -n 's/## \[\(.*\)\] - .*/\1/p')
if [ -z "$latest_version" ]; then
echo "No version found in changelog"
exit 1
fi
echo "Latest version from changelog: $latest_version"
pubspec_file="pubspec.yaml"
if [ -f "$pubspec_file" ]; then
sed -i "s/^version: .*/version: $latest_version+$version_number/" "$pubspec_file"
echo "Updated version in $pubspec_file to $latest_version+$version_number"
else
echo "$pubspec_file does not exist"
fi