Files
deb-changelog-action/run.sh
Max P. eaa9ca9f45
All checks were successful
Auto Changelog & Release / release (push) Successful in 7s
feat(script): add script to generate Debian changelog locally
- Introduces a Bash script to clone a changelog action repository,
  install dependencies, and generate a Debian-style changelog
  in the current directory.
- Supports configurable options for tag, package name, author
  details, output file, and configuration file.
- Enhances local workflows by simplifying changelog generation.
2025-06-27 22:34:33 +02:00

88 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# run.sh – local wrapper for the “deb-changelog-action”
#
# This script
# 1. clones https://git.0xmax42.io/actions/deb-changelog-action at the
# requested tag into a temporary directory,
# 2. installs git-cliff using the action’s helper script, and
# 3. generates a Debian-style changelog **in the current working directory**
# via the action’s generator script.
#
# Usage:
# ./run.sh --tag v2.9.1 \
# --package_name mypkg \
# --author_name "Max Mustermann" \
# --author_email max@example.com \
# [--output_file debian/changelog] \
# [--cliff_config path/to/cliff.toml]
#
# Notes:
# • Paths given for --output_file are interpreted relative to the directory
# where you run this script.
# • If --cliff_config is omitted, the default config shipped with the action
# (configs/cliff.debian.toml) is used.
# • PACKAGE_NAME, AUTHOR_NAME, AUTHOR_EMAIL are exported so the TOML template
# can reference them (e.g. {{ get_env(name="PACKAGE_NAME") }}).
set -euo pipefail
REPO_URL="https://git.0xmax42.io/actions/deb-changelog-action"
# ───────────────────────────────────────────────
TAG=""
PACKAGE_NAME=""
AUTHOR_NAME=""
AUTHOR_EMAIL=""
OUTPUT_FILE="debian/changelog"
CLIFF_CONFIG=""
# ───────────────────────────────────────────────
show_help() { sed -n '2,25p' "$0"; }
# 1 ─ Parse CLI options ─────────────────────────
while [[ $# -gt 0 ]]; do
case "$1" in
--tag) TAG="$2"; shift 2 ;;
--package_name) PACKAGE_NAME="$2"; shift 2 ;;
--author_name) AUTHOR_NAME="$2"; shift 2 ;;
--author_email) AUTHOR_EMAIL="$2"; shift 2 ;;
--output_file) OUTPUT_FILE="$2"; shift 2 ;;
--cliff_config) CLIFF_CONFIG="$2"; shift 2 ;;
-h|--help) show_help; exit 0 ;;
*) echo "❌ Unknown option: $1"; show_help; exit 1 ;;
esac
done
# 2 ─ Validate mandatory inputs ────────────────
[[ -z "$TAG" ]] && { echo "❌ --tag is required"; exit 1; }
[[ -z "$PACKAGE_NAME" ]] && { echo "❌ --package_name is required"; exit 1; }
[[ -z "$AUTHOR_NAME" ]] && { echo "❌ --author_name is required"; exit 1; }
[[ -z "$AUTHOR_EMAIL" ]] && { echo "❌ --author_email is required"; exit 1; }
# 3 ─ Prepare temporary clone ──────────────────
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
echo "📥 Cloning ${REPO_URL}@${TAG}$TMP_DIR"
git clone --depth 1 --branch "$TAG" "$REPO_URL" "$TMP_DIR" >/dev/null
# 4 ─ Install git-cliff via helper script ──────
bash "$TMP_DIR/scripts/install-git-cliff.sh"
# 5 ─ Determine config path ────────────────────
if [[ -z "$CLIFF_CONFIG" ]]; then
CLIFF_CONFIG="$TMP_DIR/configs/cliff.debian.toml"
fi
[[ ! -r "$CLIFF_CONFIG" ]] && { echo "❌ Config not found: $CLIFF_CONFIG"; exit 1; }
# 6 ─ Export variables for the generator ───────
export PACKAGE_NAME AUTHOR_NAME AUTHOR_EMAIL
# 7 ─ Generate changelog in CURRENT dir ────────
echo "📝 Generating changelog (output → $OUTPUT_FILE)"
bash "$TMP_DIR/scripts/generate-changelog.sh" \
-c "$CLIFF_CONFIG" \
-t "$TAG" \
-o "$OUTPUT_FILE"
echo "✅ Changelog ready: $OUTPUT_FILE"