Skip to content

Commit a315acf

Browse files
committed
ci: add changelog fragment tooling (changie + fold script)
Ports the changelog infrastructure from kai-scheduler/KAI-Scheduler (#1839): - hack/changelog-fold.sh: fold unreleased fragments into CHANGELOG.md - Makefile: changie, changelog, changelog-release, changelog-preview targets - .changie.yaml: fix issue URL to point to kai-scheduler/api Unblocks the Release — Prepare Changelog workflow (make changelog-release). Signed-off-by: SiorMeir <msior@nvidia.com>
1 parent efb4ef4 commit a315acf

3 files changed

Lines changed: 84 additions & 1 deletion

File tree

.changie.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ versionExt: md
77
fragmentFileFormat: '{{.Kind}}-{{.Time.Format "20060102-150405"}}'
88
versionFormat: '## [{{.Version}}] - {{.Time.Format "2006-01-02"}}'
99
kindFormat: '### {{.Kind}}'
10-
changeFormat: '- {{.Body}}{{if .Custom.Issue}} [#{{.Custom.Issue}}](https://github.com/kai-scheduler/KAI-Scheduler/issues/{{.Custom.Issue}}){{end}}{{if .Custom.Author}} [{{.Custom.Author}}](https://github.com/{{.Custom.Author}}){{end}}'
10+
changeFormat: '- {{.Body}}{{if .Custom.Issue}} [#{{.Custom.Issue}}](https://github.com/kai-scheduler/api/issues/{{.Custom.Issue}}){{end}}{{if .Custom.Author}} [{{.Custom.Author}}](https://github.com/{{.Custom.Author}}){{end}}'
1111
kinds:
1212
- label: Added
1313
- label: Changed

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
CONTROLLER_TOOLS_VERSION ?= v0.20.1
5+
CHANGIE_VERSION ?= v1.25.0
56

67
LOCALBIN ?= $(shell pwd)/bin
78
$(LOCALBIN):
89
mkdir -p $(LOCALBIN)
910

1011
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
12+
CHANGIE ?= $(LOCALBIN)/changie
1113

1214
# CRDs derived from Kubernetes projects that require the Kubernetes copyright header.
1315
K8S_COPYRIGHTED_MANIFEST_FILES := config/crd/kai.scheduler_topologies.yaml
@@ -51,6 +53,35 @@ manifests: controller-gen ## Generate CustomResourceDefinition objects.
5153
clients: ## Generate clientset, listers, and informers.
5254
hack/update-client.sh
5355

56+
.PHONY: changie
57+
changie: $(CHANGIE) ## Download changie locally if necessary.
58+
$(CHANGIE): $(LOCALBIN)
59+
test -s $(LOCALBIN)/changie || GOBIN=$(LOCALBIN) go install github.com/miniscruff/changie@$(CHANGIE_VERSION)
60+
61+
.PHONY: changelog
62+
changelog: changie ## Add a changelog entry. Agents: make changelog KIND=Fixed BODY="...". Humans: make changelog (interactive).
63+
@if [ -n "$(KIND)" ] && [ -n "$(BODY)" ]; then \
64+
kind_lower=$$(echo "$(KIND)" | tr '[:upper:]' '[:lower:]'); \
65+
ts=$$(date '+%Y%m%d-%H%M%S'); \
66+
out=".changes/unreleased/$${kind_lower}-$${ts}.yaml"; \
67+
printf 'kind: %s\nbody: |-\n %s\n' "$(KIND)" "$(BODY)" > "$${out}"; \
68+
echo "Created $${out}"; \
69+
elif [ -n "$(KIND)" ] || [ -n "$(BODY)" ]; then \
70+
echo "Both KIND and BODY must be set for non-interactive mode"; exit 1; \
71+
else \
72+
$(CHANGIE) new; \
73+
fi
74+
75+
.PHONY: changelog-release
76+
changelog-release: changie ## Fold unreleased fragments into CHANGELOG.md as VERSION and clear them. Usage: make changelog-release VERSION=v0.1.1
77+
@test -n "$(VERSION)" || { echo "VERSION is required, e.g. make changelog-release VERSION=v0.1.1"; exit 1; }
78+
CHANGIE=$(CHANGIE) bash hack/changelog-fold.sh $(VERSION)
79+
80+
.PHONY: changelog-preview
81+
changelog-preview: changie ## Preview the next release section without writing anything. Usage: make changelog-preview VERSION=v0.1.1
82+
@test -n "$(VERSION)" || { echo "VERSION is required, e.g. make changelog-preview VERSION=v0.1.1"; exit 1; }
83+
$(CHANGIE) batch $(VERSION) --dry-run
84+
5485
.PHONY: controller-gen
5586
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
5687
$(CONTROLLER_GEN): $(LOCALBIN)

hack/changelog-fold.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2026 NVIDIA CORPORATION
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
# Fold pending changie fragments into CHANGELOG.md as a new released version section,
6+
# then clear the fragments. CHANGELOG.md is the source of truth — this edits it in place
7+
# and does NOT keep a per-version archive.
8+
#
9+
# Usage: hack/changelog-fold.sh vX.Y.Z
10+
# CHANGIE=/path/to/changie hack/changelog-fold.sh v0.17.0 # override the binary
11+
#
12+
# The new section is rendered by `changie batch --dry-run` (no disk writes, fragments left
13+
# intact) and inserted immediately before the newest existing version heading, keeping one
14+
# blank line between versions per Keep a Changelog. Fragments are removed only after the
15+
# CHANGELOG.md write succeeds.
16+
set -euo pipefail
17+
18+
VERSION="${1:-}"
19+
if [ -z "$VERSION" ]; then
20+
echo "usage: $0 vX.Y.Z" >&2
21+
exit 1
22+
fi
23+
24+
CHANGIE="${CHANGIE:-bin/changie}"
25+
if [ ! -x "$CHANGIE" ]; then
26+
echo "changie not found at '$CHANGIE' — run: make changie" >&2
27+
exit 1
28+
fi
29+
30+
CHANGELOG="CHANGELOG.md"
31+
32+
# Render the version section only (no header, no disk mutation, fragments untouched).
33+
section="$("$CHANGIE" batch "$VERSION" --dry-run)"
34+
if [ -z "$section" ]; then
35+
echo "no unreleased fragments to release for $VERSION" >&2
36+
exit 1
37+
fi
38+
39+
# Insert the section before the first existing "## [" heading (one blank line between).
40+
# Falls back to appending after the header block if the changelog has no versions yet.
41+
SECTION="$section" awk '
42+
BEGIN { sec = ENVIRON["SECTION"] }
43+
/^## \[/ && !ins { print sec "\n"; ins = 1 }
44+
{ print }
45+
END { if (!ins) print "\n" sec }
46+
' "$CHANGELOG" > "$CHANGELOG.tmp"
47+
mv "$CHANGELOG.tmp" "$CHANGELOG"
48+
49+
# Clear the folded fragments (keep the directory + .gitkeep).
50+
find .changes/unreleased -maxdepth 1 -type f -name '*.yaml' -delete
51+
52+
echo "Folded $(basename "$VERSION") into $CHANGELOG and cleared fragments."

0 commit comments

Comments
 (0)