@kaynooo/cli-changelog 0.0.0-stage → 2.4.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Anthony Fu <https://github.com/antfu>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,213 @@
1
- # Temporary Holding Version
1
+ # @kaynooo/cli-changelog
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Generate changelog for Forgejo, Gitea or GitHub releases from [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), and post it to Discord.
4
+
5
+ > **Bun only.** This tool runs on [Bun](https://bun.sh) and uses Bun-native APIs (`Bun.$`, `Bun.file`, `Bun.Glob`, global `fetch`). It is not meant to run under Node.
6
+
7
+ ## Features
8
+
9
+ - Support exclamation mark as breaking change, e.g. `chore!: drop node v10`
10
+ - Grouped scope in changelog
11
+ - Issues linked from the subject (`#12`) and from `#12 - title` lines in the commit body
12
+ - Create the release note, or update the existing one
13
+ - Post the release to a Discord webhook
14
+ - Open the notes with the release's section of a hand-written "what's new" page
15
+ - List contributors with their avatars
16
+ - Upload assets to the release
17
+
18
+ ## Format
19
+
20
+ A note opens with a one-line summary (`3 new · 3 fixed · 6 maintenance · by @kaynooo · v1.5.0 → v1.6.6`), then lists:
21
+
22
+ - **⚠️ Breaking**, **✨ New**, **🔧 Fixed** and **⚡ Faster**, each line ending with its commit and issue links
23
+ - refactor, docs, build, types, test, style and ci commits folded into one collapsed **🧹 Maintenance** block
24
+ - the contributors' avatars and a link to the full diff
25
+
26
+ A type set to `{ title, folded: true }` in `types` joins the maintenance block, and `titles.maintenance` renames it.
27
+
28
+ With [`highlights`](#open-the-notes-with-highlights), a **🌟 Highlights** section comes right after the summary.
29
+
30
+ ## Discord
31
+
32
+ Once the release is out, it is posted to the webhook in `DISCORD_WEBHOOK` (or `discordWebhook` / `--discord-webhook`) as one embed: the same sections with each issue's title beside it, maintenance as a count line, and links to the full note and the diff. A note too long for Discord's 4096 characters ends with `…and N more`. Nothing is posted when no webhook is set.
33
+
34
+ ```yml
35
+ - run: bunx @kaynooo/cli-changelog
36
+ env:
37
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
38
+ DISCORD_WEBHOOK: ${{secrets.DISCORD_WEBHOOK}}
39
+ ```
40
+
41
+ ## Forge
42
+
43
+ A repo whose origin is on github.com releases to GitHub, with `GITHUB_TOKEN` or else `gh auth token`. Any other repo releases to Forgejo or Gitea at the `forge` host of `~/.config/kaynooo-cli/config.json`, or at origin's host when that is unset. `baseUrl` and `provider` (`gitea` or `github`) in the config override both.
44
+
45
+ ## Usage
46
+
47
+ In Forgejo, Gitea or GitHub Actions (under `.github/workflows/` on GitHub):
48
+
49
+ ```yml
50
+ # .gitea/workflows/release.yml
51
+
52
+ name: Release
53
+
54
+ permissions:
55
+ contents: write
56
+
57
+ on:
58
+ push:
59
+ tags:
60
+ - 'v*'
61
+
62
+ jobs:
63
+ release:
64
+ runs-on: ubuntu-latest
65
+ steps:
66
+ - uses: actions/checkout@v4
67
+ with:
68
+ fetch-depth: 0
69
+
70
+ - name: Setup Bun
71
+ uses: oven-sh/setup-bun@v2
72
+ with:
73
+ bun-version: latest
74
+
75
+ - run: bunx @kaynooo/cli-changelog
76
+ env:
77
+ GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
78
+ ```
79
+
80
+ It will be triggered whenever you push a tag that starts with `v`.
81
+
82
+ ## Configuration
83
+
84
+ Put a `changelog.config.{ts,mts,js,mjs,json}` file in the project root, or a `changelog` field in `package.json`. CLI flags override the file, which overrides `package.json`.
85
+
86
+ ### Roll up patches into minor releases
87
+
88
+ If you cut several patches between minor releases, `rollup` makes a minor (or major) note list every commit since the previous minor (or major), instead of only since the last patch:
89
+
90
+ ```ts
91
+ // changelog.config.ts
92
+ import { defineConfig } from '@kaynooo/cli-changelog'
93
+
94
+ export default defineConfig({
95
+ rollup: {
96
+ // On a `x.y.0` release, start from the previous `x.(y-1).0` tag,
97
+ // absorbing every patch in between.
98
+ minor: true,
99
+ // On a `x.0.0` release, start from the previous `(x-1).0.0` tag,
100
+ // absorbing every minor and patch in between.
101
+ major: true,
102
+ },
103
+ })
104
+ ```
105
+
106
+ Both default to `false`.
107
+
108
+ ### Follow only the first parent
109
+
110
+ After a `git merge --allow-unrelated-histories` (or any big merge), the note would list every commit the merge brought in. `firstParent` walks only the first parent of each merge, so the merge shows as itself:
111
+
112
+ ```ts
113
+ // changelog.config.ts
114
+ import { defineConfig } from '@kaynooo/cli-changelog'
115
+
116
+ export default defineConfig({
117
+ firstParent: true,
118
+ })
119
+ ```
120
+
121
+ It defaults to `false`. The tag the range starts from and the first commit are also looked up along the first parent.
122
+
123
+ This also drops the commits of a feature branch merged with a merge commit: only the merge's own message is read. It suits repos that squash or fast-forward, plus a one-off import.
124
+
125
+ ### Open the notes with highlights
126
+
127
+ Commit lines say what changed, not why it matters. `highlights` points at a Markdown page you write by hand, one `## <version>` section per release, and opens the notes with the section of the version being released, under **🌟 Highlights**, ending on a link to it:
128
+
129
+ ```ts
130
+ // changelog.config.ts
131
+ import { defineConfig } from '@kaynooo/cli-changelog'
132
+
133
+ export default defineConfig({
134
+ highlights: {
135
+ file: 'docs/whats-new.md',
136
+ url: 'https://docs.example.com/whats-new/',
137
+ },
138
+ })
139
+ ```
140
+
141
+ ```md
142
+ ## 1.4.0
143
+
144
+ - `render` prints a page without a server: see [the CLI](/reference/cli#render).
145
+ ```
146
+
147
+ - The section is found by the version without the tag's prefix: `## 1.4.0` for `v1.4.0`. It runs to the next `## ` heading; its own headings are demoted one level, and the page's frontmatter is skipped.
148
+ - Links resolve against `url`, so `/reference/cli` becomes `https://docs.example.com/reference/cli`. When the site serves a page elsewhere than its file, `link` maps each target as written before it resolves, `undefined` keeping it: `link: target => target.replace(/\.md(?=#|$)/, '')` turns `cli.md#render` into `cli#render`. The closing link goes to the version's heading on the page, slugged as GitHub does (`#140`).
149
+ - The Discord post opens with the same section, its headings in bold. When the post runs past Discord's limit, commits are dropped first, then the section's last lines, the link to the page always kept.
150
+ - Without the file or a section for the version, the notes are as they would be without the option. `titles.highlights` renames the section.
151
+
152
+ ## Preview Locally
153
+
154
+ ```bash
155
+ bunx @kaynooo/cli-changelog --dry-run
156
+ ```
157
+
158
+ ## JSON output
159
+
160
+ `--json` prints the result as JSON on stdout and nothing else: the progress goes to stderr, and a failure is `{"error": "...", "hint"?: "..."}` on stderr with the usual exit code.
161
+
162
+ `changelog --json` (also with `--dry-run` or `--output`):
163
+
164
+ ```json
165
+ { "command": "release", "status": "released", "from": "v1.4.2", "to": "main", "commits": 3, "notes": "...", "url": "https://git.example.org/o/r/releases/tag/v1.4.3", "output": null, "assetsFailed": 0, "discord": null }
166
+ ```
167
+
168
+ `status` is `released`, `dry-run` or `saved`; `url` is the release page once released, `output` the file written by `--output`, `discord` is `posted`, `failed` or `null` without a webhook. The exit code is 1 when an asset upload or the Discord post failed, with the report still printed.
169
+
170
+ `changelog undo --json` asks no question, so removing something needs `--yes` (or `--dry-run`, exit 2 otherwise) and the release note goes only with `--note`:
171
+
172
+ ```json
173
+ { "command": "undo", "status": "undone", "tag": "v1.4.2", "releaseNote": false, "remoteTag": true, "localTag": true, "commitReset": { "hash": "...", "subject": "chore: release v1.4.2" } }
174
+ ```
175
+
176
+ `status` is `undone`, `nothing`, `dry-run` or `declined`; each flag says whether that step was taken (or, on a dry run, would be), and `commitReset` is `null` when the commit is left alone.
177
+
178
+ ## Undo a Release
179
+
180
+ Rolled a bad release? `undo` deletes the remote tag, the local tag, and soft-resets the version-bump commit (changes are kept in your working tree). The commit is only reset when the tag points at `HEAD`.
181
+
182
+ ```bash
183
+ bunx @kaynooo/cli-changelog undo v1.4.2
184
+ ```
185
+
186
+ The tag is optional - omit it to undo the latest tag (you'll be warned which one):
187
+
188
+ ```bash
189
+ bunx @kaynooo/cli-changelog undo
190
+ ```
191
+
192
+ The Gitea release note is **not** removed by default - you're asked about it interactively. Pass `--note` to include it non-interactively.
193
+
194
+ | Flag | Description |
195
+ | ----------------- | ----------------------------------------------------------------------------------- |
196
+ | `--note` | Also delete the Gitea release note (skips the question) |
197
+ | `--dry-run` | Preview what would be removed, without deleting (`--dry` is kept as an alias) |
198
+ | `--yes` | Skip confirmation prompts (for CI/scripts) |
199
+ | `-r`, `--repo` | Repository to undo in, e.g. `kaynooo/cli` (`--gitea` is kept as an alias) |
200
+
201
+ The short `-t` for `--token` was removed, pass `--token` or set `GITHUB_TOKEN`.
202
+
203
+ ## Why?
204
+
205
+ I used to use [`conventional-github-releaser`](https://github.com/conventional-changelog/releaser-tools/tree/master/packages/conventional-github-releaser) for almost all my projects. Until I found that it [does NOT support using exclamation marks for breaking changes](https://github.com/conventional-changelog/conventional-changelog/issues/648) - hiding those important breaking changes in the changelog without the awareness from maintainers.
206
+
207
+ ## Credits
208
+
209
+ This is a Gitea / Forgejo port of [`changelogithub`](https://github.com/antfu/changelogithub) by [Anthony Fu](https://github.com/antfu).
210
+
211
+ ## License
212
+
213
+ [MIT](./LICENSE) License © 2022 [Anthony Fu](https://github.com/antfu)