Compare commits
20 Commits
fd29805fa1
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e5c4e9102 | |||
|
f6c99d11e2
|
|||
| 7e23c3f8ec | |||
|
90e0d06efd
|
|||
| 369f740c1b | |||
|
c2999be2cd
|
|||
|
1c12062f12
|
|||
|
a38586f52c
|
|||
|
1239d67412
|
|||
|
a2a77a49b1
|
|||
| ff495030d4 | |||
|
bdb621da15
|
|||
|
2a2ad79bb4
|
|||
| ec51d271e3 | |||
|
656d08d74f
|
|||
| 93a3eb41fa | |||
|
72a343db93
|
|||
| 2ca581c65a | |||
|
fb60cee748
|
|||
| 169a1feb2e |
26
CHANGELOG.md
26
CHANGELOG.md
@@ -4,8 +4,34 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
## [unreleased]
|
## [unreleased]
|
||||||
|
|
||||||
|
### ⚙️ Miscellaneous Tasks
|
||||||
|
|
||||||
|
- *(scripts)* Improve CLI option parsing and error handling - ([f6c99d1](https://git.0xmax42.io/actions/deb-changelog-action/commit/f6c99d11e2cc24591e06bd52562d6387456fc287))
|
||||||
|
- Suppress git detached HEAD advice during clone - ([90e0d06](https://git.0xmax42.io/actions/deb-changelog-action/commit/90e0d06efdd5a32e86fab6df8a728e18c2b390aa))
|
||||||
|
|
||||||
|
## [0.2.3](https://git.0xmax42.io/actions/deb-changelog-action/compare/v0.2.2..v0.2.3) - 2025-12-13
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes
|
||||||
|
|
||||||
|
- *(changelog)* Normalize version hyphens to tildes in Debian changelog - ([a38586f](https://git.0xmax42.io/actions/deb-changelog-action/commit/a38586f52c48a830a8c8a5eda25a50eed40a782f))
|
||||||
|
|
||||||
|
## [0.2.1](https://git.0xmax42.io/actions/deb-changelog-action/compare/v0.2.0..v0.2.1) - 2025-12-13
|
||||||
|
|
||||||
|
### 🚜 Refactor
|
||||||
|
|
||||||
|
- *(help)* Improve help extraction for scripts - ([656d08d](https://git.0xmax42.io/actions/deb-changelog-action/commit/656d08d74f299d3c90aebfa67eac74f37662568f))
|
||||||
|
|
||||||
|
### ⚙️ Miscellaneous Tasks
|
||||||
|
|
||||||
|
- *(scripts)* Improve install script readability and error handling - ([2a2ad79](https://git.0xmax42.io/actions/deb-changelog-action/commit/2a2ad79bb4990c1f14324180275814a274376970))
|
||||||
|
|
||||||
|
## [0.2.0](https://git.0xmax42.io/actions/deb-changelog-action/compare/v0.1.1..v0.2.0) - 2025-07-02
|
||||||
|
|
||||||
### 📚 Documentation
|
### 📚 Documentation
|
||||||
|
|
||||||
|
- *(readme)* Update script reference in usage example - ([fb60cee](https://git.0xmax42.io/actions/deb-changelog-action/commit/fb60cee7482173db64f5946d493ac16d5ea6e57d))
|
||||||
|
- *(run.sh)* Update script documentation and help output - ([fd29805](https://git.0xmax42.io/actions/deb-changelog-action/commit/fd29805fa1c15310f234857362cdfaa0124051e5))
|
||||||
|
- *(script)* Improve help message layout and readability - ([b1644de](https://git.0xmax42.io/actions/deb-changelog-action/commit/b1644de411d789cb337ac250913a8aad2d53b40d))
|
||||||
- *(run.sh)* Clarify version reference in comments - ([f1b790d](https://git.0xmax42.io/actions/deb-changelog-action/commit/f1b790d4e3ae7d5b2d2300405f6bfdb6898dc8d2))
|
- *(run.sh)* Clarify version reference in comments - ([f1b790d](https://git.0xmax42.io/actions/deb-changelog-action/commit/f1b790d4e3ae7d5b2d2300405f6bfdb6898dc8d2))
|
||||||
|
|
||||||
## [0.1.1](https://git.0xmax42.io/actions/deb-changelog-action/compare/v0.1.0..v0.1.1) - 2025-06-27
|
## [0.1.1](https://git.0xmax42.io/actions/deb-changelog-action/compare/v0.1.0..v0.1.1) - 2025-06-27
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ This repository provides a one-liner to generate a Debian-style changelog using
|
|||||||
You can run the generator directly from the URL:
|
You can run the generator directly from the URL:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
curl -s https://git.0xmax42.io/actions/deb-changelog-action/raw/branch/main/run.sh | bash -s -- \
|
curl -s https://git.0xmax42.io/actions/deb-changelog-action/raw/branch/main/bootstrap.sh | bash -s -- \
|
||||||
--tag v2.9.1 \
|
--tag v2.9.1 \
|
||||||
--package_name my-package \
|
--package_name my-package \
|
||||||
--author_name "John Doe" \
|
--author_name "John Doe" \
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
#=== HELP START ===
|
||||||
# run.sh – local wrapper for the “deb-changelog-action”
|
# run.sh – local wrapper for the “deb-changelog-action”
|
||||||
#
|
#
|
||||||
# Behaviour:
|
# Behaviour:
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
# (configs/cliff.debian.toml) is used.
|
# (configs/cliff.debian.toml) is used.
|
||||||
# • PACKAGE_NAME, AUTHOR_NAME, AUTHOR_EMAIL are exported so the TOML template
|
# • PACKAGE_NAME, AUTHOR_NAME, AUTHOR_EMAIL are exported so the TOML template
|
||||||
# can reference them (e.g. {{ get_env(name="PACKAGE_NAME") }}).
|
# can reference them (e.g. {{ get_env(name="PACKAGE_NAME") }}).
|
||||||
|
#=== HELP END ===
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO_URL="https://git.0xmax42.io/actions/deb-changelog-action"
|
REPO_URL="https://git.0xmax42.io/actions/deb-changelog-action"
|
||||||
@@ -46,36 +48,87 @@ OUTPUT_FILE="debian/changelog"
|
|||||||
CLIFF_CONFIG=""
|
CLIFF_CONFIG=""
|
||||||
# ───────────────────────────────────────────────
|
# ───────────────────────────────────────────────
|
||||||
|
|
||||||
show_help() { sed -n '2,34p' "$0"; }
|
show_help() {
|
||||||
|
sed -n '/^#=== HELP START ===/,/^#=== HELP END ===/ {
|
||||||
|
/^#=== HELP START ===/d
|
||||||
|
/^#=== HELP END ===/d
|
||||||
|
s/^#//
|
||||||
|
p
|
||||||
|
}' "$0"
|
||||||
|
}
|
||||||
|
|
||||||
# 1 ─ Parse CLI options ─────────────────────────
|
# 1 ─ Parse CLI options ─────────────────────────
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--version) VERSION="$2"; shift 2 ;;
|
--version)
|
||||||
--tag) TAG="$2"; shift 2 ;;
|
VERSION="$2"
|
||||||
--package_name) PACKAGE_NAME="$2"; shift 2 ;;
|
shift 2
|
||||||
--author_name) AUTHOR_NAME="$2"; shift 2 ;;
|
;;
|
||||||
--author_email) AUTHOR_EMAIL="$2"; shift 2 ;;
|
--tag)
|
||||||
--output_file) OUTPUT_FILE="$2"; shift 2 ;;
|
TAG="$2"
|
||||||
--cliff_config) CLIFF_CONFIG="$2"; shift 2 ;;
|
shift 2
|
||||||
-h|--help) show_help; exit 0 ;;
|
;;
|
||||||
*) echo "❌ Unknown option: $1"; show_help; exit 1 ;;
|
--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
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# 2 ─ Validate mandatory inputs ────────────────
|
# 2 ─ Validate mandatory inputs ────────────────
|
||||||
[[ -z "$VERSION" ]] && { echo "❌ --version is required"; exit 1; }
|
[[ -z "$VERSION" ]] && {
|
||||||
[[ -z "$TAG" ]] && { echo "❌ --tag is required"; exit 1; }
|
echo "❌ --version is required"
|
||||||
[[ -z "$PACKAGE_NAME" ]] && { echo "❌ --package_name is required"; exit 1; }
|
exit 1
|
||||||
[[ -z "$AUTHOR_NAME" ]] && { echo "❌ --author_name is required"; exit 1; }
|
}
|
||||||
[[ -z "$AUTHOR_EMAIL" ]] && { echo "❌ --author_email 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 ──────────────────
|
# 3 ─ Prepare temporary clone ──────────────────
|
||||||
TMP_DIR=$(mktemp -d)
|
TMP_DIR=$(mktemp -d)
|
||||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||||
|
|
||||||
echo "📥 Cloning ${REPO_URL}@${VERSION} → $TMP_DIR"
|
echo "📥 Cloning ${REPO_URL}@${VERSION} → $TMP_DIR"
|
||||||
git clone --depth 1 --branch "$VERSION" "$REPO_URL" "$TMP_DIR" >/dev/null
|
git -c advice.detachedHead=false \
|
||||||
|
clone --depth 1 --branch "$VERSION" "$REPO_URL" "$TMP_DIR" >/dev/null
|
||||||
|
|
||||||
# 4 ─ Install git-cliff via helper script ──────
|
# 4 ─ Install git-cliff via helper script ──────
|
||||||
bash "$TMP_DIR/scripts/install-git-cliff.sh"
|
bash "$TMP_DIR/scripts/install-git-cliff.sh"
|
||||||
@@ -84,7 +137,10 @@ bash "$TMP_DIR/scripts/install-git-cliff.sh"
|
|||||||
if [[ -z "$CLIFF_CONFIG" ]]; then
|
if [[ -z "$CLIFF_CONFIG" ]]; then
|
||||||
CLIFF_CONFIG="$TMP_DIR/configs/cliff.debian.toml"
|
CLIFF_CONFIG="$TMP_DIR/configs/cliff.debian.toml"
|
||||||
fi
|
fi
|
||||||
[[ ! -r "$CLIFF_CONFIG" ]] && { echo "❌ Config not found: $CLIFF_CONFIG"; exit 1; }
|
[[ ! -r "$CLIFF_CONFIG" ]] && {
|
||||||
|
echo "❌ Config not found: $CLIFF_CONFIG"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
# 6 ─ Generate changelog in CURRENT dir ────────
|
# 6 ─ Generate changelog in CURRENT dir ────────
|
||||||
echo "📝 Generating changelog (output → $OUTPUT_FILE)"
|
echo "📝 Generating changelog (output → $OUTPUT_FILE)"
|
||||||
@@ -93,8 +149,8 @@ env \
|
|||||||
AUTHOR_NAME="$AUTHOR_NAME" \
|
AUTHOR_NAME="$AUTHOR_NAME" \
|
||||||
AUTHOR_EMAIL="$AUTHOR_EMAIL" \
|
AUTHOR_EMAIL="$AUTHOR_EMAIL" \
|
||||||
bash "$TMP_DIR/scripts/generate-changelog.sh" \
|
bash "$TMP_DIR/scripts/generate-changelog.sh" \
|
||||||
-c "$CLIFF_CONFIG" \
|
-c "$CLIFF_CONFIG" \
|
||||||
-t "$TAG" \
|
-t "$TAG" \
|
||||||
-o "$OUTPUT_FILE"
|
-o "$OUTPUT_FILE"
|
||||||
|
|
||||||
echo "✅ Changelog ready: $OUTPUT_FILE"
|
echo "✅ Changelog ready: $OUTPUT_FILE"
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[changelog]
|
[changelog]
|
||||||
body = """\
|
body = """\
|
||||||
{{ get_env(name="PACKAGE_NAME") }} ({% if version %}{{ version | trim_start_matches(pat="v") }}{% else %}0.0.0-1{% endif %}) unstable; urgency=medium\
|
{{ get_env(name="PACKAGE_NAME") }} ({% if version %}{{ version | replace(from="-", to="~") | trim_start_matches(pat="v") }}{% else %}0.0.0-1{% endif %}) unstable; urgency=medium\
|
||||||
{% for group, commits in commits | group_by(attribute="group") %}
|
{% for group, commits in commits | group_by(attribute="group") %}
|
||||||
* {{ group | striptags | trim | upper_first }}:\
|
* {{ group | striptags | trim | upper_first }}:\
|
||||||
{% for commit in commits %}
|
{% for commit in commits %}
|
||||||
@@ -8,7 +8,7 @@ body = """\
|
|||||||
{% endfor %}\
|
{% endfor %}\
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
-- {{ get_env(name="AUTHOR_NAME") }} <{{ get_env(name="AUTHOR_EMAIL") }}> {% if version %}{{ now() | date(format="%a, %d %b %Y %H:%M:%S %z") }}{% else %}{{ now() | date(format="%a, %d %b %Y %H:%M:%S %z") }}{% endif %}
|
-- {{ get_env(name="AUTHOR_NAME") }} <{{ get_env(name="AUTHOR_EMAIL") }}> {% if version %}{{ now() | date(format="%a, %d %b %Y %H:%M:%S %z") }}{% else %}{{ now() | date(format="%a, %d %b %Y %H:%M:%S %z") }}{% endif %}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
#=== HELP START ===
|
||||||
# generate-changelog.sh – generates a Debian-style changelog via git-cliff
|
# generate-changelog.sh – generates a Debian-style changelog via git-cliff
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
@@ -16,6 +17,7 @@
|
|||||||
# • Checks that the config file exists and is readable.
|
# • Checks that the config file exists and is readable.
|
||||||
# • Ensures the parent directory of the output file exists (unless --debug).
|
# • Ensures the parent directory of the output file exists (unless --debug).
|
||||||
# • Generates the changelog; removes a leading empty line.
|
# • Generates the changelog; removes a leading empty line.
|
||||||
|
#=== HELP END ===
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# ───────────────────────────────────────────────
|
# ───────────────────────────────────────────────
|
||||||
@@ -25,32 +27,89 @@ OUT_FILE=""
|
|||||||
DEBUG=false
|
DEBUG=false
|
||||||
# ───────────────────────────────────────────────
|
# ───────────────────────────────────────────────
|
||||||
|
|
||||||
show_help() { sed -n '2,18p' "$0"; }
|
show_help() {
|
||||||
|
sed -n '/^#=== HELP START ===/,/^#=== HELP END ===/ {
|
||||||
|
/^#=== HELP START ===/d
|
||||||
|
/^#=== HELP END ===/d
|
||||||
|
s/^#//
|
||||||
|
p
|
||||||
|
}' "$0"
|
||||||
|
}
|
||||||
|
|
||||||
# 1 Parse CLI options
|
# 1 Parse CLI options
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-c|--config) [[ $# -lt 2 ]] && { echo "❌ $1 requires a value"; exit 1; }; CONFIG_FILE="$2"; shift 2 ;;
|
-c | --config)
|
||||||
-t|--tag) [[ $# -lt 2 ]] && { echo "❌ $1 requires a value"; exit 1; }; TAG="$2"; shift 2 ;;
|
[[ $# -lt 2 ]] && {
|
||||||
-o|--out) [[ $# -lt 2 ]] && { echo "❌ $1 requires a value"; exit 1; }; OUT_FILE="$2"; shift 2 ;;
|
echo "❌ $1 requires a value"
|
||||||
-d|--debug) DEBUG=true; shift ;;
|
exit 1
|
||||||
-h|--help) show_help; exit 0 ;;
|
}
|
||||||
*) echo "❌ Unknown option: $1"; show_help; 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
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# 2 Basic validation
|
# 2 Basic validation
|
||||||
[[ -z "$CONFIG_FILE" || -z "$TAG" ]] && { echo "❌ --config and --tag are required"; show_help; exit 1; }
|
[[ -z "$CONFIG_FILE" || -z "$TAG" ]] && {
|
||||||
[[ "$DEBUG" = false && -z "$OUT_FILE" ]] && { echo "❌ --out is required unless --debug is set"; show_help; exit 1; }
|
echo "❌ --config and --tag are required"
|
||||||
[[ ! -r "$CONFIG_FILE" ]] && { echo "❌ Config file not found or unreadable: $CONFIG_FILE"; exit 1; }
|
show_help
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
[[ "$DEBUG" = false && -z "$OUT_FILE" ]] && {
|
||||||
|
echo "❌ --out is required unless --debug is set"
|
||||||
|
show_help
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
[[ ! -r "$CONFIG_FILE" ]] && {
|
||||||
|
echo "❌ Config file not found or unreadable: $CONFIG_FILE"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
if [[ "$DEBUG" = false ]]; then
|
if [[ "$DEBUG" = false ]]; then
|
||||||
OUT_DIR=$(dirname "$OUT_FILE")
|
OUT_DIR=$(dirname "$OUT_FILE")
|
||||||
[[ ! -d "$OUT_DIR" ]] && { echo "❌ Output directory does not exist: $OUT_DIR"; exit 1; }
|
[[ ! -d "$OUT_DIR" ]] && {
|
||||||
|
echo "❌ Output directory does not exist: $OUT_DIR"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3 Required tools
|
# 3 Required tools
|
||||||
need() { command -v "$1" >/dev/null || { echo "❌ $1 is required but not installed"; exit 1; }; }
|
need() { command -v "$1" >/dev/null || {
|
||||||
need git; need git-cliff; need sed
|
echo "❌ $1 is required but not installed"
|
||||||
|
exit 1
|
||||||
|
}; }
|
||||||
|
need git
|
||||||
|
need git-cliff
|
||||||
|
need sed
|
||||||
|
|
||||||
# 4 Generate changelog
|
# 4 Generate changelog
|
||||||
if $DEBUG; then
|
if $DEBUG; then
|
||||||
@@ -58,6 +117,6 @@ if $DEBUG; then
|
|||||||
git cliff --config "$CONFIG_FILE" -t "$TAG" -s all
|
git cliff --config "$CONFIG_FILE" -t "$TAG" -s all
|
||||||
else
|
else
|
||||||
echo "📝 Generating changelog → $OUT_FILE"
|
echo "📝 Generating changelog → $OUT_FILE"
|
||||||
git cliff --config "$CONFIG_FILE" -t "$TAG" -s all > "$OUT_FILE"
|
git cliff --config "$CONFIG_FILE" -t "$TAG" -s all >"$OUT_FILE"
|
||||||
echo "✅ Changelog written to $OUT_FILE"
|
echo "✅ Changelog written to $OUT_FILE"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
#=== HELP START ===
|
||||||
# install-git-cliff.sh – Installs the git-cliff binary
|
# install-git-cliff.sh – Installs the git-cliff binary
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
# aarch64-linux-gnu / musl / apple-darwin / pc-windows-msvc
|
# aarch64-linux-gnu / musl / apple-darwin / pc-windows-msvc
|
||||||
# i686-linux-gnu / musl / pc-windows-msvc
|
# i686-linux-gnu / musl / pc-windows-msvc
|
||||||
# x86_64-linux-gnu / musl / apple-darwin / pc-windows-*
|
# x86_64-linux-gnu / musl / apple-darwin / pc-windows-*
|
||||||
|
#=== HELP END ===
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
REPO="orhun/git-cliff"
|
REPO="orhun/git-cliff"
|
||||||
@@ -29,7 +31,7 @@ REPO="orhun/git-cliff"
|
|||||||
# ───────────────────────────────────────────────
|
# ───────────────────────────────────────────────
|
||||||
# Defaults (internal vs. user-facing)
|
# Defaults (internal vs. user-facing)
|
||||||
ARCH_OS_DEFAULT="x86_64-unknown-linux-gnu"
|
ARCH_OS_DEFAULT="x86_64-unknown-linux-gnu"
|
||||||
DEFAULT_ARCH_DISPLAY="${ARCH_OS_DEFAULT/-unknown-/}" # shown to user → x86_64-linux-gnu
|
DEFAULT_ARCH_DISPLAY="${ARCH_OS_DEFAULT/-unknown-/}" # shown to user → x86_64-linux-gnu
|
||||||
INSTALL_DIR_DEFAULT="/usr/local/bin"
|
INSTALL_DIR_DEFAULT="/usr/local/bin"
|
||||||
ARCH_OS="$ARCH_OS_DEFAULT"
|
ARCH_OS="$ARCH_OS_DEFAULT"
|
||||||
INSTALL_DIR="$INSTALL_DIR_DEFAULT"
|
INSTALL_DIR="$INSTALL_DIR_DEFAULT"
|
||||||
@@ -39,21 +41,47 @@ USER_VERSION_SPECIFIED=false
|
|||||||
# ───────────────────────────────────────────────
|
# ───────────────────────────────────────────────
|
||||||
|
|
||||||
# 0 Help function
|
# 0 Help function
|
||||||
show_help() { sed -n '2,24p' "$0"; }
|
show_help() {
|
||||||
|
sed -n '/^#=== HELP START ===/,/^#=== HELP END ===/ {
|
||||||
|
/^#=== HELP START ===/d
|
||||||
|
/^#=== HELP END ===/d
|
||||||
|
s/^#//
|
||||||
|
p
|
||||||
|
}' "$0"
|
||||||
|
}
|
||||||
|
|
||||||
# 1 Parse options (keeps old single-arg form)
|
# 1 Parse options (keeps old single-arg form)
|
||||||
POSITIONAL=()
|
POSITIONAL=()
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h|--help) show_help; exit 0 ;;
|
-h | --help)
|
||||||
-n|--dry-run) DRY_RUN=true; shift ;;
|
show_help
|
||||||
-a|--arch)
|
exit 0
|
||||||
[[ $# -lt 2 ]] && { echo "❌ Option $1 requires an argument"; exit 1; }
|
;;
|
||||||
ARCH_OS_INPUT="$2"; shift 2 ;;
|
-n | --dry-run)
|
||||||
-d|--dir)
|
DRY_RUN=true
|
||||||
[[ $# -lt 2 ]] && { echo "❌ Option $1 requires an argument"; exit 1; }
|
shift
|
||||||
INSTALL_DIR="$2"; shift 2 ;;
|
;;
|
||||||
*) POSITIONAL+=("$1"); shift ;;
|
-a | --arch)
|
||||||
|
[[ $# -lt 2 ]] && {
|
||||||
|
echo "❌ Option $1 requires an argument"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
ARCH_OS_INPUT="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
-d | --dir)
|
||||||
|
[[ $# -lt 2 ]] && {
|
||||||
|
echo "❌ Option $1 requires an argument"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
INSTALL_DIR="$2"
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
POSITIONAL+=("$1")
|
||||||
|
shift
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
if [[ ${#POSITIONAL[@]} -gt 0 ]]; then
|
if [[ ${#POSITIONAL[@]} -gt 0 ]]; then
|
||||||
@@ -89,8 +117,16 @@ if command -v git-cliff >/dev/null; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# 4 Check for required tools
|
# 4 Check for required tools
|
||||||
need() { command -v "$1" >/dev/null || { echo "$1 is missing"; exit 1; }; }
|
need() { command -v "$1" >/dev/null || {
|
||||||
need curl; need tar; need grep; need sed; need awk; need jq
|
echo "$1 is missing"
|
||||||
|
exit 1
|
||||||
|
}; }
|
||||||
|
need curl
|
||||||
|
need tar
|
||||||
|
need grep
|
||||||
|
need sed
|
||||||
|
need awk
|
||||||
|
need jq
|
||||||
|
|
||||||
# 5 Determine version → Fetch release JSON
|
# 5 Determine version → Fetch release JSON
|
||||||
if [[ "$VERSION" == "latest" ]]; then
|
if [[ "$VERSION" == "latest" ]]; then
|
||||||
@@ -100,14 +136,23 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "🔍 Fetching release info ($API_URL)…"
|
echo "🔍 Fetching release info ($API_URL)…"
|
||||||
JSON=$(curl -fsSL "$API_URL") || { echo "❌ Failed to fetch release info"; exit 1; }
|
JSON=$(curl -fsSL "$API_URL") || {
|
||||||
|
echo "❌ Failed to fetch release info"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
VERSION=$(jq -r '.tag_name' <<< "$JSON") || { echo "❌ Could not extract version"; exit 1; }
|
VERSION=$(jq -r '.tag_name' <<<"$JSON") || {
|
||||||
|
echo "❌ Could not extract version"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
ASSET_URL=$(jq -r '.assets[]?.browser_download_url' <<< "$JSON" |
|
ASSET_URL=$(jq -r '.assets[]?.browser_download_url' <<<"$JSON" |
|
||||||
grep -E "${ARCH_OS}\.(tar\.(gz|xz)|zip)$" | head -n1)
|
grep -E "${ARCH_OS}\.(tar\.(gz|xz)|zip)$" | head -n1)
|
||||||
|
|
||||||
[[ -z "$ASSET_URL" ]] && { echo "❌ Matching asset not found for architecture ${ARCH_OS}"; exit 1; }
|
[[ -z "$ASSET_URL" ]] && {
|
||||||
|
echo "❌ Matching asset not found for architecture ${ARCH_OS}"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
ASSET_FILE=$(basename "$ASSET_URL")
|
ASSET_FILE=$(basename "$ASSET_URL")
|
||||||
echo "📦 Downloading git-cliff ${VERSION} (${ASSET_FILE}) …"
|
echo "📦 Downloading git-cliff ${VERSION} (${ASSET_FILE}) …"
|
||||||
@@ -116,21 +161,32 @@ curl -#L -o "${TMP}/${ASSET_FILE}" "$ASSET_URL"
|
|||||||
|
|
||||||
# 6 Extract based on file extension
|
# 6 Extract based on file extension
|
||||||
case "$ASSET_FILE" in
|
case "$ASSET_FILE" in
|
||||||
*.tar.gz|*.tgz) tar -C "$TMP" -xzf "${TMP}/${ASSET_FILE}" ;;
|
*.tar.gz | *.tgz) tar -C "$TMP" -xzf "${TMP}/${ASSET_FILE}" ;;
|
||||||
*.tar.xz) tar -C "$TMP" -xJf "${TMP}/${ASSET_FILE}" ;;
|
*.tar.xz) tar -C "$TMP" -xJf "${TMP}/${ASSET_FILE}" ;;
|
||||||
*.zip) need unzip; unzip -q "${TMP}/${ASSET_FILE}" -d "$TMP" ;;
|
*.zip)
|
||||||
*) echo "❌ Unknown archive format: $ASSET_FILE"; exit 1 ;;
|
need unzip
|
||||||
|
unzip -q "${TMP}/${ASSET_FILE}" -d "$TMP"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "❌ Unknown archive format: $ASSET_FILE"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# 7 Locate & (maybe) install binary
|
# 7 Locate & (maybe) install binary
|
||||||
BIN_PATH=$(find "$TMP" -type f -name git-cliff -perm -u+x | head -n1)
|
BIN_PATH=$(find "$TMP" -type f -name git-cliff -perm -u+x | head -n1)
|
||||||
[[ -z "$BIN_PATH" ]] && { echo "❌ Binary not found"; exit 1; }
|
[[ -z "$BIN_PATH" ]] && {
|
||||||
|
echo "❌ Binary not found"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
if $DRY_RUN; then
|
if $DRY_RUN; then
|
||||||
echo "🧪 Dry-run: verified git-cliff binary at ${BIN_PATH}"
|
echo "🧪 Dry-run: verified git-cliff binary at ${BIN_PATH}"
|
||||||
echo "ℹ️ Would install to: ${INSTALL_DIR}/git-cliff (sudo install -m755 …)"
|
echo "ℹ️ Would install to: ${INSTALL_DIR}/git-cliff (sudo install -m755 …)"
|
||||||
echo "✅ git-cliff $("$BIN_PATH" --version) would be installed successfully"
|
echo "✅ git-cliff $("$BIN_PATH" --version) would be installed successfully"
|
||||||
else
|
else
|
||||||
sudo install -m755 "$BIN_PATH" "${INSTALL_DIR}/git-cliff"
|
SUDO=""
|
||||||
|
[[ $EUID -eq 0 ]] || SUDO="sudo"
|
||||||
|
$SUDO install -m755 "$BIN_PATH" "${INSTALL_DIR}/git-cliff"
|
||||||
echo "✅ git-cliff $(git-cliff --version) installed in ${INSTALL_DIR}"
|
echo "✅ git-cliff $(git-cliff --version) installed in ${INSTALL_DIR}"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user