🧪 Run Tests

github-header

Swift 公共 API 差异

此工具允许比较 swift (sdk) 项目的 2 个版本,并以人类可读的方式列出所有更改。

它利用在 swift 项目归档期间生成的 .swiftinterface 文件,并使用 swift-syntax 解析它们。

贡献

我们强烈鼓励您为我们的存储库贡献代码。 在我们的贡献指南中了解更多信息

要求

用法

从项目到输出

swift run public-api-diff \
    project \
    --platform iOS \
    --new "develop~https://github.com/Adyen/adyen-ios.git" \
    --old "5.12.0~https://github.com/Adyen/adyen-ios.git"
swift run public-api-diff \
    project \
    --platform macOS \
    --new "main~https://github.com/Adyen/adyen-swift-public-api-diff" \
    --old "0.4.0~https://github.com/Adyen/adyen-swift-public-api-diff"
--help
USAGE: public-api-diff project --new <new> --old <old> --platform <platform> [--scheme <scheme>] [--swift-interface-type <swift-interface-type>] [--output <output>] [--log-output <log-output>] [--log-level <log-level>]

OPTIONS:
  --new <new>             Specify the updated version to compare to
  --old <old>             Specify the old version to compare to
  --platform <platform>   The platform to build the project for (iOS/macOS)
  --scheme <scheme>       [Optional] Which scheme to build (Needed when
                          comparing 2 xcode projects)
  --swift-interface-type <swift-interface-type>
                          [Optional] Specify the type of .swiftinterface you
                          want to compare (public/private) (default: public)
  --output <output>       [Optional] Where to output the result (File path)
  --log-output <log-output>
                          [Optional] Where to output the logs (File path)
  --log-level <log-level> [Optional] The log level to use during execution
                          (default: default)
  -h, --help              Show help information.

.swiftinterface 到输出

1. 使用 BUILD_LIBRARY_FOR_DISTRIBUTION=YES 构建项目的 2 个版本

xcodebuild clean build \
    -scheme "YOUR_TARGET_NAME" \
    -derivedDataPath .build \
    -sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" \
    -destination "generic/platform=iOS" \
    BUILD_LIBRARY_FOR_DISTRIBUTION=YES

2..swiftinterface 文件提供给公共 API 差异工具

swift run public-api-diff \
    swift-interface \
    --new "new/path/to/project.swiftinterface" \
    --old "old/path/to/project.swiftinterface"
--help
USAGE: public-api-diff swift-interface --new <new> --old <old> [--target-name <target-name>] [--old-version-name <old-version-name>] [--new-version-name <new-version-name>] [--output <output>] [--log-output <log-output>] [--log-level <log-level>]

OPTIONS:
  --new <new>             Specify the updated .swiftinterface file to compare to
  --old <old>             Specify the old .swiftinterface file to compare to
  --target-name <target-name>
                          [Optional] The name of your target/module to show in
                          the output
  --old-version-name <old-version-name>
                          [Optional] The name of your old version (e.g. v1.0 /
                          main) to show in the output
  --new-version-name <new-version-name>
                          [Optional] The name of your new version (e.g. v2.0 /
                          develop) to show in the output
  --output <output>       [Optional] Where to output the result (File path)
  --log-output <log-output>
                          [Optional] Where to output the logs (File path)
  --log-level <log-level> [Optional] The log level to use during execution
                          (default: default)
  -h, --help              Show help information.

.framework 到输出

swift run public-api-diff \
    framework \
    --target-name "TargetName" \
    --new "new/path/to/project.framework" \
    --old "old/path/to/project.framework"
--help
USAGE: public-api-diff framework --new <new> --old <old> --target-name <target-name> [--swift-interface-type <swift-interface-type>] [--old-version-name <old-version-name>] [--new-version-name <new-version-name>] [--output <output>] [--log-output <log-output>] [--log-level <log-level>]

OPTIONS:
  --new <new>             Specify the updated .framework to compare to
  --old <old>             Specify the old .framework to compare to
  --target-name <target-name>
                          The name of your target/module to show in the output
  --swift-interface-type <swift-interface-type>
                          [Optional] Specify the type of .swiftinterface you
                          want to compare (public/private) (default: public)
  --old-version-name <old-version-name>
                          [Optional] The name of your old version (e.g. v1.0 /
                          main) to show in the output
  --new-version-name <new-version-name>
                          [Optional] The name of your new version (e.g. v2.0 /
                          develop) to show in the output
  --output <output>       [Optional] Where to output the result (File path)
  --log-output <log-output>
                          [Optional] Where to output the logs (File path)
  --log-level <log-level> [Optional] The log level to use during execution
                          (default: default)
  -h, --help              Show help information.

Release 构建

创建

swift build --configuration release

运行

./public-api-diff \
    project \
    --new "develop~https://github.com/Adyen/adyen-ios.git" \ 
    --old "5.12.0~https://github.com/Adyen/adyen-ios.git"
./public-api-diff \
    swift-interface \
    --new "new/path/to/project.swiftinterface" \
    --old "old/path/to/project.swiftinterface"
./public-api-diff \
    framework \
    --target-name "TargetName" \
    --new "new/path/to/project.framework" \
    --old "old/path/to/project.framework"

Github Action

public-api-diff 可以通过提供的 github action 轻松使用,它会在 PR 上创建一个注释(如果适用),并将其添加到 Github 步骤摘要中。

- name: 🔍 Detect Changes
  uses: Adyen/adyen-swift-public-api-diff@0.4.0
  with:
    platform: "iOS"
    new: "develop~https://github.com/Adyen/adyen-ios.git"
    old: "5.12.0~https://github.com/Adyen/adyen-ios.git"

参见: 示例工作流程

替代方案

使用 public-api-diff 的项目

灵感来源

支持

如果您有功能请求,或发现错误或技术问题,请创建一个 GitHub issue。

许可

MIT 许可。 有关更多信息,请参见 LICENSE 文件。