A MoonBit-native public API compatibility checker for semver-aware package releases.
中文简介:MoonCompat 用 MoonBit 实现 MoonBit 包的公开 API 兼容性检查。它比较两个版本的 .mbti 接口,识别破坏性变更,给出 SemVer 建议,并能作为 GitHub Actions 的发布门禁。
git clone https://github.com/404-32/byc002.git
cd byc002
moon run cmd/main -- --helpmoon run cmd/main -- check fixtures/demo/base fixtures/demo/headMoonCompat: fixtures/demo/base -> fixtures/demo/head
BREAKING: changed public function `parse`
before: pub fn parse(String) -> Forecast
after: pub fn parse(String, strict? : Bool) -> Forecast raise
...
Summary: 3 breaking, 1 compatible, 2 unchanged
Recommended bump: majormoon info
git worktree add /tmp/mooncompat-base v0.1.0
(cd /tmp/mooncompat-base && moon info)
moon run cmd/main -- check /tmp/mooncompat-base . \
--format json \
--output mooncompat-report.jsonmooncompat check <base-path> <head-path> [options]
mooncompat snapshot <path> [--output report.json]
mooncompat rules
mooncompat version--format text|json Report format (default: text)
-o, --output FILE Write the report to FILE
--fail-on breaking|never Exit 1 on breaking changes (default: breaking)
-q, --quiet Hide before/after signatures in text output| Code | Meaning |
|---|---|
| 0 | No breaking changes, or --fail-on never |
| 1 | Breaking changes detected |
| 2 | Invalid input, unsupported .mbti syntax, parse failure, or I/O error |
name: API compatibility
on: [pull_request]
jobs:
api-compat:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up MoonBit
run: |
curl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash
echo "$HOME/.moon/bin" >> "$GITHUB_PATH"
- name: Generate interfaces
run: |
git worktree add /tmp/base "${{ github.event.pull_request.base.sha }}"
(cd /tmp/base && moon info)
moon info
- name: Check public API
run: moon run cmd/main -- check /tmp/base . --format json --output api-report.json
- uses: actions/upload-artifact@v4
if: always()
with:
name: mooncompat-report
path: api-report.json.mbti files
|
v
line-aware parser -> normalized declaration IR
|
v
package matcher -> compatibility comparator -> SemVer recommendation
|
+--> deterministic JSON
+--> human-readable text
+--> CI exit statusmoon check --deny-warn
moon test --deny-warn
moon fmtbash scripts/test-cli.shbash scripts/check-real-packages.shbash scripts/check-self-api.shpub struct Change {
package_id : String
name : String
declaration_kind : String
kind : ChangeKind
severity : ChangeSeverity
before : String
after : String
message : String
}pub enum ChangeKind {
PackageRenamed
Removed
Added
DeclarationChanged
}pub enum ChangeSeverity {
Breaking
Compatible
}pub enum DeclarationKind {
Function
Struct
Enum
Type
Error
Trait
Impl
Value
Other
}pub enum VersionBump {
Major
Minor
Patch
}fn compare_api_sets(base : Array[ApiSnapshot], head : Array[ApiSnapshot], base_label~ : String, head_label~ : String) -> CompatibilityReportInstall
Download zipA MoonBit-native public API compatibility checker for semver-aware package releases.