Files
deb-changelog-action/run.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

95 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 version 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 --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]
#
# 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
source "$(dirname "$0")/lib/utils.sh"
source "$(dirname "$0")/lib/logging.sh"
source "$(dirname "$0")/config.env"
# ───────────────────────────────────────────────
VERSION=""
TAG=""
PACKAGE_NAME=""
AUTHOR_NAME=""
AUTHOR_EMAIL=""
# CLIFF_CONFIG and OUTPUT_FILE are now sourced from .env
# ───────────────────────────────────────────────
show_help() { sed -n '2,25p' "$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 ────────────────
validate_arg "--version" "$VERSION"
validate_arg "--tag" "$TAG"
validate_arg "--package_name" "$PACKAGE_NAME"
validate_arg "--author_name" "$AUTHOR_NAME"
validate_arg "--author_email" "$AUTHOR_EMAIL"
# 3 ─ Prepare temporary clone ──────────────────
TMP_DIR=$(mktemp -d)
trap 'rm -rf "$TMP_DIR"' EXIT
log_info "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" ]] && { log_error "Config not found: $CLIFF_CONFIG"; exit 1; }
# 6 ─ Generate changelog in CURRENT dir ────────
log_info "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"
log_info "Changelog ready: $OUTPUT_FILE"