Skip to content

chore: release v2.0.1 #9

chore: release v2.0.1

chore: release v2.0.1 #9

Workflow file for this run

name: Auto Changelog & Versioned Docs
on:
release:
types: [published]
push:
tags:
- 'v*.*.*' # Matches v1.0.0, v2.14.2, etc.
- '*.*.*' # Matches 1.0.0 (no v prefix)
- 'v*.*.*-*' # Matches v1.0.1-alpha.1, v1.2.0-beta.3, v2.0.0-rc.1
- '*.*.*-*' # Matches 1.0.1-alpha.1 (no v prefix)
workflow_dispatch:
inputs:
version:
description: 'Version to generate changelog/docs for (e.g., v1.2.5)'
required: true
type: string
jobs:
generate-changelog:
runs-on: ubuntu-latest
concurrency:
group: auto-changelog-${{ github.ref_name }}
cancel-in-progress: false
permissions:
contents: write
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
token: ${{ secrets.GH_PAT }}
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
- name: Build Changelog/Release Notes
id: github_release
uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2
with:
toTag: ${{ github.event.inputs.version || github.ref_name }}
configurationJson: |
{
"categories": [
{ "title": "### 🚀 Features", "labels": ["feat", "feature"] },
{ "title": "### 🐛 Fixes", "labels": ["fix", "bug"] },
{ "title": "### 📚 Documentation", "labels": ["docs", "doc"] },
{ "title": "### ⚡ Improvements", "labels": ["perf", "refactor"] },
{ "title": "### 🔧 Chore & CI", "labels": ["chore", "ci", "build", "test", "style", "revert"] }
],
"label_extractor": [
{
"pattern": "^(feat|fix|docs|doc|perf|refactor|chore|ci|build|test|style|revert)(?:\\([\\w\\-\\.]+\\))?(!)?:",
"on_property": "title",
"target": "$1"
}
],
"template": "#{{CHANGELOG}}",
"pr_template": "- {{TITLE}} by @{{AUTHOR}} in #{{NUMBER}}",
"empty_template": "- No changes",
"sort": {
"order": "DESC",
"on_property": "mergedAt"
}
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Flat Version File & Update README
env:
CHANGELOG: ${{ steps.github_release.outputs.changelog }}
run: |
VERSION="${{ github.event.inputs.version || github.ref_name }}"
VERSION_FILE="docs/${VERSION}.md"
# 1. Create the standalone version document right in the root of docs/
echo "# KDM CLI Documentation - ${VERSION}" > "$VERSION_FILE"
echo "Published on: $(date +'%Y-%m-%d')" >> "$VERSION_FILE"
echo "" >> "$VERSION_FILE"
printf '%s\n' "$CHANGELOG" >> "$VERSION_FILE"
# 2. Build the new dynamic landing page in a temporary file
TEMP_README=$(mktemp)
echo "# Documentation (Latest: ${VERSION})" > "$TEMP_README"
echo "" >> "$TEMP_README"
# 3. Embed the raw content of the new version directly into the README
cat "$VERSION_FILE" >> "$TEMP_README"
echo "" >> "$TEMP_README"
echo "---" >> "$TEMP_README"
echo "## Version History" >> "$TEMP_README"
echo "" >> "$TEMP_README"
# 4. Safely extract, sort, and process all version documentation files
# shopt -s nullglob ensures an unmatched glob pattern expands to nothing rather than its literal string
shopt -s nullglob
# Ingest all docs/*.md files, filter out README.md, version-sort in reverse chronological order
mapfile -t version_files < <(printf '%s\n' docs/*.md | grep -v '^docs/README\.md$' | sort -V -r)
# 5. Loop through the array buffer safely without breaking on empty sets or spaces
for file in "${version_files[@]}"; do
# Double check the file exists to catch empty arrays securely
[ -f "$file" ] || continue
V_NAME=$(basename "$file" .md)
echo "* [$V_NAME]($V_NAME.md)" >> "$TEMP_README"
done
# 6. Overwrite the main docs/README.md with our cleanly compiled template
mv "$TEMP_README" docs/README.md
- name: Commit and Push Changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git checkout ${{ github.event.repository.default_branch }}
git checkout ${{ github.event.repository.default_branch }}
# Retry fast-forward pull up to 3 times with exponential backoff
max_attempts=3
attempt=1
while [ $attempt -le $max_attempts ]; do
if git pull origin ${{ github.event.repository.default_branch }} --ff-only; then
break
fi
if [ $attempt -eq $max_attempts ]; then
echo "ERROR: Failed to fast-forward after $max_attempts attempts"
echo "Manual intervention required - docs/ has conflicts"
exit 1
fi
echo "Fast-forward failed (attempt $attempt/$max_attempts), retrying in $((2**attempt))s..."
sleep $((2**attempt))
((attempt++))
done
git add docs/
if git diff --cached --quiet; then
echo "No documentation changes to commit."
exit 0
fi
git commit -m "docs: auto-scaffold flat documentation for ${{ github.event.inputs.version || github.ref_name }} [skip ci]"
git push origin HEAD:${{ github.event.repository.default_branch }}