Skip to content

Commit b7eb3ed

Browse files
committed
changelog creator
Signed-off-by: Ali Caglayan <alizter@gmail.com>
1 parent f535d4c commit b7eb3ed

5 files changed

Lines changed: 143 additions & 0 deletions

File tree

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ dev-switch:
8787
opam switch create -y . $(TEST_OCAMLVERSION) --deps-only --with-test
8888
opam install -y --update-invariant ocaml.$(TEST_OCAMLVERSION) $(TEST_DEPS) $(DEV_DEPS)
8989

90+
.PHONY: changelog
91+
changelog:
92+
$(BIN) exec -- doc/changes/add.exe
93+
94+
.PHONY: compile-changelog
95+
compile-changelog:
96+
- $(BIN) build @doc/changes/compile-changelog
97+
$(BIN) promote
98+
rm -rf doc/changes/unreleased
99+
90100
.PHONY: test
91101
test: $(BIN)
92102
$(BIN) runtest

doc/changes/add.ml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
open Stdune
2+
module Console = Dune_console
3+
4+
(** This script generates a changelog entry for a PR. It asks the user for
5+
information about the pull request and then generates a file in the
6+
[output_directory]. *)
7+
8+
let output_directory =
9+
Path.source (Path.Source.of_string "doc/changes/unreleased")
10+
11+
let () =
12+
Console.printf "Hello, let's create a changelog entry!";
13+
Console.printf "What is the change about?";
14+
let description = read_line () in
15+
Console.printf "PR number? (Leave blank if you don't know)";
16+
let pr_number =
17+
match read_line () with
18+
| "" -> "????"
19+
| s -> s
20+
in
21+
Console.printf "What is your username?";
22+
let username = read_line () in
23+
Console.printf "Which issue numbers does this change fix?";
24+
let issues =
25+
match read_line () with
26+
| "" -> ""
27+
| s ->
28+
String.split ~on:' ' s
29+
|> List.map ~f:(fun s -> "#" ^ s)
30+
|> String.enumerate_and
31+
|> fun x -> ", fixes " ^ x
32+
in
33+
let pp =
34+
Pp.concat
35+
[ Pp.verbatim "- "
36+
; Pp.box
37+
(Pp.textf "%s (#%s%s, @%s)" description pr_number issues username)
38+
; Pp.newline
39+
]
40+
in
41+
let entry_file =
42+
Path.append_source output_directory
43+
(Path.Source.of_string (pr_number ^ "_" ^ username))
44+
in
45+
Path.mkdir_p output_directory;
46+
Io.write_lines entry_file [ Format.asprintf "%a" Pp.to_fmt pp ]

doc/changes/add.t

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Testing the changelog adding script
2+
3+
$ cat > user_response << EOF
4+
> Changelog description that is long enough to be wrapped to the next line
5+
> 1234
6+
> SomeGithubUser
7+
> 123 456 789
8+
> EOF
9+
10+
$ ./add.exe < user_response
11+
Hello, let's create a changelog entry!
12+
What is the change about?
13+
PR number? (Leave blank if you don't know)
14+
What is your username?
15+
Which issue numbers does this change fix?
16+
17+
$ ls doc/changes/unreleased
18+
1234_SomeGithubUser
19+
$ cat doc/changes/unreleased/*
20+
- Changelog description that is long enough to be wrapped to the next line
21+
(#1234, fixes #123, #456 and #789, @SomeGithubUser)
22+
23+
24+
Testing some edge cases
25+
26+
$ cat > user_response << EOF
27+
> Changelog description that is long enough to be wrapped to the next line. \
28+
> This one takes teh cake for being especially long.
29+
>
30+
> AnotherUser
31+
>
32+
> EOF
33+
34+
$ ./add.exe < user_response
35+
Hello, let's create a changelog entry!
36+
What is the change about?
37+
PR number? (Leave blank if you don't know)
38+
What is your username?
39+
Which issue numbers does this change fix?
40+
41+
$ ls doc/changes/unreleased
42+
1234_SomeGithubUser
43+
????_AnotherUser
44+
$ cat doc/changes/unreleased/*
45+
- Changelog description that is long enough to be wrapped to the next line
46+
(#1234, fixes #123, #456 and #789, @SomeGithubUser)
47+
48+
- Changelog description that is long enough to be wrapped to the next line.
49+
This one takes teh cake for being especially long. (#????, @AnotherUser)
50+

doc/changes/dune

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(executable
2+
(name add)
3+
(libraries stdune pp dune_console))
4+
5+
(cram
6+
(deps add.exe))
7+
8+
(rule
9+
(alias compile-changelog)
10+
(deps
11+
(glob_files unreleased/*))
12+
(action
13+
(with-stdout-to
14+
changes-new.md
15+
(progn
16+
(echo "Unreleased\n")
17+
(echo "----------\n")
18+
(echo "\n")
19+
(cat %{deps})
20+
(cat ../../CHANGES.md)))))
21+
22+
(rule
23+
(alias compile-changelog)
24+
(action
25+
(diff ../../CHANGES.md changes-new.md)))

doc/hacking.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,18 @@ For project names, use the following capitalization:
389389
- **PPX,** rather than ppx or Ppx; ``ppxlib``
390390
- **UTop,** rather than utop or Utop.
391391
392+
Changelog
393+
=========
394+
395+
All changes observable by the user should be documented in the changelog.
396+
397+
Use ``make changelog`` to run an interactive script for adding a changelog
398+
entry. Unreleased changes are collected in their own files in the
399+
``doc/changes/unreleased`` directory.
400+
401+
During the release process, the changelog entries will be compiled into
402+
``CHANGES.md``.
403+
392404
Vendoring
393405
=========
394406

0 commit comments

Comments
 (0)