Skip to content

Commit 1df68f7

Browse files
ci: Add release with changelog workflow
1 parent 63d2cbb commit 1df68f7

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

docs/changelog.org

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
* Changelog
2+

scripts/generate_changelog.lua

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
local function populate_section(content, name, list)
2+
if #list == 0 then
3+
return
4+
end
5+
content[#content + 1] = '*** ' .. name
6+
vim.list_extend(
7+
content,
8+
vim.tbl_map(function(item)
9+
return '- ' .. item
10+
end, list)
11+
)
12+
content[#content + 1] = ''
13+
end
14+
local function generate_changelog()
15+
local latest_tag = vim.fn.system('git describe --tags `git rev-list --tags --max-count=1`'):gsub('\n', '')
16+
local commits = vim.fn.systemlist('git log ' .. latest_tag .. "..master --pretty=format:'%s'")
17+
local fixes = {}
18+
local features = {}
19+
local breaking_changes = {}
20+
21+
for _, commit in ipairs(commits) do
22+
local type = commit:match('^(.-):')
23+
if type then
24+
type = type
25+
local message = vim.trim(commit:sub(#type + 2))
26+
if vim.endswith(type, '!') then
27+
table.insert(breaking_changes, message)
28+
elseif vim.startswith(type, 'fix') then
29+
table.insert(fixes, message)
30+
elseif vim.startswith(type, 'feat') or vim.startswith(type, 'feature') then
31+
table.insert(features, message)
32+
end
33+
end
34+
end
35+
local new_tag = arg[1]
36+
local changelog = vim.fn.readfile('./docs/changelog.org')
37+
local start = { unpack(changelog, 1, 2) }
38+
local remaining = { unpack(changelog, 3) }
39+
40+
local new_content = {
41+
'** ' .. new_tag,
42+
'- Date: [[' .. os.date('%Y-%m-%d') .. ']]',
43+
('- [[https://github.com/nvim-orgmode/orgmode/compare/%s...%s][Compare]]'):format(latest_tag, new_tag),
44+
('- [[https://github.com/nvim-orgmode/orgmode/releases/tag/%s][Link to release]]'):format(latest_tag),
45+
'',
46+
}
47+
populate_section(new_content, 'Breaking changes', breaking_changes)
48+
populate_section(new_content, 'Features', features)
49+
populate_section(new_content, 'Bug fixes', fixes)
50+
51+
local new_changelog = vim.list_extend(start, new_content)
52+
new_changelog = vim.list_extend(new_changelog, remaining)
53+
54+
vim.fn.writefile(new_changelog, './docs/changelog.org')
55+
end
56+
57+
generate_changelog()

0 commit comments

Comments
 (0)