-
Notifications
You must be signed in to change notification settings - Fork 8
171 lines (146 loc) · 5.91 KB
/
Copy pathchangelog.yml
File metadata and controls
171 lines (146 loc) · 5.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Auto Changelog & Versioned Docs
on:
release:
types: [published]
push:
tags:
- 'v*.*.*'
- '*.*.*'
- 'v*.*.*-*'
- '*.*.*-*'
workflow_dispatch:
inputs:
version:
description: 'Version to generate 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:
fetch-depth: 0
ref: ${{ github.event.repository.default_branch }}
- name: Determine version range
id: version_range
run: |
VERSION="${{ github.event.inputs.version || github.ref_name }}"
echo "toTag=$VERSION" >> "$GITHUB_OUTPUT"
prev=""
while IFS= read -r tag; do
if [ "$tag" = "$VERSION" ]; then
echo "fromTag=$prev" >> "$GITHUB_OUTPUT"
echo "previous_tag=$prev" >> "$GITHUB_OUTPUT"
break
fi
prev="$tag"
done < <(git tag --sort=-version:refname)
- name: Build Changelog/Release Notes
id: github_release
uses: mikepenz/release-changelog-builder-action@348e88fab4c37338b1e803ceb2d4a7a5db6c0833 # v6.2.2
with:
fromTag: ${{ steps.version_range.outputs.fromTag }}
toTag: ${{ steps.version_range.outputs.toTag }}
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": "^(?i)(feat|feature|fix|docs?|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="${{ steps.version_range.outputs.toTag }}"
FROM_TAG="${{ steps.version_range.outputs.fromTag }}"
VERSION_FILE="docs/${VERSION}.md"
FALLBACK=false
TRIMMED=$(printf '%s' "$CHANGELOG" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -z "$TRIMMED" ] || [ "$TRIMMED" = "- No changes" ]; then
FALLBACK=true
echo "[!] Empty changelog — using git log fallback"
fi
echo "# KDM CLI Documentation - ${VERSION}" > "$VERSION_FILE"
echo "Published on: $(date +'%Y-%m-%d')" >> "$VERSION_FILE"
echo "" >> "$VERSION_FILE"
if [ "$FALLBACK" = "true" ]; then
{
echo "### 📦 Commits"
echo ""
if [ -n "$FROM_TAG" ]; then
git log --oneline --no-merges "${FROM_TAG}..${VERSION}"
else
git log --oneline --no-merges "${VERSION}"
fi | grep -vi "auto-scaffold flat documentation" | grep -vi "skip ci" | while IFS= read -r line; do
msg="${line#* }"
echo "- ${msg}"
done
} >> "$VERSION_FILE"
else
printf '%s\n' "$CHANGELOG" >> "$VERSION_FILE"
fi
TEMP_README=$(mktemp)
echo "# Documentation (Latest: ${VERSION})" > "$TEMP_README"
echo "" >> "$TEMP_README"
cat "$VERSION_FILE" >> "$TEMP_README"
echo "" >> "$TEMP_README"
echo "---" >> "$TEMP_README"
echo "## Version History" >> "$TEMP_README"
echo "" >> "$TEMP_README"
shopt -s nullglob
mapfile -t version_files < <(printf '%s\n' docs/*.md | grep -v -E '^docs/(README|what-is-kdm|UPGRADE-v2)\.md$' | sort -V -r)
for file in "${version_files[@]}"; do
[ -f "$file" ] || continue
V_NAME=$(basename "$file" .md)
echo "* [$V_NAME]($V_NAME.md)" >> "$TEMP_README"
done
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 }}
for i in 1 2 3; do
if git pull origin ${{ github.event.repository.default_branch }} --ff-only; then
break
fi
if [ $i -eq 3 ]; then
echo "ERROR: Failed to fast-forward after 3 attempts"
exit 1
fi
sleep $((2**i))
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 ${{ steps.version_range.outputs.toTag }} [skip ci]"
git push origin HEAD:${{ github.event.repository.default_branch }}