Files
deb-changelog-action/scripts/generate-changelog.sh
Max P. ba7b9f2928
All checks were successful
Auto Changelog & Release / release (push) Successful in 8s
feat: modularize scripts and improve project architecture
- Added `lib/utils.sh` and `lib/logging.sh` for reusable utility and logging functions.
- Updated `run.sh` and `scripts/generate-changelog.sh` to use the new utility and logging functions (`validate_arg`, `log_info`, `log_error`).
- Add `config.env` for better clarity and updated all references in the project.
- Enhanced documentation in `README.md` to reflect the new configuration file and usage instructions.
- Improved error handling and logging consistency across scripts.
2025-07-02 12:59:16 +02:00

66 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# generate-changelog.sh – generates a Debian-style changelog via git-cliff
#
# Usage:
# ./generate-changelog.sh -c cliff.debian.toml -t v2.9.1 -o debian/changelog
#
# Options:
# -c, --config <file> Path to a valid git-cliff config file (required)
# -t, --tag <tag> Git tag used as the starting point for the changelog (required)
# -o, --out <file> Target changelog file to write to (required, unless --debug)
# -d, --debug Print changelog to stdout instead of writing the file
# -h, --help Show this help message
#
# Behaviour:
# • Verifies git-cliff, sed, and git are installed.
# • Checks that the config file exists and is readable.
# • Ensures the parent directory of the output file exists (unless --debug).
# • Generates the changelog; removes a leading empty line.
set -euo pipefail
# ───────────────────────────────────────────────
CONFIG_FILE=""
TAG=""
OUT_FILE=""
DEBUG=false
# ───────────────────────────────────────────────
show_help() { sed -n '2,18p' "$0"; }
# 1 Parse CLI options
while [[ $# -gt 0 ]]; do
case "$1" in
-c|--config) [[ $# -lt 2 ]] && { echo "$1 requires a value"; exit 1; }; CONFIG_FILE="$2"; shift 2 ;;
-t|--tag) [[ $# -lt 2 ]] && { echo "$1 requires a value"; exit 1; }; TAG="$2"; shift 2 ;;
-o|--out) [[ $# -lt 2 ]] && { echo "$1 requires a value"; exit 1; }; OUT_FILE="$2"; shift 2 ;;
-d|--debug) DEBUG=true; shift ;;
-h|--help) show_help; exit 0 ;;
*) echo "❌ Unknown option: $1"; show_help; exit 1 ;;
esac
done
# 2 Basic validation
[[ -z "$CONFIG_FILE" || -z "$TAG" ]] && { echo "❌ --config and --tag are required"; show_help; exit 1; }
[[ "$DEBUG" = false && -z "$OUT_FILE" ]] && { echo "❌ --out is required unless --debug is set"; show_help; exit 1; }
[[ ! -r "$CONFIG_FILE" ]] && { log_error "Config file not found or unreadable: $CONFIG_FILE"; exit 1; }
if [[ "$DEBUG" = false ]]; then
OUT_DIR=$(dirname "$OUT_FILE")
[[ ! -d "$OUT_DIR" ]] && { log_error "Output directory does not exist: $OUT_DIR"; exit 1; }
fi
# 3 Required tools
need() { command -v "$1" >/dev/null || { echo "$1 is required but not installed"; exit 1; }; }
source "$(dirname "$0")/../lib/utils.sh"
source "$(dirname "$0")/../lib/logging.sh"
need git; need git-cliff; need sed
# 4 Generate changelog
if $DEBUG; then
log_info "Generating changelog (debug mode – stdout only)"
git cliff --config "$CONFIG_FILE" -t "$TAG" -s all
else
log_info "Generating changelog → $OUT_FILE"
git cliff --config "$CONFIG_FILE" -t "$TAG" -s all > "$OUT_FILE"
log_info "Changelog written to $OUT_FILE"
fi