PXBuildVersion 0.7.0

PXBuildVersion 0.7.0

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期最后发布日期2016年4月

Pixio维护。



  • Kevin Wong

从git到您的应用程序中最简单的方法来获取构建版本信息。

PXBuildVersion是一组用于生成有关您的应用程序的构建版本信息的脚本。这包括构建日期、版本控制信息(git提交SHA、分支和标签)以及构建时捕获的其他任何环境变量。

支持Jenkins CI、Travis CI和Circle CI构建号。

安装

PXBuildVersion可通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中:

pod 'PXBuildVersion'

您还需要添加一个构建脚本。最简单的方法是将一个post_install钩子添加到您的Podfile中。如果您已经在Podfile中有一个post_install部分,只需将内容添加到现有的post_install中,因为每个Podfile只允许一个post_install钩子。

post_install do |installer|
  if File.exists?('Pods/PXBuildVersion')
    require_relative 'Pods/PXBuildVersion/scripts/util/setup.rb'
    pxbuildversion_setup(installer)
  end
end

一旦您的Podfile配置正确,只需运行pod install即可安装!

使用方法

使用很简单!

Objective-C

NSLog(@"git sha: %@", [PXBuildVersion commit]);
if ([PXBuildVersion tag] != nil) {
    NSLog(@"git tag: %@", [PXBuildVersion tag]);
}

Swift

if let commit = PXBuildVersion.commit() {
    print("git sha: \(commit)")
}
if let tag = PXBuildVersion.tag() {
    print("git tag: \(tag)")
}

将其添加到您的设置页面。或者,添加到您的崩溃报告工具,以帮助追踪问题!

[[Crashlytics sharedInstance] setObjectValue:[PXBuildVersion commit] forKey:@"commit"];

配置

通过调整设置脚本,您可以控制版本负载中生成的环境变量。

选项

    -e, --env [NAMES]                Comma separated list of env variable names
        --all-env                    Dump all environment env variables found
        --exclude-default            Exclude default env variables

这些选项可以应用于Podfile中的设置脚本。

示例

将您的Podfile中的pxbuildversion_setup行更新为指定确切的脚本,指定任何选项。

if File.exists?('Pods/PXBuildVersion')
  require_relative 'Pods/PXBuildVersion/scripts/util/setup.rb'
  pxbuildversion_setup(installer, script: %(\"${PODS_ROOT}/PXBuildVersion/scripts/git.rb\" -e NODE_NAME,BUILD_URL --exclude-default))
end

然后根据需要访问任何捕获的环境变量

if let buildNode = PXBuildVersion.environmentVariables()["NODE_NAME"],
       buildUrl = PXBuildVersion.environmentVariables()["BUILD_URL"] {
    print("This was built by Travis CI on node: \(buildNode)")
    print("Access the build job details at: \(buildUrl)")
}
else {
    print("Perhaps we should automate our builds with a CI server")
}

作者

kwongius

许可证

PXBuildVersion在MIT许可证下可用。有关更多信息,请参阅LICENSE文件。