里程碑

Build Status Language SwiftPM compatible Platform License

一个简单的 SwiftPM 插件,用于在您的应用程序上显示 Git 提交信息

摘要

Milepost 是一个简单的库,用于获取 Git 提交信息。

您可以为调试版本或生产版本显示 Git 版本信息,以供最终用户查询。

此库提供 SwiftPM 构建工具插件。它可以帮助开发者轻松集成它。

安装

1. 使用 SwiftPM 将 Milepost 集成到您的项目中

2. 在您的应用程序目标中链接 Milepost

3. 添加构建阶段以获取 git 信息

用法

您可以使用 RevisionLoader.load() 获取最新的修订版本。

import Milepost

let revision = RevisionLoader.load()!
revision.hash
revision.branch
revision.shortHash
revision.lastCommit.author.description
revision.lastCommit.committer.description
revision.lastCommit.subject
revision.lastCommit.authorDate
revision.lastCommit.commitDate

您可以轻松地构建如下设置页面

import SwiftUI
import Milepost

struct RevisionView: View {
    var body: some View {
        List {
            Section {
                if let revision = RevisionLoader.load() {
                    LabeledContent("Hash") {
                        Text(revision.hash)
                            .font(.caption)
                    }
                    LabeledContent("Short Hash") {
                        Text(revision.shortHash)
                    }
                    LabeledContent("Branch") {
                        Text(revision.branch ?? "-")
                    }
                    LabeledContent("Last Author") {
                        VStack(alignment: .trailing) {
                            Text(revision.lastCommit.author.name)
                            Text(revision.lastCommit.author.email)
                                .font(.caption)
                        }
                    }
                    LabeledContent("Commit Message") {
                        Text(revision.lastCommit.subject ?? "-")
                    }
                }
            } header: {
                Text("Revision")
            }
        }
    }
}

要求

用户 版本
开发者 Xcode 14.0 或更高版本和 macOS 11.0 或更高版本
App 用户 任何 iOS、iPadOS、macOS、watchOS、tvOS

此插件使用 SwiftPM Build Tools Plugin。因此,您必须使用 Xcode 14.0 或更高版本。

此功能仅在构建过程中需要。因此,该库可在任何平台版本上运行。