Skip to content

Commit a514c49

Browse files
authored
Merge pull request slgobinath#764 from archisman-panigrahi/version-updater
Version updater
2 parents 02ac820 + 144b40d commit a514c49

File tree

2 files changed

+115
-2
lines changed

2 files changed

+115
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,13 @@ The available dependency groups can be found in the `pyproject.toml` file.
220220
0. Run `update-po.sh` to generate new translation files (which will be eventually updated by translators). Commit and push the changes to the master branch.
221221
1. Checkout the latest commits from the `master` branch
222222
2. Run `python3 -m safeeyes` to make sure nothing is broken
223-
3. Update the Safe Eyes version in the following places (Open the project in VSCode and search for the current version):
223+
3. Update the Safe Eyes version. Run `./update-version.sh "version.number.number" "New version with shiny new feature"`.
224+
To manually change the version number, update the following places (Open the project in VSCode and search for the current version):
224225
- [pyproject.toml](https://github.com/slgobinath/SafeEyes/blob/master/pyproject.toml#L4)
225226
- [pyproject.toml](https://github.com/slgobinath/SafeEyes/blob/master/pyproject.toml#L35)
226227
- [io.github.slgobinath.SafeEyes.metainfo.xml](https://github.com/slgobinath/SafeEyes/blob/master/safeeyes/platform/io.github.slgobinath.SafeEyes.metainfo.xml#L56)
227228
- [about_dialog.glade](https://github.com/slgobinath/SafeEyes/blob/master/safeeyes/glade/about_dialog.glade#L74)
228-
4. Update the [changelog](https://github.com/slgobinath/SafeEyes/blob/master/debian/changelog) (for Ubuntu PPA release)
229+
4. Update the [changelog](https://github.com/slgobinath/SafeEyes/blob/master/debian/changelog) (for Ubuntu PPA release). *This is automated* if you use the `./update-version.sh` script mentioned above, but you may want to manually add more lines to describe what's new in this release.
229230
5. Commit the changes to `master`
230231
6. Create a pull-request from `master` to `release`
231232
7. Merge the PR to release **with merge commit** (Important to merge with merge commit)

update-version.sh

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
usage() {
5+
echo "Usage: $0 \"version.number\" \"release-message\""
6+
exit 2
7+
}
8+
9+
if [ "$#" -ne 2 ]; then
10+
usage
11+
fi
12+
13+
version="$1"
14+
message="$2"
15+
16+
# Validate version format (allow x.y or x.y.z)
17+
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?$ ]]; then
18+
echo "Warning: Version '$version' does not match the standard format x.y or x.y.z."
19+
echo "Please validate the version number manually."
20+
read -p "Do you want to continue? [y/N]: " confirm
21+
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
22+
echo "Aborted by user."
23+
exit 10
24+
fi
25+
fi
26+
27+
CHANGELOG="debian/changelog"
28+
METAFILE="safeeyes/platform/io.github.slgobinath.SafeEyes.metainfo.xml"
29+
PYPROJECT="pyproject.toml"
30+
31+
if [ ! -f "$CHANGELOG" ]; then
32+
echo "Error: $CHANGELOG not found." >&2
33+
exit 1
34+
fi
35+
if [ ! -f "$METAFILE" ]; then
36+
echo "Error: $METAFILE not found." >&2
37+
exit 1
38+
fi
39+
40+
# Build maintainer from Git config (do not read debian/control)
41+
# Prefer git user.name and user.email; fall back to sensible defaults
42+
name=$(git config user.name || echo "Unknown")
43+
email=$(git config user.email || echo "[email protected]")
44+
maintainer="$name <$email>"
45+
46+
47+
# Dates
48+
rfc_date=$(date -u '+%a, %d %b %Y %H:%M:%S +0000')
49+
iso_date=$(date -u '+%Y-%m-%d')
50+
51+
# Determine distribution string from existing changelog first entry, fallback to 'noble'
52+
dist=$(sed -n '1,120p' "$CHANGELOG" | grep -m1 '^safeeyes (' | sed -n 's/.*) \([^;]*\);.*/\1/p' || true)
53+
if [ -z "$dist" ]; then
54+
dist="noble"
55+
fi
56+
57+
# Safety checks: do not add duplicate entries
58+
if grep -qF "safeeyes ($version)" "$CHANGELOG" 2>/dev/null; then
59+
echo "Changelog already contains an entry for version $version; aborting." >&2
60+
exit 3
61+
fi
62+
if grep -q "version=\"$version\"" "$METAFILE"; then
63+
echo "Metainfo already contains a release element for version $version; aborting." >&2
64+
exit 4
65+
fi
66+
67+
# Update pyproject.toml version and Downloads URL if file exists
68+
if [ -f "$PYPROJECT" ]; then
69+
# Replace version = "..."
70+
sed -i "s/^version = \".*\"/version = \"$version\"/" "$PYPROJECT"
71+
# Set Downloads to canonical GitHub archive URL for this version
72+
# Use a stable URL: https://github.com/slgobinath/SafeEyes/archive/v<version>.tar.gz
73+
sed -i "s#^[[:space:]]*Downloads = \".*\"#Downloads = \"https://github.com/slgobinath/SafeEyes/archive/v$version.tar.gz\"#" "$PYPROJECT" || true
74+
echo "Updated $PYPROJECT"
75+
fi
76+
77+
# Update glade about dialog label if present
78+
GLADE_ABOUT="safeeyes/glade/about_dialog.glade"
79+
if [ -f "$GLADE_ABOUT" ]; then
80+
# replace 'Safe Eyes x.y.z' inside <property name="label">...<
81+
sed -i "s/\(<property name=\"label\">Safe Eyes \).*\(<\/property>\)/\1$version\2/" "$GLADE_ABOUT" || true
82+
echo "Updated $GLADE_ABOUT"
83+
fi
84+
85+
86+
87+
# Prepend changelog entry (Debian format)
88+
tmpfile=$(mktemp)
89+
cat > "$tmpfile" <<EOF
90+
safeeyes ($version) $dist; urgency=medium
91+
92+
* $message
93+
94+
-- $maintainer $rfc_date
95+
96+
EOF
97+
98+
cat "$tmpfile" "$CHANGELOG" > "$CHANGELOG.new" && mv "$CHANGELOG.new" "$CHANGELOG"
99+
rm -f "$tmpfile"
100+
echo "Updated $CHANGELOG"
101+
102+
# Insert release element as the first child under <releases>
103+
# Keep indentation consistent with project file (8 spaces for release lines)
104+
awk -v ver="$version" -v iso="$iso_date" '
105+
/^[[:space:]]*<releases>[[:space:]]*$/ { print; printf " <release version=\"%s\" date=\"%s\" />\n", ver, iso; next }
106+
{ print }
107+
' "$METAFILE" > "$METAFILE.new" && mv "$METAFILE.new" "$METAFILE"
108+
echo "Updated $METAFILE"
109+
110+
echo "Updated $CHANGELOG and $METAFILE"
111+
112+
exit 0

0 commit comments

Comments
 (0)