sh Git向DataPlist iOS提交数据(本Tenseg博客文章中讨论的代码:http://www.tenseg.net/blog/2017/08/03/git-commit-info-in-

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Git向DataPlist iOS提交数据(本Tenseg博客文章中讨论的代码:http://www.tenseg.net/blog/2017/08/03/git-commit-info-in-相关的知识,希望对你有一定的参考价值。

//  version-string.swift
//  Created by Alexander Celeste on 8/1/17.

var versionString = ""
if let shortVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] as? String {
	versionString += "Version \(shortVersion)"
}
if let bundleVersion = Bundle.main.infoDictionary!["CFBundleVersion"] as? String {
	versionString += " (build \(bundleVersion))"
}
if let commitString = Bundle.main.infoDictionary!["TSCommit"] as? String {
	versionString += " (\(commitString))"
}
#!/bin/bash

#  git-commit-num-to-build-num.sh
#  Created by Alexander Celeste on 8/1/17.

# Instructions:
#  Run this script after the 'Copy Bundle Resources' build phase
#  It will compute git commit information and write it to the target's built Info.plist
#  Based on http://tgoode.com/2014/06/05/sensible-way-increment-bundle-version-cfbundleversion-xcode/#code

# declare # uncomment for a list of all env variables

# get data
BRANCH=$(cat $PROJECT_DIR/.git/HEAD | rev | cut -d "/" -f 1 | rev)
echo "You are on the $BRANCH branch."
BUILDNUM=$(expr $(git rev-list $BRANCH --count) - $(git rev-list HEAD..$BRANCH --count))
echo "This is build $BUILDNUM."
COMMIT=$(git rev-list $BRANCH | head -1 | cut -c1-7)
DIFF=$(git diff | wc -l)
echo "This is commit $COMMIT with $DIFF diffs compared to HEAD."

# write data to the products, both the app itself and the dSYM bundle
# build number, this key should already exist as it is standard in Apple-ecosystem apps
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILDNUM" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $BUILDNUM" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
# commit information, we always delete the key first to ensure we add the new information each time
/usr/libexec/PlistBuddy -c "Delete :TSCommit" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Add :TSCommit string \"$BRANCH $COMMIT $DIFF\"" "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}"
/usr/libexec/PlistBuddy -c "Delete :TSCommit" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
/usr/libexec/PlistBuddy -c "Add :TSCommit string \"$BRANCH $COMMIT $DIFF\"" "${BUILT_PRODUCTS_DIR}/${WRAPPER_NAME}.dSYM/Contents/Info.plist"
echo "Completed writing the above data to the products."
#!/bin/bash

#  Add this as a new Run Script build phase for your target.
#  Created by Alexander Celeste on 8/1/17.

#  Based on http://kelan.io/2008/xcode-run-script-build-phase-tip/

script_file="git-commit-num-to-build-num.sh"

echo "Running a custom build phase script: $script_file"
sh ${PROJECT_DIR}/scripts/${script_file}
scriptExitStatus=$?
echo "DONE with script: ${script_file} (exitStatus=${scriptExitStatus})"
exit "${scriptExitStatus}"

以上是关于sh Git向DataPlist iOS提交数据(本Tenseg博客文章中讨论的代码:http://www.tenseg.net/blog/2017/08/03/git-commit-info-in-的主要内容,如果未能解决你的问题,请参考以下文章

git写个脚本提交

git自动提交脚本(供参考)

sh git修改提交消息

sh 修改Git提交日期

sh git修改了之前的提交

sh 从提交中创建Git补丁