|
| 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