Files
deb-changelog-action/run.sh
Max P. fd29805fa1
All checks were successful
Auto Changelog & Release / release (push) Successful in 7s
docs(run.sh): update script documentation and help output
- Improve script documentation for clarity and consistency
- Extend help output to include detailed descriptions of options
2025-07-02 13:56:09 +02:00

101 lines
4.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# run.sh – local wrapper for the “deb-changelog-action”
#
# Behaviour:
# • Clones https://git.0xmax42.io/actions/deb-changelog-action at the requested version into a temporary directory.
# • Installs git-cliff via the action’s helper script.
# • Generates a Debian-style changelog **in the current working directory** via the action’s generator script.
#
# Usage:
# ./run.sh --version v0 \
# --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]
#
# Options:
# --version <ver> Action version to clone (required)
# --tag <tag> Git tag used as starting point (required)
# --package_name <name> Debian package name (required)
# --author_name <name> Changelog author name (required)
# --author_email <mail> Changelog author e-mail (required)
# --output_file <file> Changelog path (default: debian/changelog)
# --cliff_config <file> git-cliff config file (default: configs/cliff.debian.toml)
# -h, --help Show this help message
#
# 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"
# ───────────────────────────────────────────────
VERSION=""
TAG=""
PACKAGE_NAME=""
AUTHOR_NAME=""
AUTHOR_EMAIL=""
OUTPUT_FILE="debian/changelog"
CLIFF_CONFIG=""
# ───────────────────────────────────────────────
show_help() { sed -n '2,34p' "$0"; }
# 1 ─ Parse CLI options ─────────────────────────
while [[ $# -gt 0 ]]; do
case "$1" in
--version) VERSION="$2"; shift 2 ;;
--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 "$VERSION" ]] && { echo "❌ --version is required"; exit 1; }
[[ -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}@${VERSION}$TMP_DIR"
git clone --depth 1 --branch "$VERSION" "$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 ─ Generate changelog in CURRENT dir ────────
echo "📝 Generating changelog (output → $OUTPUT_FILE)"
env \
PACKAGE_NAME="$PACKAGE_NAME" \
AUTHOR_NAME="$AUTHOR_NAME" \
AUTHOR_EMAIL="$AUTHOR_EMAIL" \
bash "$TMP_DIR/scripts/generate-changelog.sh" \
-c "$CLIFF_CONFIG" \
-t "$TAG" \
-o "$OUTPUT_FILE"
echo "✅ Changelog ready: $OUTPUT_FILE"