2015-12-31 12:01:31 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# script.sh
|
|
|
|
#
|
|
|
|
# This file is meant to be sourced during the `script` phase of the Travis
|
|
|
|
# build. Do not attempt to source or run it locally.
|
|
|
|
#
|
|
|
|
# shellcheck disable=SC1090
|
|
|
|
. "${TRAVIS_BUILD_DIR}/ci/travis/helpers.sh"
|
|
|
|
|
|
|
|
header 'Running script.sh...'
|
|
|
|
|
2018-01-03 09:08:42 +08:00
|
|
|
apps () { /usr/bin/find /Applications -type d -name '*.app' -maxdepth 2 ; }
|
|
|
|
kexts () { "$(brew --repository)/Library/Taps/caskroom/homebrew-cask/developer/bin/list_loaded_kext_ids" ; }
|
|
|
|
launchjob_install () { "$(brew --repository)/Library/Taps/caskroom/homebrew-cask/developer/bin/list_installed_launchjob_ids" ; }
|
|
|
|
launchjob_load () { "$(brew --repository)/Library/Taps/caskroom/homebrew-cask/developer/bin/list_loaded_launchjob_ids" ; }
|
|
|
|
pkgs () { "$(brew --repository)/Library/Taps/caskroom/homebrew-cask/developer/bin/list_recent_pkg_ids" ; }
|
|
|
|
|
2018-01-10 04:23:57 +08:00
|
|
|
checks=('pkgs' 'apps' 'kexts' 'launchjob_install' 'launchjob_load')
|
2018-01-03 09:08:42 +08:00
|
|
|
|
|
|
|
/bin/mkdir -p "${HOME}/cask-checks/"{before,after}
|
|
|
|
|
|
|
|
for check in "${checks[@]}"; do
|
|
|
|
"${check}" > "${HOME}/cask-checks/before/${check}"
|
|
|
|
done
|
|
|
|
|
2017-10-07 10:39:20 +08:00
|
|
|
modified_ruby_files=($(git diff --name-only --diff-filter=AMR "${TRAVIS_COMMIT_RANGE}" -- *.rb))
|
2017-01-06 10:58:14 +08:00
|
|
|
|
|
|
|
for file in "${modified_ruby_files[@]}"; do
|
|
|
|
[[ "${file}" == 'Casks/'* ]] && modified_casks+=("${file}") || casks_wrong_dir+=("${file}")
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ ${#casks_wrong_dir[@]} -gt 0 ]]; then
|
|
|
|
odie "Casks added outside Casks directory: ${casks_wrong_dir[*]}"
|
|
|
|
elif [[ ${#modified_casks[@]} -gt 0 ]]; then
|
2016-07-16 01:09:10 +08:00
|
|
|
run brew cask _audit_modified_casks "${TRAVIS_COMMIT_RANGE}"
|
2016-01-07 14:27:20 +08:00
|
|
|
run brew cask style "${modified_casks[@]}"
|
2017-11-11 10:06:40 +08:00
|
|
|
if [[ ${#modified_casks[@]} -le 3 ]]; then
|
2018-01-03 09:08:42 +08:00
|
|
|
if /usr/bin/grep "depends_on cask:" "${modified_casks[@]}" > /dev/null; then
|
|
|
|
export HOMEBREW_NO_AUTO_UPDATE=1
|
|
|
|
run brew tap homebrew/bundle
|
|
|
|
run brew bundle dump --file="${HOME}/Brewfile"
|
|
|
|
fi
|
2017-10-01 08:24:47 +08:00
|
|
|
for cask in "${modified_casks[@]}"; do
|
2017-10-12 12:50:02 +08:00
|
|
|
run brew cask reinstall --verbose "${cask}"
|
2018-02-28 13:32:10 +08:00
|
|
|
run brew cask zap --verbose "${cask}"
|
2017-10-01 08:24:47 +08:00
|
|
|
done
|
2018-01-03 09:08:42 +08:00
|
|
|
if [[ -f "${HOME}/Brewfile" ]]; then
|
|
|
|
run brew bundle cleanup --force --file="${HOME}/Brewfile"
|
|
|
|
fi
|
2017-09-16 17:45:14 +08:00
|
|
|
else
|
2017-11-11 10:06:40 +08:00
|
|
|
ohai 'More than 3 Casks modified, skipping install'
|
2017-09-16 17:45:14 +08:00
|
|
|
fi
|
2016-10-19 23:04:38 +08:00
|
|
|
else
|
2017-11-11 10:06:40 +08:00
|
|
|
ohai 'No Casks modified, skipping'
|
2016-01-08 22:05:31 +08:00
|
|
|
fi
|
2018-01-03 09:08:42 +08:00
|
|
|
|
2018-02-14 05:26:16 +08:00
|
|
|
sleep 5 # Rerunning the checks too soon can result in false positives
|
|
|
|
|
2018-01-03 09:08:42 +08:00
|
|
|
for check in "${checks[@]}"; do
|
|
|
|
"${check}" > "${HOME}/cask-checks/after/${check}"
|
|
|
|
|
|
|
|
if ! /usr/bin/diff "${HOME}/cask-checks/before/${check}" "${HOME}/cask-checks/after/${check}" > /dev/null; then
|
|
|
|
ohai "Leftover: ${check}"
|
|
|
|
/usr/bin/diff "${HOME}/cask-checks/before/${check}" "${HOME}/cask-checks/after/${check}" | /usr/bin/grep '>'
|
|
|
|
fi
|
|
|
|
done
|