Skip to content

Commit 8dd150d

Browse files
committed
feat: Refactored the source to TypeScript
- The source is now strongly typed TypeScript - We support both ESM and CJS user config files now - Fixed a bug with include_commit_body which always overrode the user config file's value - Switched from npm to pnpm - Switched from ncc to esbuild - Updated all dependencies - Improved the indenting of commit body text: now all lines are indented, not just the first one - Replaced deprecated substr with substring
1 parent 90f8dd1 commit 8dd150d

24 files changed

+25997
-37491
lines changed

.eslintrc.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/run.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ jobs:
1111

1212
steps:
1313
- name: Checkout locally
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v6
1515
if: ${{ env.ACT }}
1616
with:
1717
path: "tag-changelog"
1818

1919
- name: Checkout GitHub
20-
uses: actions/checkout@v2
20+
uses: actions/checkout@v6
2121
if: ${{ !env.ACT }}
2222

2323
- name: Create latest tag
@@ -35,13 +35,14 @@ jobs:
3535
uses: ./
3636
with:
3737
token: ${{ secrets.GITHUB_TOKEN }}
38+
include_commit_body: true
3839
exclude_types: other,doc,chore,build
3940

4041
- name: Create release
4142
uses: softprops/action-gh-release@v2
4243
if: ${{ !env.ACT }}
4344
with:
44-
tag_name: ${{ github.ref }}
45-
name: Release ${{ github.ref }}
45+
tag_name: ${{ github.ref_name }}
46+
name: Release ${{ github.ref_name }}
4647
body: ${{ steps.changelog.outputs.changes }}
4748
token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
22
.secrets
3+
.claude

CLAUDE.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
tag-changelog is a GitHub Action that generates changelogs from conventional commits between git tags. It parses commit messages, groups them by type, and outputs formatted changelog text. It runs on Node 20. Source is TypeScript with ESM imports, bundled to a single file via esbuild.
8+
9+
## Commands
10+
11+
- `pnpm test` — run Mocha tests (`test/*.spec.ts`)
12+
- `pnpm check` — lint and auto-fix with ESLint + Prettier, then type-check with `tsc --noEmit`
13+
- `pnpm package` — check then bundle `src/index.ts``dist/index.js` via esbuild
14+
- `pnpm act` — package and test locally with `act` (GitHub Actions local runner)
15+
16+
Run a single test file: `pnpm mocha --require tsx test/parseCommitMessage.spec.ts`
17+
18+
## Architecture
19+
20+
All source is in `src/` (TypeScript), tests in `test/`, bundled output in `dist/`. Shared type definitions are in `src/types.ts`.
21+
22+
**`src/index.ts`** — Action entry point. Reads GitHub Action inputs (`token`, `exclude_types`, `include_commit_body`, `config_file`), fetches tags and commits via GitHub API, processes commits through the pipeline, and sets two outputs: `changelog` (with version header) and `changes` (without header).
23+
24+
**Processing pipeline:**
25+
26+
1. `parseCommitMessage.ts` — Parses conventional commit format using `@conventional-commits/parser`. Extracts type, scope, subject, body, breaking change notes, and PR number (`#123` pattern). Non-conventional commits fall back to type "other".
27+
2. `groupByType.ts` — Groups parsed commits by type into an ordered array, sorted by the type order defined in config.
28+
3. `generateChangelog.ts` — Filters excluded types, renders each type section and breaking change notes using config render functions, wraps with version header.
29+
4. `translateType.ts` — Maps commit type strings (e.g., "feat") to human-readable labels (e.g., "New Features") using config.
30+
31+
**`src/defaultConfig.ts`** — Default configuration defining type groups/labels, render functions (`renderTypeSection`, `renderNotes`, `renderChangelog`), and options (`excludeTypes`, `includeCommitBody`). Users can provide a custom JS config file that gets merged via `Object.assign`.
32+
33+
## Key Details
34+
35+
- `dist/index.js` is the bundled artifact that GitHub Actions runs. It must be rebuilt (`pnpm package`) after any `src/` changes and committed.
36+
- Code style: Prettier with 140 char print width, avoid arrow parens, ES5 trailing commas. ESLint with typescript-eslint enforces no-var, prefer-const, eqeqeq.
37+
- Tests use Node's built-in `assert` with Mocha (via `tsx` loader) — no assertion library needed.
38+
- Only `src/` modules (not `index.ts`) have test coverage; `index.ts` is integration-level (GitHub API calls).

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424

