build: make the release driver and Debian changelogs dependable

- The container release driver wrote rv=fail but returned success to
  CI. Run every selected target, keep its report line, and exit
  nonzero if any target fails or its builder can't run. A missing
  podman during --cleanup is reported per target instead of aborting
  the run. Reject a target name that matches no containerfile.
- --branch silently defaulted to master, and the tarball containerfile
  did too, so a release could package a moving branch instead of the
  intended tag. Require --branch and --git-repo for direct calls.
- Remove the static installer target. Its makeself command printed
  "foo", and it copied whatever static archives the output directory
  held, possibly from an older release or missing one built later in
  the same run. The static archives themselves are unchanged.
- git2debcl enumerated every tag and used symmetric differences, so a
  private tag could become a package version and commits from another
  branch could be listed. Take release and release-candidate tags
  reachable from the requested revision, ordered by version with each
  final after its candidates, with one-sided ranges between ancestor
  boundaries. Keep the requested version when tags share a revision or
  a range is empty. A tagless snapshot gets 0~git.<count>.<hash>; a
  shallow tagless checkout must give --version.
- Debian versions for candidates are printed as 2.42.0~~rc1, so dpkg
  orders them below the 2.42.0 final. The raw -rc1 form sorted above
  it, making the final release look like a downgrade.
- TEST_release_metadata covers the driver's results and arguments,
  sibling and merged histories, non-release tags, candidates,
  tagless and shallow checkouts, and dpkg version ordering.
- Document the static and release targets and the driver's arguments.
This commit is contained in:
Antonio SJ Musumeci 2026-11-25 13:36:10 -05:00
parent 181371d84c
commit 036246140b
6 changed files with 548 additions and 68 deletions

View file

