adachsoft/changelog-linter
Composer 安装命令:
composer require adachsoft/changelog-linter
包简介
Changelog linter tool - validate and convert changelog formats
关键字:
README 文档
README
A minimal PHP library for validating and converting changelog formats between JSON and Markdown.
It follows a constrained, explicit changelog schema inspired by Keep a Changelog, with first-class support for the following change sections:
AddedChangedFixedRemovedDeprecatedSecurityMigration Notes(JSON key:migration_notes)
Installation
Install via Composer:
composer require --dev adachsoft/changelog-linter
Usage
CLI Commands
Validate changelog (JSON or Markdown)
vendor/bin/changelog validate --path=changelog.json [--lenient]
vendor/bin/changelog validate --path=CHANGELOG.md [--lenient]
- For
.jsonfiles, validation checks the JSON schema, required fields, version ordering and section keys. - For
.mdfiles, validation parses the Markdown and applies the same rules to the logical model.
--lenient applies only to Markdown input and is ignored for JSON:
- tolerates unknown/unsupported sections (they are reported as ignored),
- allows version headers with or without
vprefix, - recognizes
[Unreleased]section.
Generate Markdown from JSON
vendor/bin/changelog generate-md --input=changelog.json --output=CHANGELOG.md
- Reads a
changelog.jsonfile and renders aCHANGELOG.mdusing the built-in Twig template. - All supported sections, including
Migration Notes, are rendered as dedicated Markdown sections:### Added### Changed### Fixed### Removed### Deprecated### Security### Migration Notes
Generate JSON from Markdown
vendor/bin/changelog generate-json \
--input=CHANGELOG.md \
--output=changelog.json \
[--lenient] [--with-created-at]
Options:
--lenient: enables tolerant parsing/validation mode for Markdown → JSON.--with-created-at: when set, adds or preservescreatedAtfor each version.
Behavior of --with-created-at:
- If the output JSON already exists, the tool reads the existing file and preserves
createdAtfor known versions. - New versions (present only in Markdown) receive a fresh
createdAtvalue. - If
--with-created-atis not provided, nocreatedAtfield is added (the schema allows it to be omitted).
Programmatic Usage
The library can be used directly from PHP code through the public facade (no internal services needed):
use AdachSoft\ChangelogLinter\Facade\ChangelogFacadeFactory;
use AdachSoft\ChangelogLinter\Facade\Dto\GenerateJsonOptionsDto;
// Create the facade (all dependencies are wired automatically)
$facade = ChangelogFacadeFactory::create();
// 1. Validate a changelog file (JSON or Markdown)
$result = $facade->validate('changelog.json');
if (!$result->isValid()) {
// handle ValidationResult with errors
}
$resultMd = $facade->validate('CHANGELOG.md');
// 2. Generate Markdown from JSON
$facade->generateMarkdown('changelog.json', 'CHANGELOG.md');
// 3. Generate JSON from Markdown with options
$options = new GenerateJsonOptionsDto(
inputPath: 'CHANGELOG.md',
outputPath: 'changelog.json',
lenient: true,
withCreatedAt: true,
);
$facade->generateJson($options);
You can also use the facade directly to work with the in-memory changelog model:
use AdachSoft\ChangelogLinter\Facade\Dto\AddVersionEntryDto;
use AdachSoft\ChangelogLinter\Model\ChangeItem;
use AdachSoft\ChangelogLinter\Model\ChangeItemsCollection;
$facade = ChangelogFacadeFactory::create();
// Read from JSON or Markdown
db
$changelog = $facade->readChangelog('changelog.json');
// Add a new version entry with Migration Notes
$dto = new AddVersionEntryDto(
version: '1.2.0',
date: '2025-01-01',
added: new ChangeItemsCollection([new ChangeItem('New feature')]),
changed: new ChangeItemsCollection([]),
fixed: new ChangeItemsCollection([]),
removed: new ChangeItemsCollection([]),
deprecated: new ChangeItemsCollection([]),
security: new ChangeItemsCollection([]),
migrationNotes: new ChangeItemsCollection([new ChangeItem('Run database migrations')]),
);
$updated = $facade->addEntry($changelog, $dto);
$facade->writeChangelog($updated, 'changelog.json');
Composer Scripts
The package can expose convenient composer scripts (depending on your project setup):
composer run changelog:validate # Validate changelog.json or CHANGELOG.md
composer run changelog:generate # Generate Markdown from JSON
composer run changelog:from-md # Generate JSON from Markdown
Configuration (changelog-linter.json)
Optional configuration file located at the repository root.
{
"markdown": {
"version_header_prefix": "v",
"allow_prologue": true
},
"json": {
"created_at_field_name": "createdAt",
"created_at_format": "Y-m-d H:i:s"
}
}
markdown.version_header_prefix: Prefix in version headings in Markdown (default:"v").markdown.allow_prologue: Whether to allow any text between the title and first version (default:true).json.created_at_field_name: Field name for creation timestamp in JSON (default:"createdAt").json.created_at_format: Datetime format forcreatedAt(default:"Y-m-d H:i:s").
File Formats
changelog.json (JSON Schema excerpt)
Root-level fields:
title(string, optional)intro(string, optional)unreleased(object withchanges, optional)versions(array of version objects; required)
unreleased object:
changes(object, same structure as for versions)
Version object:
version(string, X.Y.Z)date(string,YYYY-MM-DD)createdAt(string,YYYY-MM-DD HH:MM:SS; optional)changes(object) – allowed keys:added: array of stringschanged: array of stringsfixed: array of stringsremoved: array of stringsdeprecated: array of stringssecurity: array of stringsmigration_notes: array of strings (Migration Notes)
Example changelog.json
{
"title": "Changelog",
"intro": "All notable changes to this project will be documented in this file.",
"unreleased": {
"changes": {
"added": ["Upcoming feature"],
"migration_notes": ["Run database migrations before deploying"]
}
},
"versions": [
{
"version": "0.3.0",
"date": "2025-11-10",
"createdAt": "2025-11-10 10:00:00",
"changes": {
"added": [
"Support for title/intro/unreleased",
"New sections: Deprecated/Security/Migration Notes"
],
"changed": ["createdAt optional in schema"],
"security": [],
"migration_notes": ["Run migration XYZ before upgrading"]
}
}
]
}
CHANGELOG.md (Markdown)
# Changelog
## [Unreleased]
### Added
- Upcoming feature
### Migration Notes
- Run database migrations before deploying
## [v0.3.0] - 2025-11-10
### Added
- Support for title/intro/unreleased
- New sections: Deprecated/Security/Migration Notes
### Changed
- createdAt optional in schema
### Migration Notes
- Run migration XYZ before upgrading
Validation Rules
The validator checks for:
- Valid JSON format
- Required fields
- Semantic versioning format (
X.Y.Z) - Valid date format (
YYYY-MM-DD) - Optional
createdAtformat (YYYY-MM-DD HH:ii:ss) when present - Versions sorted in descending order
- No duplicate versions
- Valid change section keys (
added,changed,fixed,removed,deprecated,security,migration_notes) - For Markdown: that only supported sections are used (unsupported sections are reported/ignored depending on mode)
Development
Running Tests
composer test
Code Style
composer cs:check # Check code style
composer cs:fix # Fix code style
Static Analysis
composer stan
Requirements
- PHP >= 8.2
- Composer
Dependencies
- justinrainbow/json-schema: JSON Schema validation
- twig/twig: Markdown generation templates
- adachsoft/collection: Immutable collections
- phpunit/phpunit: Testing framework
adachsoft/changelog-linter 适用场景与选型建议
adachsoft/changelog-linter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 31 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「linter」 「changelog」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 adachsoft/changelog-linter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 adachsoft/changelog-linter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 adachsoft/changelog-linter 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lot's of tools for git, file and static source code analysis.
A Deployment/Change Log Schedule and Notes system for SilverStripe sites
Validate Blade templates for syntax errors, security issues, and best practices
An less opinionated version of Laravel Pint.
PHP code linter using Laravel Shift ruleset and PHP-CS-Fixer
Enforce architecture by defining modules with allowed dependencies. Detects forbidden, uncovered, missing and unused module dependencies in PHP projects.
统计信息
- 总下载量: 31
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 6
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-07