2525
steps:
2626
- name: Checkout
27-
uses: actions/checkout@latest
27+
uses: actions/checkout@v6
2828

2929
- name: Create changelog text
3030
id: changelog
@@ -36,8 +36,8 @@ jobs:
3636
- name: Create release
3737
uses: softprops/action-gh-release@v2
3838
with:
39-
tag_name: ${{ github.ref }}
40-
name: Release ${{ github.ref }}
39+
tag_name: ${{ github.ref_name }}
40+
name: Release ${{ github.ref_name }}
4141
body: ${{ steps.changelog.outputs.changes }}
4242
token: ${{ secrets.GITHUB_TOKEN }}
4343
```
@@ -64,12 +64,12 @@ jobs:
6464
config_file: .github/tag-changelog-config.js
6565
```
6666

67-
The config file can be used to map commit types to changelog labels, to override the rendering of changelog sections, and the rendering of the overall changelog. You only need to override the things you want to override. For example, you can leave out `renderTypeSection` and `renderChangelog` and only include the `types` config; the [default config](https://github.com/loopwerk/tag-changelog/blob/main/src/defaultConfig.js) will be used for whatever is not overriden.
67+
The config file can be used to map commit types to changelog labels, to override the rendering of changelog sections, and the rendering of the overall changelog. You only need to override the things you want to override. For example, you can leave out `renderTypeSection` and `renderChangelog` and only include the `types` config; the [default config](https://github.com/loopwerk/tag-changelog/blob/main/src/defaultConfig.ts) will be used for whatever is not overriden.
6868

6969
### Example config file:
7070

7171
```javascript
72-
module.exports = {
72+
export default {
7373
types: [
7474
{ types: ["feat", "feature"], label: "🎉 New Features" },
7575
{ types: ["fix", "bugfix"], label: "🐛 Bugfixes" },
@@ -86,7 +86,7 @@ module.exports = {
8686
8787
excludeTypes: ["other"],
8888
89-
renderTypeSection: function (label, commits) {
89+
renderTypeSection(label, commits) {
9090
let text = `\n## ${label}\n`;
9191

9292
commits.forEach(commit => {
@@ -99,9 +99,9 @@ module.exports = {
9999
return text;
100100
},
101101

102-
renderChangelog: function (release, changes) {
102+
renderChangelog(release, changes) {
103103
const now = new Date();
104-
return `# ${release} - ${now.toISOString().substr(0, 10)}\n` + changes + "\n\n";
104+
return `# ${release} - ${now.toISOString().substring(0, 10)}\n` + changes + "\n\n";
105105
},
106106
};
107107
```
@@ -140,4 +140,4 @@ Thanks to [Helmisek/conventional-changelog-generator](https://github.com/Helmise
140140

141141
## Support
142142

143-
Commercial support is available via [Loopwerk](https://www.loopwerk.io/open-source/support/).
143+
Commercial support is available via [Loopwerk](https://www.loopwerk.io/open-source/support/).

action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ inputs:
1414
include_commit_body:
1515
description: Whether to include the commit body in the changelog
1616
required: false
17-
default: "false"
1817
config_file:
19-
description: Location of the config JSON file
18+
description: Location of the config JS file
2019
required: false
2120
outputs:
2221
changelog:

0 commit comments

Comments
 (0)