|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Update or create debian/changelog using dch. |
| 4 | +# Usage: |
| 5 | +# scripts/debian-changelog-update.sh [--version VERSION] [--message MSG] [--distribution DIST] [--help] |
| 6 | +# |
| 7 | +# Behavior: |
| 8 | +# - If --version is provided, set that exact Debian version (e.g., 1.2.3-1). |
| 9 | +# - If not provided, auto-bump the Debian revision for the upstream version |
| 10 | +# found in the existing changelog; if no changelog exists, requires --version. |
| 11 | +# - If --distribution is not provided, defaults to "unstable". |
| 12 | + |
| 13 | +set -euo pipefail |
| 14 | + |
| 15 | +REPO_ROOT=${GITHUB_WORKSPACE:-$(git rev-parse --show-toplevel)} |
| 16 | +cd "$REPO_ROOT" |
| 17 | + |
| 18 | +PKG_NAME="libwolfprov" |
| 19 | +DEBFULLNAME="${DEBFULLNAME:-WolfSSL Developer}" |
| 20 | +DEBEMAIL="${DEBEMAIL:-support@wolfssl.com}" |
| 21 | +export DEBFULLNAME DEBEMAIL |
| 22 | + |
| 23 | +explicit_version="" |
| 24 | +message="Release" |
| 25 | +distribution="unstable" |
| 26 | + |
| 27 | +print_help() { |
| 28 | + cat <<EOF |
| 29 | +Update or create debian/changelog using dch. |
| 30 | +
|
| 31 | +Usage: |
| 32 | + scripts/debian-changelog-update.sh [--version VERSION] [--message MSG] [--distribution DIST] |
| 33 | +
|
| 34 | +Options: |
| 35 | + --version VERSION Set exact Debian version (e.g., 1.2.3-1). If omitted, auto-bump Debian revision. |
| 36 | + --message MSG Changelog message prefix. Default: "Release". |
| 37 | + --distribution DIST Target distribution for dch. Default: "unstable". |
| 38 | + --help Show this help and exit. |
| 39 | +
|
| 40 | +Examples: |
| 41 | + # Create or update changelog with explicit version for bookworm |
| 42 | + scripts/debian-changelog-update.sh --version 1.2.3-1 --distribution bookworm --message "Release" |
| 43 | +
|
| 44 | + # Auto-bump Debian revision in existing changelog for unstable |
| 45 | + scripts/debian-changelog-update.sh --message "Nightly build" --distribution unstable |
| 46 | +EOF |
| 47 | +} |
| 48 | + |
| 49 | +while [[ $# -gt 0 ]]; do |
| 50 | + case "$1" in |
| 51 | + --version) |
| 52 | + explicit_version="$2"; shift 2 ;; |
| 53 | + --message) |
| 54 | + message="$2"; shift 2 ;; |
| 55 | + --distribution) |
| 56 | + distribution="$2"; shift 2 ;; |
| 57 | + --help) |
| 58 | + print_help; exit 0 ;; |
| 59 | + *) |
| 60 | + echo "Unknown argument: $1" >&2; exit 2 ;; |
| 61 | + esac |
| 62 | +done |
| 63 | + |
| 64 | +mkdir -p debian |
| 65 | + |
| 66 | +if [[ -n "$explicit_version" ]]; then |
| 67 | + # Validate explicit version for non-native packages: must include Debian revision (e.g., -1) |
| 68 | + format="" |
| 69 | + if [[ -f debian/source/format ]]; then |
| 70 | + format="$(head -n1 debian/source/format || true)" |
| 71 | + fi |
| 72 | + if [[ "$format" != "3.0 (native)" ]]; then |
| 73 | + # If there is no dash, assume missing Debian revision and provide a suggestion |
| 74 | + if [[ "$explicit_version" == "${explicit_version%%-*}" ]]; then |
| 75 | + echo "❌ Non-native package version must include a Debian revision (e.g., -1)." >&2 |
| 76 | + echo " Provided: $explicit_version" >&2 |
| 77 | + echo " Suggested: ${explicit_version}-1" >&2 |
| 78 | + exit 2 |
| 79 | + fi |
| 80 | + fi |
| 81 | + |
| 82 | + if [[ -f debian/changelog ]]; then |
| 83 | + dch -v "$explicit_version" --distribution "$distribution" --urgency=medium "$message version $explicit_version" |
| 84 | + else |
| 85 | + dch --create -v "$explicit_version" --package "$PKG_NAME" \ |
| 86 | + --distribution "$distribution" --urgency=medium "$message version $explicit_version" |
| 87 | + fi |
| 88 | + echo "Updated changelog to version $explicit_version" |
| 89 | + exit 0 |
| 90 | +fi |
| 91 | + |
| 92 | +# No explicit version provided. Attempt to auto-bump Debian revision. |
| 93 | +if [[ ! -f debian/changelog ]]; then |
| 94 | + echo "❌ debian/changelog does not exist. Provide --version to create it." >&2 |
| 95 | + exit 1 |
| 96 | +fi |
| 97 | + |
| 98 | +current_version=$(dpkg-parsechangelog --show-field Version) |
| 99 | +upstream_version="${current_version%%-*}" |
| 100 | +current_rev="${current_version##*-}" |
| 101 | + |
| 102 | +if [[ "$current_version" == "$upstream_version" ]]; then |
| 103 | + # No Debian revision part present; start at -1 |
| 104 | + new_version="${upstream_version}-1" |
| 105 | +else |
| 106 | + if [[ "$current_rev" =~ ^[0-9]+$ ]]; then |
| 107 | + new_rev=$((current_rev + 1)) |
| 108 | + else |
| 109 | + echo "❌ Could not parse Debian revision from version: $current_version" >&2 |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | + new_version="${upstream_version}-${new_rev}" |
| 113 | +fi |
| 114 | + |
| 115 | +dch -v "$new_version" --distribution "$distribution" --urgency=medium "$message version $new_version" |
| 116 | +echo "Bumped changelog version to $new_version" |
| 117 | + |
| 118 | + |
0 commit comments