Skip to content

Commit

Permalink
Fix version.swift and info.plist version scripts
Browse files Browse the repository at this point in the history
made a real .sh file
fixed the input / output paths
detect and skip for targets that don’t have plists
  • Loading branch information
JoeMatt committed Sep 23, 2018
1 parent 15ceee8 commit aa0659c
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 13 deletions.
14 changes: 8 additions & 6 deletions Provenance.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1928,31 +1928,33 @@
files = (
);
inputPaths = (
./.version,
"${PROJECT_DIR}/${INFOPLIST_FILE}",
);
name = "Set Build Number";
outputPaths = (
"\"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"",
"${SRC_ROOT}/.version",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "function success_exit\n{\n echo \"${PROGNAME}: ${1:-\"Completed\"}\" 1>&2\n exit 0\n}\n\nvpath={SCRIPT_INPIT_FILE_0}\nGIT_DATE=`git log -1 --format=\"%cd\" --date=\"local\"`\n\nif [ -f $vpath ] && [[ $(< $vpath) == \"$GIT_DATE\" ]]; then\nsuccess_exit \"$vpath matches $GIT_DATE\"\nfi\n\nbuildNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\")\nbuildNumber=`git rev-list --count HEAD`\n#/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\"\n# Use the built products dir so GIT doesn't want to constantly upload a changed Info.plist in the code directory - jm\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\nGIT_TAG=`git describe --tags --always --dirty`\nGIT_DATE=`git log -1 --format=\"%cd\" --date=\"local\"`\nGIT_BRANCH=`git branch | grep \\* | cut -d ' ' -f2-`\n/usr/libexec/PlistBuddy -c \"Set :GitBranch $GIT_BRANCH\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\n/usr/libexec/PlistBuddy -c \"Set :GitDate $GIT_DATE\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\n/usr/libexec/PlistBuddy -c \"Set :GitTag $GIT_TAG\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\n\n# Set Git SHA\nrevision=$(git rev-parse --short HEAD)\n#/usr/libexec/PlistBuddy -c \"Set :Revision $revision\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\"\n# Use the built products dir so GIT doesn't want to constantly upload a changed Info.plist in the code directory - jm\n/usr/libexec/PlistBuddy -c \"Set :Revision $revision\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"";
shellPath = /bin/bash;
shellScript = ". Scripts/set_bundle_build_number.sh\n";
};
1A44C0AE1D0A1E730018751A /* Set Build Number */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
./.version,
"${PROJECT_DIR}/${INFOPLIST_FILE}",
);
name = "Set Build Number";
outputPaths = (
"${SRC_ROOT}/.version",
"\"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "function success_exit\n{\n echo \"${PROGNAME}: ${1:-\"Completed\"}\" 1>&2\n exit 0\n}\n\nvpath={SCRIPT_INPIT_FILE_0}\nGIT_DATE=`git log -1 --format=\"%cd\" --date=\"local\"`\n\nif [ -f $vpath ] && [[ $(< $vpath) == \"$GIT_DATE\" ]]; then\n success_exit \"$vpath matches $GIT_DATE\"\nfi\n\nbuildNumber=$(/usr/libexec/PlistBuddy -c \"Print CFBundleVersion\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\")\nbuildNumber=`git rev-list --count HEAD`\n#/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\"\n# Use the built products dir so GIT doesn't want to constantly upload a changed Info.plist in the code directory - jm\n/usr/libexec/PlistBuddy -c \"Set :CFBundleVersion $buildNumber\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\nGIT_TAG=`git describe --tags --always --dirty`\nGIT_DATE=`git log -1 --format=\"%cd\" --date=\"local\"`\nGIT_BRANCH=`git branch | grep \\* | cut -d ' ' -f2-`\n/usr/libexec/PlistBuddy -c \"Set :GitBranch $GIT_BRANCH\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\n/usr/libexec/PlistBuddy -c \"Set :GitDate $GIT_DATE\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\n/usr/libexec/PlistBuddy -c \"Set :GitTag $GIT_TAG\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"\n\n# Set Git SHA\nrevision=$(git rev-parse --short HEAD)\n#/usr/libexec/PlistBuddy -c \"Set :Revision $revision\" \"${PROJECT_DIR}/${INFOPLIST_FILE}\"\n# Use the built products dir so GIT doesn't want to constantly upload a changed Info.plist in the code directory - jm\n/usr/libexec/PlistBuddy -c \"Set :Revision $revision\" \"${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}\"";
shellPath = /bin/bash;
shellScript = ". Scripts/set_bundle_build_number.sh\n";
};
1A88180A20D6BC3C00984B39 /* Carthage Copy Frameworks */ = {
isa = PBXShellScriptBuildPhase;
Expand Down
17 changes: 11 additions & 6 deletions Provenance/Resources/createVersionHeader.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ INFOPATH="${PROJECT_DIR}/${INFOPLIST_FILE}"
# else
# echo "$PLISTBUDDY not found."
# fi
if [ "command -v $PLISTBUDDY" ] ; then
if [ "command -v ${INFOPATH}" ] ; then

plist_buddy_installed() {
[-x "$(command -v "$PLISTBUDDY")"]
}

if [[ plist_buddy_installed && "${INFOPATH}" == *".plist"* ]]; then
if [ -f "${INFOPATH}" ]; then
## Read the app version (x.y.z) from the PList
appversion=$($PLISTBUDDY -c "Print :CFBundleShortVersionString" "${INFOPATH}")
echo "appversion=${appversion}"

BUILT_INFO_PATH="${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
if [ "command -v ${BUILT_INFO_PATH}" ] ; then
if [ -f "${BUILT_INFO_PATH}" ]; then
PLIST_GIT_COMMIT_COUNT=$($PLISTBUDDY -c "Print :CFBundleVersion" "${BUILT_INFO_PATH}")
echo "Plist version is $PLIST_GIT_COMMIT_COUNT"
else
Expand Down Expand Up @@ -93,16 +98,16 @@ else
error_exit "$LINENO: $GIT not found."
fi

if [ $GIT_COMMIT_COUNT == $PLIST_GIT_COMMIT_COUNT ]; then
if [ "$GIT_COMMIT_COUNT" == "$PLIST_GIT_COMMIT_COUNT" ]; then
success_exit "GIT commit count hasn't changed. No need to update files."
fi

vpath="$SRCROOT/.version"
echo "Testing for $vpath"
if [ -f $vpath ] && [[ $(< $vpath) == "$GIT_DATE" ]]; then
if [ -f $vpath ] && [[ "$(< $vpath)" == "$GIT_DATE" ]]; then
success_exit "$vpath matches $GIT_DATE"
else
echo $GIT_DATE > $vpath
echo "$GIT_DATE" > "$vpath"
fi

echo "Creating Version.h in" ${PROJECT_DIR}
Expand Down
1 change: 1 addition & 0 deletions Scripts/createVersionHeader.sh
51 changes: 51 additions & 0 deletions Scripts/set_bundle_build_number.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
set -e
set -o pipefail

DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/setup_env.sh"

vpath="$SRCROOT/.version"
GIT_DATE=`git log -1 --format="%cd" --date="local"`

if [[ -f "$vpath" ]] && [[ "$(< $vpath)" == "$GIT_DATE" ]]; then
success_exit "$vpath matches $GIT_DATE"
fi

buildNumber="$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")"
buildNumber=`git rev-list --count HEAD`

GIT_TAG=`git describe --tags --always --dirty`
GIT_DATE=`git log -1 --format="%cd" --date="local"`
GIT_BRANCH=`git branch | grep \* | cut -d ' ' -f2-`

PLISTBUDDY="/usr/libexec/PlistBuddy"

plist_buddy_installed() {
[-x "$(command -v "$PLISTBUDDY")"]
}

if ! plist_buddy_installed; then
error_exit "System binary PlistBuddy is missing."
fi

# Use the built products dir so GIT doesn't want to constantly upload a changed Info.plist in the code directory - jm
$PLISTBUDDY -c "Set :CFBundleVersion $buildNumber" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"

$PLISTBUDDY -c "Set :GitBranch $GIT_BRANCH" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
$PLISTBUDDY -c "Set :GitDate $GIT_DATE" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"
$PLISTBUDDY -c "Set :GitTag $GIT_TAG" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"

# Set Git SHA
revision=$(git rev-parse --short HEAD)

#$PLISTBUDDY -c "Set :Revision $revision" "${PROJECT_DIR}/${INFOPLIST_FILE}"
# Use the built products dir so GIT doesn't want to constantly upload a changed Info.plist in the code directory - jm
$PLISTBUDDY-c "Set :Revision $revision" "${BUILT_PRODUCTS_DIR}/${INFOPLIST_PATH}"

echo "Updated app plist with git data."
echo "TAG: ${GIT_TAG}, DATE: ${GIT_DATE}, BRANCH: ${GIT_BRANCH}, REVISION: $revision"

# Store the date for next run
echo "$GIT_DATE" > "$vpath"
2 changes: 1 addition & 1 deletion Scripts/setup_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export FASTLANE_SKIP_UPDATE_CHECK=true

if ![[ "$PATH" = *".fastlane/bin"* ]]; then
if [[ "$PATH" != *".fastlane/bin"* ]]; then
echo "Adding hypothetical fastlane bin folder to PATH since many user forget to update PATH after install"
export PATH="$HOME/.fastlane/bin:$PATH"
fi
Expand Down

0 comments on commit aa0659c

Please sign in to comment.