Skip to content

Commit 46afc0a

Browse files
committed
Adjustments
1 parent 11f17e5 commit 46afc0a

File tree

5 files changed

+211
-57
lines changed

5 files changed

+211
-57
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
This library adheres to [Semantic Versioning](https://semver.org/) and [Keep a CHANGELOG](https://keepachangelog.com/en/1.0.0/).
4+
5+
## 0.0.1
6+
7+
- Initial testing release.

PUBLISHING.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Publishing to NPM
2+
3+
This package is published to NPM as `@alleyinteractive/changelog-extractor`.
4+
5+
## Prerequisites
6+
7+
1. You need to be a member of the `@alleyinteractive` organization on NPM
8+
2. You need to be logged in: `npm login`
9+
3. Ensure all tests pass: `npm test`
10+
11+
## Publishing Steps
12+
13+
1. Update the version in `package.json`:
14+
```bash
15+
npm version patch # or minor, or major
16+
```
17+
18+
2. Publish to NPM:
19+
```bash
20+
npm publish --access public
21+
```
22+
23+
3. Push the version tag to GitHub:
24+
```bash
25+
git push --follow-tags
26+
```
27+
28+
## After Publishing
29+
30+
Users can then use the package via:
31+
32+
```bash
33+
# Run with npx (no installation)
34+
npx @alleyinteractive/changelog-extractor
35+
36+
# Or install globally
37+
npm install -g @alleyinteractive/changelog-extractor
38+
changelog-extractor
39+
```
40+
41+
## GitHub Action
42+
43+
The GitHub Action in this repository will continue to work alongside the NPM package. The action uses the parser from `src/parser.js` directly.

README.md

Lines changed: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
# Changelog Extractor Action
1+
# Changelog Extractor
22

3-
A GitHub Action that parses [Keep a Changelog](https://keepachangelog.com/) formatted changelog files and extracts structured version information for use in release workflows and other automation.
3+
Parse and extract structured information from [Keep a
4+
Changelog](https://keepachangelog.com/) formatted changelogs. Available as both
5+
a **GitHub Action** and a **CLI tool**.
46

57
## Features
68

7-
- 📝 Parses Keep a Changelog format (like [Mantle Framework](https://github.com/alleyinteractive/mantle-framework))
8-
- 🎯 Extract all versions or a specific version
9-
- 📦 Returns structured data with sections (Added, Changed, Fixed, etc.)
10-
- 🔄 Supports mixed formats (with and without subsections)
11-
- ✅ Comprehensive Jest test suite
12-
- 🚀 Zero build step - pure JavaScript
9+
- Parses Keep a Changelog format (tested with [Mantle Framework](https://github.com/alleyinteractive/mantle-framework) and others)
10+
- Extract all versions or filter to a specific one
11+
- Returns structured data with sections (Added, Changed, Fixed, etc.)
12+
- Handles mixed formats, including versions without subsections
13+
- Available as a CLI tool via npx or as a GitHub Action
14+
- Written in plain JavaScript with no build step required
1315

1416
## Usage
1517

18+
### As a GitHub Action
19+
20+
#### Extract All Versions
21+
1622
### Extract All Versions
1723

1824
By default, the action returns all versions in the changelog:
@@ -69,20 +75,20 @@ jobs:
6975
body: ${{ fromJson(steps.changelog.outputs.result)[0].contents }}
7076
```
7177
72-
## Inputs
78+
#### Action Inputs
7379
7480
| Input | Description | Required | Default |
7581
|-------|-------------|----------|---------|
7682
| `changelog-path` | Path to the changelog file | No | `CHANGELOG.md` |
7783
| `version` | Specific version to extract (e.g., `1.14.0` or `v1.14.0`). Leave empty to return all versions. | No | _(returns all)_ |
7884

79-
## Outputs
85+
#### Action Outputs
8086

8187
| Output | Description |
8288
|--------|-------------|
8389
| `result` | JSON string containing array of parsed version objects |
8490

85-
### Output Structure
91+
#### Output Structure
8692

8793
The `result` output is a JSON string that can be parsed with `fromJson()`:
8894

@@ -105,6 +111,31 @@ The `result` output is a JSON string that can be parsed with `fromJson()`:
105111
- `sections` - Object with lowercase keys (`added`, `changed`, `fixed`, `deprecated`, `removed`, `security`)
106112
- `contents` - Full markdown content for the version (all sections combined, without version header)
107113

114+
### As a CLI Tool
115+
116+
Run directly with npx (no installation required):
117+
118+
```bash
119+
# Extract all versions from CHANGELOG.md
120+
npx @alleyinteractive/changelog-extractor
121+
122+
# Extract specific version
123+
npx @alleyinteractive/changelog-extractor CHANGELOG.md 1.14.0
124+
125+
# Count versions
126+
npx @alleyinteractive/changelog-extractor -l
127+
128+
# Show help
129+
npx @alleyinteractive/changelog-extractor --help
130+
```
131+
132+
Or install globally:
133+
134+
```bash
135+
npm install -g @alleyinteractive/changelog-extractor
136+
changelog-extractor
137+
```
138+
108139
## Supported Changelog Format
109140

110141
This action parses changelogs following the [Keep a Changelog](https://keepachangelog.com/) format:
@@ -137,6 +168,40 @@ This action parses changelogs following the [Keep a Changelog](https://keepachan
137168
- Fixed
138169
- Security
139170

171+
## CLI Options
172+
173+
```
174+
Usage: changelog-extractor [options] [changelog-file] [version]
175+
176+
Options:
177+
-l, --list List the count of versions found and exit
178+
-h, --help Show help message
179+
180+
Arguments:
181+
changelog-file Path to changelog file (default: CHANGELOG.md)
182+
version Specific version to extract (e.g., "1.14.0" or "v1.14.0")
183+
Leave empty to return all versions
184+
```
185+
186+
## Programmatic Usage
187+
188+
You can also use the parser directly in your Node.js code:
189+
190+
```javascript
191+
const { parseChangelog } = require('@alleyinteractive/changelog-extractor');
192+
const fs = require('fs');
193+
194+
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
195+
196+
// Get all versions
197+
const allVersions = parseChangelog(changelog);
198+
199+
// Get specific version
200+
const v1 = parseChangelog(changelog, '1.14.0');
201+
202+
console.log(JSON.stringify(allVersions, null, 2));
203+
```
204+
140205
## Development
141206

142207
### Prerequisites
@@ -163,27 +228,25 @@ npm run test:coverage
163228
npm run test:watch
164229
```
165230

166-
### Testing Locally
167-
168-
You can test the parser directly:
231+
### Local Testing
169232

170-
```javascript
171-
const { parseChangelog } = require('./src/parser');
172-
const fs = require('fs');
173-
174-
const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
175-
const results = parseChangelog(changelog, 'latest');
176-
console.log(JSON.stringify(results, null, 2));
233+
```bash
234+
# Test the CLI locally
235+
node cli.js
236+
node cli.js -l
237+
node cli.js CHANGELOG.md 1.0.0
177238
```
178239

179-
## License
240+
## Changelog
180241

181-
GPL-3.0 - see [LICENSE](LICENSE) for details.
242+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
182243

183-
## Contributing
244+
## Credits
184245

185-
Contributions are welcome! Please feel free to submit a Pull Request.
246+
This project is actively maintained by [Alley Interactive](https://github.com/alleyinteractive).
186247

187-
## Credits
248+
- [Sean Fisher](https://github.com/srtfisher)
249+
250+
## License
188251

189-
Maintained by [Alley Interactive](https://github.com/alleyinteractive).
252+
The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.

cli.js

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,38 @@
11
#!/usr/bin/env node
22

3+
/**
4+
* Changelog Extractor CLI
5+
*
6+
* Parse and extract structured information from Keep a Changelog formatted files.
7+
* Can be run via npx or installed globally.
8+
*
9+
* @package @alleyinteractive/changelog-extractor
10+
* @author Alley Interactive
11+
* @license GPL-3.0
12+
*/
13+
314
const fs = require('fs');
415
const path = require('path');
516
const { parseChangelog } = require('./src/parser');
617

7-
/**
8-
* CLI for testing the changelog parser
9-
* Usage: node cli.js [changelog-file] [version]
10-
*/
11-
1218
function printUsage() {
1319
console.log(`
14-
Usage: node cli.js [options] [changelog-file] [version]
20+
Usage: npx @alleyinteractive/changelog-extractor [options]
1521
1622
Options:
17-
-l, --list List the count of versions found and exit
18-
-h, --help Show this help message
19-
20-
Arguments:
21-
changelog-file Path to changelog file (default: CHANGELOG.md)
22-
version Specific version to extract (e.g., "1.14.0" or "v1.14.0")
23-
Leave empty to return all versions (default: all versions)
23+
-f, --file <path> Path to changelog file (default: CHANGELOG.md)
24+
-v, --version <ver> Specific version to extract (e.g., "1.14.0" or "v1.14.0")
25+
Leave empty to return all versions
26+
-l, --list List the count of versions found and exit
27+
-h, --help Show this help message
2428
2529
Examples:
26-
node cli.js # Parse CHANGELOG.md, extract all versions
27-
node cli.js -l # Count versions in CHANGELOG.md
28-
node cli.js CHANGELOG.md # Same as above
29-
node cli.js CHANGELOG.md 1.14.0 # Extract specific version
30-
node cli.js /tmp/test-changelog.md # Parse specific file, all versions
31-
node cli.js -l /tmp/test-changelog.md # Count versions in specific file
30+
npx @alleyinteractive/changelog-extractor # Parse CHANGELOG.md, all versions
31+
npx @alleyinteractive/changelog-extractor -l # Count versions in CHANGELOG.md
32+
npx @alleyinteractive/changelog-extractor -v 1.14.0 # Extract specific version
33+
npx @alleyinteractive/changelog-extractor -f /tmp/test.md # Parse specific file
34+
npx @alleyinteractive/changelog-extractor -f CHANGELOG.md -v 1.14.0 # Both options
35+
changelog-extractor -l # If installed globally
3236
`);
3337
}
3438

@@ -41,10 +45,21 @@ if (args.includes('--help') || args.includes('-h')) {
4145
}
4246

4347
const listMode = args.includes('-l') || args.includes('--list');
44-
const filteredArgs = args.filter(arg => arg !== '-l' && arg !== '--list');
4548

46-
const changelogFile = filteredArgs[0] || 'CHANGELOG.md';
47-
const versionArg = filteredArgs[1] || null;
49+
// Parse file option
50+
let changelogFile = 'CHANGELOG.md';
51+
const fileIndex = args.findIndex(arg => arg === '-f' || arg === '--file');
52+
if (fileIndex !== -1 && args[fileIndex + 1]) {
53+
changelogFile = args[fileIndex + 1];
54+
}
55+
56+
// Parse version option
57+
let versionArg = null;
58+
const versionIndex = args.findIndex(arg => arg === '-v' || arg === '--version');
59+
if (versionIndex !== -1 && args[versionIndex + 1]) {
60+
versionArg = args[versionIndex + 1];
61+
}
62+
4863
const version = versionArg;
4964

5065
// Read changelog file
@@ -74,7 +89,7 @@ try {
7489

7590
if (results.length === 0) {
7691
console.log('⚠️ No changelog entries found');
77-
process.exit(0);
92+
process.exit(1);
7893
}
7994

8095
console.log(`✅ Found ${results.length} version(s)\n`);

package.json

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
11
{
2-
"name": "action-changelog-extractor",
3-
"version": "1.0.0",
4-
"description": "GitHub Action to parse and extract changelog information",
5-
"main": "src/index.js",
2+
"name": "@alleyinteractive/changelog-extractor",
3+
"version": "0.0.1",
4+
"description": "Parse and extract structured information from Keep a Changelog formatted changelogs",
5+
"main": "src/parser.js",
6+
"bin": {
7+
"changelog-extractor": "./cli.js"
8+
},
69
"scripts": {
710
"test": "jest",
811
"test:watch": "jest --watch",
9-
"test:coverage": "jest --coverage"
12+
"test:coverage": "jest --coverage",
13+
"version:patch": "npm version patch",
14+
"version:minor": "npm version minor",
15+
"version:major": "npm version major",
16+
"prepublishOnly": "npm test",
17+
"release:patch": "npm run version:patch && npm publish --access public && git push --follow-tags",
18+
"release:minor": "npm run version:minor && npm publish --access public && git push --follow-tags",
19+
"release:major": "npm run version:major && npm publish --access public && git push --follow-tags"
1020
},
1121
"keywords": [
12-
"github-action",
1322
"changelog",
1423
"parser",
15-
"release-notes"
24+
"keep-a-changelog",
25+
"release-notes",
26+
"github-action",
27+
"cli"
1628
],
1729
"author": "Alley Interactive",
1830
"license": "GPL-3.0",
31+
"repository": {
32+
"type": "git",
33+
"url": "https://github.com/alleyinteractive/action-changelog-extractor.git"
34+
},
35+
"bugs": {
36+
"url": "https://github.com/alleyinteractive/action-changelog-extractor/issues"
37+
},
38+
"homepage": "https://github.com/alleyinteractive/action-changelog-extractor#readme",
39+
"files": [
40+
"src/",
41+
"cli.js",
42+
"README.md",
43+
"LICENSE"
44+
],
1945
"devDependencies": {
2046
"@types/jest": "^29.5.12",
2147
"@types/node": "^20.11.24",

0 commit comments

Comments
 (0)