#!/bin/bash # DevMagic template: Changelog (git-cliff) (changelog) # Generated by https://devmagic.run/install/changelog — review before running. # Conventional-commits changelog generation with git-cliff — the cliff.toml config plus a GitHub Actions workflow that keeps CHANGELOG.md updated on every push to main set -e BASE="https://raw.githubusercontent.com/marcelocra/devmagic/main" FORCE="0" REPO_URL_PLACEHOLDER="https://github.com/YOUR_ORG/YOUR_REPO" if ! command -v curl >/dev/null 2>&1; then echo "❌ curl is not installed. Please install curl to continue." exit 1 fi # Detect this project's repository URL, for templates that link back to it # (e.g. changelog release links). Falls back to an obvious placeholder. REPO_URL="" if command -v git >/dev/null 2>&1; then ORIGIN=$(git remote get-url origin 2>/dev/null || true) if [ -n "$ORIGIN" ]; then # Normalize: git@host:owner/repo(.git) → https://host/owner/repo REPO_URL=$(printf '%s' "$ORIGIN" | sed -E 's#^git@([^:]+):#https://\1/#; s#\.git$##') fi fi # Only accept URL-safe characters (the value is used in a sed replacement). if ! printf '%s' "$REPO_URL" | grep -Eq '^[A-Za-z0-9./:_-]+$'; then REPO_URL="$REPO_URL_PLACEHOLDER" fi fill_placeholders() { local dest="$1" if grep -q "{{REPO_URL}}" "$dest" 2>/dev/null; then sed -i.bak "s#{{REPO_URL}}#${REPO_URL}#g" "$dest" && rm -f "$dest.bak" if [ "$REPO_URL" = "$REPO_URL_PLACEHOLDER" ]; then echo "⚠️ Couldn't detect your git remote — edit the repository URL in $dest" fi fi } install_file() { local src="$1" dest="$2" if [ -e "$dest" ] && [ "$FORCE" != "1" ]; then echo "⚠️ $dest already exists, skipping (add ?force=1 to the URL to overwrite)" return 0 fi local dir dir=$(dirname "$dest") [ "$dir" != "." ] && mkdir -p "$dir" curl -fsSL "$BASE/$src" -o "$dest" fill_placeholders "$dest" echo "✓ $dest" } echo "🚀 DevMagic template: Changelog (git-cliff)" echo install_file "templates/changelog/cliff.toml" "cliff.toml" install_file "templates/changelog/changelog-workflow.yml" ".github/workflows/changelog.yml" echo echo "💡 The changelog links use your repository URL, auto-detected from git remote origin — if detection fails, edit the URL placeholder in cliff.toml" echo "💡 Optional: add package.json scripts: \"changelog\": \"git-cliff -o CHANGELOG.md\" and \"changelog:unreleased\": \"git-cliff --unreleased\"" echo "💡 Local generation needs git-cliff (e.g. pnpm add -D git-cliff); the GitHub workflow needs nothing extra" echo echo "✅ Done. Review the files and commit the ones you want to keep."