diff --git a/README.md b/README.md index 809ce42..1e9b52a 100644 --- a/README.md +++ b/README.md @@ -103,8 +103,6 @@ npm install -g xar-js npm install -g google-closure-compiler-js ``` -Additionally a reimplementation of the utility PlistBuddy used for automated build numbering is [provided](https://github.com/amarcu5/PiPer/tree/master/build-tools/) but it is advisable to download the original as part of [Xcode](https://itunes.apple.com/gb/app/xcode/id497799835?mt=12) or from [Apple's Command Line Tools](https://developer.apple.com/download/) - #### Steps 1. Clone the repository 2. Run `make.sh` diff --git a/build-tools/plistbuddy b/build-tools/plistbuddy deleted file mode 100755 index 814716b..0000000 Binary files a/build-tools/plistbuddy and /dev/null differ diff --git a/make.sh b/make.sh index fac949c..fae60fa 100755 --- a/make.sh +++ b/make.sh @@ -9,7 +9,6 @@ CSSO_PATH=$(type "csso" >/dev/null 2>&1 && echo "csso" || echo "./build-tools/cs CCJS_PATH=$(type "google-closure-compiler-js" >/dev/null 2>&1 && echo "google-closure-compiler-js" || echo "./build-tools/google-closure-compiler-js") XARJS_PATH=$(type "xarjs" >/dev/null 2>&1 && echo "xarjs" || echo "./build-tools/xarjs") SVGO_PATH=$(type "svgo" >/dev/null 2>&1 && echo "svgo" || echo "./build-tools/svgo") -PLISTBUDDY_PATH=$(type "/usr/libexec/PlistBuddy" >/dev/null 2>&1 && echo "/usr/libexec/PlistBuddy" || echo "./build-tools/plistbuddy") # Certifcate paths LEAF_CERT_PATH="../certs/cert.pem" @@ -82,6 +81,15 @@ while :; do shift done +# Check for git and exit if not found +if [[ "${update_version}" -eq 1 ]] && { ! type "git" &>/dev/null; }; then + echo "Error: 'git' command not found" >&2 + echo "Please install the latest version of git (see https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)" >&2 + exit 1 +else + GIT_PATH=$(sh /etc/profile; which git) +fi + # # Build script @@ -120,6 +128,34 @@ if [[ "$compress_css" -eq 1 ]]; then done fi +# Get current version from git if automatic versioning enabled +if [[ "${update_version}" -eq 1 ]]; then + + # Check we're inside a git work tree + inside_git_repo="$(git rev-parse --is-inside-work-tree 2>/dev/null)" + if [[ "${inside_git_repo}" ]]; then + + # Get number of commits and release version from most recent tag + number_of_commits=$(($("${GIT_PATH}" rev-list HEAD --count) + 1)) + git_release_version=$("${GIT_PATH}" describe --tags --always --abbrev=0) + git_release_version=${git_release_version%%-*}; + git_release_version=${git_release_version#*v}; + + # Otherwise issue warning and set blank version + else + echo "Warning: Unable to set version automatically as cannot find 'git' repository (ensure repository has been cloned to fix this)" >&2 + number_of_commits="0" + git_release_version="0.0.0" + fi + + # Helper performs multiline sed regular expression + function multiline_sed_regex() { + mv "$1" "$1.bak" + cat "$1.bak" | tr "\n" "\f" | sed -E "$2" | tr "\f" "\n" > "$1" + rm -rf "$1.bak" + } +fi + # Use closure compiler to compress javascript if [[ "$compress_js" -eq 1 ]]; then for path in "out/${EXTENSION_NAME}.safariextension/scripts"/*.js; do @@ -138,26 +174,18 @@ fi rm "out/${EXTENSION_NAME}.safariextension/scripts/externs.js" # Update version info from git -if [[ "$update_version" -eq 1 ]]; then - git=$(sh /etc/profile; which git) - number_of_commits=$(($("$git" rev-list HEAD --count) + 1)) - git_release_version=$("$git" describe --tags --always --abbrev=0) - git_release_version=${git_release_version%%-*}; - git_release_version=${git_release_version#*v}; +if [[ "${update_version}" -eq 1 ]]; then info_plist="out/${EXTENSION_NAME}.safariextension/Info.plist" update_plist="update.plist" - ${PLISTBUDDY_PATH} -c "Set :CFBundleVersion $number_of_commits" "$info_plist" - ${PLISTBUDDY_PATH} -c "Set :CFBundleShortVersionString ${git_release_version}" "$info_plist" - ${PLISTBUDDY_PATH} -c "Set \":Extension Updates:0:CFBundleVersion\" $number_of_commits" "$update_plist" - ${PLISTBUDDY_PATH} -c "Set \":Extension Updates:0:CFBundleShortVersionString\" ${git_release_version#*v}" "$update_plist" + multiline_sed_regex "${info_plist}" "s|(> *CFBundleShortVersionString *[^>]+>)[^<]+|\1${git_release_version}|g" + multiline_sed_regex "${info_plist}" "s|(> *CFBundleVersion *[^>]+>)[^<]+|\1${number_of_commits}|g" + multiline_sed_regex "${update_plist}" "s|(> *CFBundleShortVersionString *[^>]+>)[^<]+|\1${git_release_version}|g" + multiline_sed_regex "${update_plist}" "s|(> *CFBundleVersion *[^>]+>)[^<]+|\1${number_of_commits}|g" fi # Package safari extension -cd out || exit -if [[ "$package_ext" -eq 1 ]] && [[ -f "${PRIVATE_KEY_PATH}" ]]; then - [[ ${XARJS_PATH} != /* ]] && ! type "${XARJS_PATH}" >/dev/null 2>&1 && XARJS_PATH="../${XARJS_PATH}" - ${XARJS_PATH} create "${EXTENSION_NAME}.safariextz" --cert "${LEAF_CERT_PATH}" --cert "${INTERMEDIATE_CERT_PATH}" --cert "${ROOT_CERT_PATH}" --private-key "${PRIVATE_KEY_PATH}" "${EXTENSION_NAME}.safariextension" - rm -rf "${EXTENSION_NAME}.safariextension" +if [[ "${package_ext}" -eq 1 ]] && [[ -f "out/${PRIVATE_KEY_PATH}" ]]; then + (cd out && ${XARJS_PATH} create "${EXTENSION_NAME}.safariextz" --cert "${LEAF_CERT_PATH}" --cert "${INTERMEDIATE_CERT_PATH}" --cert "${ROOT_CERT_PATH}" --private-key "${PRIVATE_KEY_PATH}" "${EXTENSION_NAME}.safariextension") + rm -rf "out/${EXTENSION_NAME}.safariextension" fi - echo "Done." diff --git a/out/PiPer.safariextz b/out/PiPer.safariextz index 0421657..c0c1136 100644 Binary files a/out/PiPer.safariextz and b/out/PiPer.safariextz differ diff --git a/update.plist b/update.plist index e2d544f..9245e1e 100644 --- a/update.plist +++ b/update.plist @@ -8,9 +8,9 @@ CFBundleIdentifier com.amarcus.safari.piper CFBundleShortVersionString - 0.2.5 + CFBundleVersion - 152 + 153 Developer Identifier BQ6Q24MF9X URL @@ -21,3 +21,11 @@ + + + + + + + +