@zairakai/js-dev-tools 4.1.0 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -30,6 +30,8 @@ variables:
|
|
|
30
30
|
# Consumer projects do NOT need to override these.
|
|
31
31
|
# dev-tools itself overrides them in its own .gitlab-ci.yml.
|
|
32
32
|
JS_DEV_TOOLS_SCRIPTS: 'node_modules/@zairakai/js-dev-tools/scripts'
|
|
33
|
+
# The scripts of the jobs of the release: the notes of a version.
|
|
34
|
+
JS_DEV_TOOLS_GITLAB_SCRIPTS: 'node_modules/@zairakai/js-dev-tools/.gitlab/scripts'
|
|
33
35
|
|
|
34
36
|
# NODE
|
|
35
37
|
# ================
|
|
@@ -68,9 +68,14 @@ js:publish:
|
|
|
68
68
|
# RELEASE
|
|
69
69
|
# ================
|
|
70
70
|
js:release:
|
|
71
|
-
extends:
|
|
71
|
+
extends:
|
|
72
|
+
- .js:base
|
|
73
|
+
- .js:cache
|
|
72
74
|
stage: release
|
|
73
75
|
image: ${RELEASE_CLI_IMAGE}
|
|
76
|
+
variables:
|
|
77
|
+
# All the history and all the tags: the notes cover the range since the previous tag
|
|
78
|
+
GIT_DEPTH: 0
|
|
74
79
|
rules:
|
|
75
80
|
- if: $UPDATE_DEPENDENCIES == "true"
|
|
76
81
|
when: never
|
|
@@ -82,18 +87,11 @@ js:release:
|
|
|
82
87
|
- git config --global user.email "ci@gitlab.com"
|
|
83
88
|
script:
|
|
84
89
|
- |
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
else
|
|
90
|
-
COMMITS="- Initial release"
|
|
90
|
+
bash "${JS_DEV_TOOLS_GITLAB_SCRIPTS}/generate-release-notes.sh"
|
|
91
|
+
if [ ! -s release_notes.md ]; then
|
|
92
|
+
echo "❌ ERROR: release_notes.md is missing or empty"
|
|
93
|
+
exit 1
|
|
91
94
|
fi
|
|
92
|
-
cat > release_notes.md << NOTES
|
|
93
|
-
## ${CI_COMMIT_TAG}
|
|
94
|
-
|
|
95
|
-
${COMMITS}
|
|
96
|
-
NOTES
|
|
97
95
|
release-cli create \
|
|
98
96
|
--tag-name "${CI_COMMIT_TAG}" \
|
|
99
97
|
--name "Release ${CI_COMMIT_TAG}" \
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
#
|
|
3
|
+
# Generate the release notes of a tag from the commits since the previous tag,
|
|
4
|
+
# following the git-rules conventions.
|
|
5
|
+
# Usage: bash .gitlab/scripts/generate-release-notes.sh [from_tag] [to_tag]
|
|
6
|
+
# from_tag the previous tag (default: the version tag before to_tag, none
|
|
7
|
+
# for a first release)
|
|
8
|
+
# to_tag the tag to describe (default: the tag of HEAD)
|
|
9
|
+
# Writes release_notes.md in the current directory, and never leaves it empty.
|
|
10
|
+
set -euo pipefail
|
|
11
|
+
|
|
12
|
+
# The CI clones with a small depth and fetches only the tag of the pipeline:
|
|
13
|
+
# without the history and the other tags the
|
|
14
|
+
# previous tag is unknown, and the range between the tag and itself is empty.
|
|
15
|
+
fetch_history() {
|
|
16
|
+
if [ "$(git rev-parse --is-shallow-repository 2>/dev/null)" = "true" ]; then
|
|
17
|
+
git fetch --quiet --unshallow --tags \
|
|
18
|
+
|| echo "⚠️ Could not fetch the history: the notes may be incomplete"
|
|
19
|
+
else
|
|
20
|
+
git fetch --quiet --tags 2>/dev/null || true
|
|
21
|
+
fi
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
# The version tags, newest first, with or without the old "v" prefix (v2.2.0
|
|
25
|
+
# then 2.3.0). The order does not rely on "sort -V": the busybox of the images
|
|
26
|
+
# of the CI sorts a pre-release (1.0.0-rc.1) after its release. The key of a
|
|
27
|
+
# tag is its three numbers, padded, then "1" for a release, which comes before
|
|
28
|
+
# its pre-releases ("0" and the pre-release).
|
|
29
|
+
version_tags() {
|
|
30
|
+
git tag \
|
|
31
|
+
| grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+(-.+)?$' \
|
|
32
|
+
| awk '{
|
|
33
|
+
version = $0
|
|
34
|
+
sub(/^v/, "", version)
|
|
35
|
+
pre = ""
|
|
36
|
+
dash = index(version, "-")
|
|
37
|
+
if (dash > 0) {
|
|
38
|
+
pre = substr(version, dash + 1)
|
|
39
|
+
version = substr(version, 1, dash - 1)
|
|
40
|
+
}
|
|
41
|
+
split(version, number, ".")
|
|
42
|
+
printf "%010d.%010d.%010d.%s %s\n", number[1], number[2], number[3], \
|
|
43
|
+
(pre == "" ? "1" : "0" pre), $0
|
|
44
|
+
}' \
|
|
45
|
+
| sort -r \
|
|
46
|
+
| cut -d' ' -f2 \
|
|
47
|
+
|| true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fetch_history
|
|
51
|
+
|
|
52
|
+
TO_TAG="${2:-$(git describe --tags --abbrev=0 HEAD)}"
|
|
53
|
+
FROM_TAG="${1:-$(version_tags | grep -A1 -Fx "${TO_TAG}" | sed -n 2p || true)}"
|
|
54
|
+
|
|
55
|
+
if [ -n "${FROM_TAG}" ]; then
|
|
56
|
+
RANGE="${FROM_TAG}..${TO_TAG}"
|
|
57
|
+
else
|
|
58
|
+
# A first release: all its commits
|
|
59
|
+
RANGE="${TO_TAG}"
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
RELEASE_NOTES="release_notes.md"
|
|
63
|
+
|
|
64
|
+
echo "━━━━━━━━━━━━━━━━"
|
|
65
|
+
echo "📝 Generating Release Notes"
|
|
66
|
+
echo "━━━━━━━━━━━━━━━━"
|
|
67
|
+
echo ""
|
|
68
|
+
echo "→ From: ${FROM_TAG:-(first release)}"
|
|
69
|
+
echo "→ To: ${TO_TAG}"
|
|
70
|
+
echo "→ Output: ${RELEASE_NOTES}"
|
|
71
|
+
echo ""
|
|
72
|
+
|
|
73
|
+
: > "${RELEASE_NOTES}"
|
|
74
|
+
|
|
75
|
+
# Write to both stdout and the file
|
|
76
|
+
output() {
|
|
77
|
+
echo "$@" | tee -a "${RELEASE_NOTES}"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
footer() {
|
|
81
|
+
output "---"
|
|
82
|
+
output ""
|
|
83
|
+
if [ -n "${FROM_TAG}" ]; then
|
|
84
|
+
output "**Full Changelog**: ${FROM_TAG}...${TO_TAG}"
|
|
85
|
+
else
|
|
86
|
+
output "**First release**: ${TO_TAG}"
|
|
87
|
+
fi
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
# Commits of the range, without the merge commits
|
|
91
|
+
COMMITS=$(git log "${RANGE}" --pretty=format:"%s" --no-merges)
|
|
92
|
+
|
|
93
|
+
output "## What's Changed"
|
|
94
|
+
output ""
|
|
95
|
+
|
|
96
|
+
if [ -z "${COMMITS}" ]; then
|
|
97
|
+
output "No commit${FROM_TAG:+ since ${FROM_TAG}}."
|
|
98
|
+
output ""
|
|
99
|
+
footer
|
|
100
|
+
exit 0
|
|
101
|
+
fi
|
|
102
|
+
|
|
103
|
+
# The breaking changes: the paragraph that starts with "BREAKING CHANGE:", up to
|
|
104
|
+
# the next blank line, as one bullet. The
|
|
105
|
+
# paragraph "Migration:" that follows it is added under it.
|
|
106
|
+
breaking_changes() {
|
|
107
|
+
local commit
|
|
108
|
+
for commit in $(git log "${RANGE}" --pretty=format:"%H" --no-merges); do
|
|
109
|
+
git show --no-patch --pretty=format:"%b" "${commit}" | awk '
|
|
110
|
+
function end_paragraph() {
|
|
111
|
+
if (kind == "b") { print "- " text; after = "b" }
|
|
112
|
+
else if (kind == "m") { print " " text; after = "" }
|
|
113
|
+
else { after = "" }
|
|
114
|
+
kind = ""; text = ""
|
|
115
|
+
}
|
|
116
|
+
/^[[:space:]]*$/ { end_paragraph(); next }
|
|
117
|
+
kind == "" {
|
|
118
|
+
if ($0 ~ /^BREAKING CHANGE:/) {
|
|
119
|
+
kind = "b"; text = $0
|
|
120
|
+
sub(/^BREAKING CHANGE:[[:space:]]*/, "", text)
|
|
121
|
+
}
|
|
122
|
+
else if (after == "b" && $0 ~ /^Migration:/) { kind = "m"; text = $0 }
|
|
123
|
+
else { kind = "x" }
|
|
124
|
+
next
|
|
125
|
+
}
|
|
126
|
+
kind == "b" || kind == "m" { text = text " " $0 }
|
|
127
|
+
END { end_paragraph() }
|
|
128
|
+
'
|
|
129
|
+
done
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
# Format a commit message: without the type and the scope, with its ticket at
|
|
133
|
+
# the end
|
|
134
|
+
format_commit() {
|
|
135
|
+
local commit="$1"
|
|
136
|
+
local type_pattern="$2"
|
|
137
|
+
local message ticket
|
|
138
|
+
|
|
139
|
+
message=$(echo "${commit}" | sed -E "s/^${type_pattern}(\([^)]*\))?: //")
|
|
140
|
+
ticket=$(echo "${message}" | grep -oE "#[0-9]+" | head -n1 || true)
|
|
141
|
+
|
|
142
|
+
if [ -n "${ticket}" ]; then
|
|
143
|
+
# The pattern is quoted: a "#" at its start would anchor it at the start of
|
|
144
|
+
# the message
|
|
145
|
+
message="${message/"${ticket} "/}"
|
|
146
|
+
echo "- ${message} (${ticket})"
|
|
147
|
+
else
|
|
148
|
+
echo "- ${message}"
|
|
149
|
+
fi
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# A section of the notes: section <title> <commits> <type>
|
|
153
|
+
section() {
|
|
154
|
+
local title="$1"
|
|
155
|
+
local commits="$2"
|
|
156
|
+
local type="$3"
|
|
157
|
+
|
|
158
|
+
[ -n "${commits}" ] || return 0
|
|
159
|
+
|
|
160
|
+
output "### ${title}"
|
|
161
|
+
output ""
|
|
162
|
+
|
|
163
|
+
while read -r commit; do
|
|
164
|
+
output "$(format_commit "${commit}" "${type}")"
|
|
165
|
+
done <<< "${commits}"
|
|
166
|
+
|
|
167
|
+
output ""
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
# Categorize the commits by type (following git-rules)
|
|
171
|
+
commits_of() {
|
|
172
|
+
echo "${COMMITS}" | grep "^$1" || true
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
BREAKING_CHANGES=$(breaking_changes)
|
|
176
|
+
|
|
177
|
+
if [ -n "${BREAKING_CHANGES}" ]; then
|
|
178
|
+
output "### ⚠️ BREAKING CHANGES"
|
|
179
|
+
output ""
|
|
180
|
+
echo "${BREAKING_CHANGES}" | while IFS= read -r line; do
|
|
181
|
+
output "${line}"
|
|
182
|
+
done
|
|
183
|
+
output ""
|
|
184
|
+
fi
|
|
185
|
+
|
|
186
|
+
section "✨ Features" "$(commits_of feat)" "feat"
|
|
187
|
+
section "🐛 Bug Fixes" "$(commits_of fix)" "fix"
|
|
188
|
+
section "🚨 Hotfixes" "$(commits_of hotfix)" "hotfix"
|
|
189
|
+
section "⚡ Performance" "$(commits_of perf)" "perf"
|
|
190
|
+
section "♻️ Refactoring" "$(commits_of refactor)" "refactor"
|
|
191
|
+
section "📝 Documentation" "$(commits_of docs)" "docs"
|
|
192
|
+
section "🧪 Tests" "$(commits_of test)" "test"
|
|
193
|
+
section "🏗️ Build System" "$(commits_of build)" "build"
|
|
194
|
+
section "👷 CI/CD" "$(commits_of ci)" "ci"
|
|
195
|
+
section "💄 Code Style" "$(commits_of style)" "style"
|
|
196
|
+
section "🔧 Maintenance" "$(commits_of chore)" "chore"
|
|
197
|
+
|
|
198
|
+
# Other commits (not following convention)
|
|
199
|
+
TYPES="feat|fix|hotfix|docs|style|refactor|perf|test|build|ci|chore"
|
|
200
|
+
OTHER=$(echo "${COMMITS}" | grep -vE "^(${TYPES})" || true)
|
|
201
|
+
|
|
202
|
+
if [ -n "${OTHER}" ]; then
|
|
203
|
+
output "### 📦 Other Changes"
|
|
204
|
+
output ""
|
|
205
|
+
while read -r commit; do
|
|
206
|
+
output "- ${commit}"
|
|
207
|
+
done <<< "${OTHER}"
|
|
208
|
+
output ""
|
|
209
|
+
fi
|
|
210
|
+
|
|
211
|
+
# The issues of the release: the tickets of the subjects, and the issues that
|
|
212
|
+
# the footers close
|
|
213
|
+
output "### 🎫 Issues"
|
|
214
|
+
output ""
|
|
215
|
+
ISSUES=$({
|
|
216
|
+
echo "${COMMITS}" | grep -oE "#[0-9]+" || true
|
|
217
|
+
git log "${RANGE}" --pretty=format:"%b" --no-merges \
|
|
218
|
+
| grep -oE "(Closes|Fixes|Resolves) #[0-9]+(, #[0-9]+)*" \
|
|
219
|
+
| grep -oE "#[0-9]+" || true
|
|
220
|
+
} | sed 's/^#//' | sort -nu | sed 's/^/#/')
|
|
221
|
+
|
|
222
|
+
if [ -n "${ISSUES}" ]; then
|
|
223
|
+
output "The issues of this release:"
|
|
224
|
+
output ""
|
|
225
|
+
while read -r issue; do
|
|
226
|
+
output "- ${issue}"
|
|
227
|
+
done <<< "${ISSUES}"
|
|
228
|
+
else
|
|
229
|
+
output "No issues referenced in commits."
|
|
230
|
+
fi
|
|
231
|
+
|
|
232
|
+
output ""
|
|
233
|
+
footer
|
|
234
|
+
|
|
235
|
+
echo ""
|
|
236
|
+
echo "✅ Release notes generated: ${RELEASE_NOTES}"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zairakai/js-dev-tools",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.1",
|
|
4
4
|
"description": "The development toolkit of the JavaScript and TypeScript projects for the web: shared ESLint, Prettier, Stylelint, Vitest, TypeScript and markdownlint rules, Knip, Makefile targets, Git hooks and GitLab CI pipeline templates",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dev-tools",
|