@ -30,7 +30,9 @@ Generated debian/changelog from git log
Options:
--name NAME Name of package (required)
--version VERSION Place in git history to include upto (default: ::guess::)
--version VERSION Package version (default: infer from Git). If it names
a tag, end the changelog there; otherwise use HEAD.
Required in shallow clones with no reachable tag.
--distro DISTRO Distribution name (default: ::guess::)
--codename NAME Distribution codename (default: ::guess::)
--urgency URGENCY Urgency (default: medium)
@ -78,16 +80,28 @@ if [ -z "$NAME" ]; then
usage
fi
# Function to get git tags sorted in reverse order
# Function to get reachable release tags sorted in reverse version order.
# A final release sorts after its release candidates.
git_tags() {
git tag -l | sort -rV
local version_ref="$1"
git -c versionsort.suffix=-rc tag \
--merged "$version_ref" --sort=-version:refname --list |
grep -E '^[0-9]+([.][0-9]+)*(-rc[0-9]+)?$'
}
# Function to get git log between two tags
# Function to get git log reachable from totag but not fromtag
git_log() {
local fromtag="$1"
local totag="$2"
git log --no-merges --oneline "${fromtag}...${totag}" 2>/dev/null
git log --no-merges --oneline "${fromtag}..${totag}" 2>/dev/null
}
# dpkg splits a version at the last '-' and sorts '-' above '~', so
# printing an rc tag as 2.42.0-rc1~dist would compare above the final
# 2.42.0~dist release. Emit rc tags with a doubled '~' instead; tag
# lookups, ranges, and ordering keep the raw names.
deb_version() {
printf '%s\n' "$1" | sed 's/-rc/~~rc/'
}
# Function to get author and time for a tag
@ -98,7 +112,29 @@ git_author_and_time() {
# Function to get git version
git_version() {
git describe --always --tags --dirty 2>/dev/null || echo "unknown"
# Empty match prevents describe from considering tags when none are
# eligible. Every other match is an exact reachable release tag.
set -- --match ''
while IFS= read -r tag; do
if [ -n "$tag" ]; then
set -- "$@" --match "$tag"
fi
done <<EOF
$(git_tags HEAD)
EOF
git describe --tags --dirty "$@" 2>/dev/null || {
commit=$(git rev-parse --short HEAD) || return 1
if [ "$(git rev-parse --is-shallow-repository)" != false ]; then
echo "Error: tagless snapshots need full history; fetch it or specify --version" >&2
return 1
fi
count=$(git rev-list --count HEAD) || return 1
if ! git diff --quiet 2>/dev/null ||
! git diff --cached --quiet 2>/dev/null; then
commit="${commit}-dirty"
fi
printf '0~git.%s.%s\n' "$count" "$commit"
}
}
# Function to guess distribution
@ -129,28 +165,50 @@ if [ "$CODENAME" = "::guess::" ]; then
fi
if [ "$VERSION" = "::guess::" ]; then
VERSION=$(git_version)
VERSION=$(git_version) || exit 1
fi
# Version suffix
VERSUFFIX="~${DISTRO}-${CODENAME}"
# Get all tags
TAGS=$(git_tags)
# If version names a tag, end the changelog there; otherwise use HEAD.
if git rev-parse --verify "refs/tags/${VERSION}^{commit}" >/dev/null 2>&1; then
VERSION_REF="$VERSION"
else
VERSION_REF=HEAD
fi
# Create temporary file for tag pairs
# A requested tag may have history even when HEAD is unborn.
git rev-parse --verify "${VERSION_REF}^{commit}" >/dev/null || exit 1
# Only release tags reachable from the requested ref are eligible.
TAGS=$(git_tags "$VERSION_REF")
# Create temporary file for tag pairs. The first line also covers an explicit
# version on an untagged HEAD and a requested non-release tag.
TMPFILE=$(mktemp)
trap 'rm -f "$TMPFILE"' EXIT
{
printf '%s %s\n' "$VERSION" "$VERSION_REF"
printf '%s\n' "$TAGS"
} > "$TMPFILE"
# Check if version is in tags
if echo "$TAGS" | grep -q "^${VERSION}$"; then
# If version is a tag, start from that tag
echo "$TAGS" | awk -v ver="$VERSION" 'BEGIN{found=0} {if($0==ver)found=1; if(found)print}' > "$TMPFILE"
else
# If version is not a tag, use HEAD as starting point
echo "$VERSION HEAD" > "$TMPFILE"
echo "$TAGS" >> "$TMPFILE"
fi
# Print one changelog entry: header, log lines, then author and time
print_entry() {
local tag="$1"
local ref="$2"
local entries="$3"
printf "%s (%s%s) %s; urgency=%s\n\n" "$NAME" "$(deb_version "$tag")" "$VERSUFFIX" "$CODENAME" "$URGENCY"
echo "$entries" | while IFS= read -r entry; do
if [ -n "$entry" ]; then
printf " * %s\n" "$entry"
fi
done
printf "\n %s\n\n" "$(git_author_and_time "$ref")"
}
# Process tags and generate changelog
PREV_TAG=""
@ -162,41 +220,41 @@ while IFS= read -r line; do
continue
fi
# Handle the special case of VERSION HEAD
if [ "$line" = "$VERSION HEAD" ]; then
# Handle the requested version and ref on the first line
if [ "$line" = "$VERSION $VERSION_REF" ]; then
TAG="$VERSION"
REF="HEAD"
REF="$VERSION_REF"
else
TAG="$line"
REF="$line"
fi
if [ -n "$PREV_TAG" ]; then
# Get log entries between current and previous tag
LOG_ENTRIES=$(git_log "$REF" "$PREV_REF")
# Skip if no changes
if [ -z "$LOG_ENTRIES" ] || [ "$LOG_ENTRIES" = "" ]; then
PREV_TAG="$TAG"
PREV_REF="$REF"
# Version order does not make sibling tags comparable. Skip this
# boundary and keep the newer tag for an actual ancestor.
if ! git merge-base --is-ancestor "$REF" "$PREV_REF"; then
continue
fi
# Print package header
printf "%s (%s%s) %s; urgency=%s\n\n" "$NAME" "$PREV_TAG" "$VERSUFFIX" "$CODENAME" "$URGENCY"
# Get log entries between current and previous tag
LOG_ENTRIES=$(git_log "$REF" "$PREV_REF")
# Print each log entry
echo "$LOG_ENTRIES" | while IFS= read -r entry; do
if [ -n "$entry" ]; then
printf " * %s\n" "$entry"
fi
done
# Tags at the same revision have no changes between them. Keep the
# newer version for the next nonempty range.
if [ -z "$LOG_ENTRIES" ]; then
continue
fi
# Print author and time
AUTHOR_TIME=$(git_author_and_time "$PREV_REF")
printf "\n %s\n\n" "$AUTHOR_TIME"
print_entry "$PREV_TAG" "$PREV_REF" "$LOG_ENTRIES"
FIRST=0
fi
PREV_TAG="$TAG"
PREV_REF="$REF"
done < "$TMPFILE"
# If no tag range produced an entry, list the requested version's history.
if [ "$FIRST" = 1 ]; then
LOG_ENTRIES=$(git log --no-merges --oneline "$VERSION_REF" --) || exit 1
print_entry "$VERSION" "$VERSION_REF" "$LOG_ENTRIES"
fi