From db93c84a109ad5b8118073f9dfa51f195331b727 Mon Sep 17 00:00:00 2001 From: commitay Date: Tue, 10 Jul 2018 20:05:18 +1000 Subject: [PATCH] script: various (#48662) --- ci/travis/helpers.sh | 8 +++- ci/travis/script.sh | 65 +++++++++++++++-------------- developer/bin/sync_templates_and_ci | 5 --- 3 files changed, 40 insertions(+), 38 deletions(-) diff --git a/ci/travis/helpers.sh b/ci/travis/helpers.sh index ead13a485c..75d7dca5d8 100644 --- a/ci/travis/helpers.sh +++ b/ci/travis/helpers.sh @@ -15,6 +15,7 @@ shopt -s extglob CYAN='\033[0;36m' MAGENTA='\033[1;35m' RED='\033[1;31m' +YELLOW='\033[0;33m' NC='\033[0m' # no color # log command before running and add a blank line @@ -30,8 +31,13 @@ ohai () { echo -e "${MAGENTA}>>>${NC} $*" } +onoe () { + echo -e "${YELLOW}>>> $* ${NC}" + exit 0 +} + odie () { - echo -e "${RED}!!!${NC} $*" + echo -e "${RED}!!! $* !!!${NC}" exit 1 } diff --git a/ci/travis/script.sh b/ci/travis/script.sh index d0a5332efa..111de8d106 100755 --- a/ci/travis/script.sh +++ b/ci/travis/script.sh @@ -23,43 +23,44 @@ for check in "${checks[@]}"; do "${check}" > "${HOME}/cask-checks/before/${check}" done -modified_ruby_files=($(git diff --name-only --diff-filter=AMR "${TRAVIS_COMMIT_RANGE}" -- *.rb)) - -for file in "${modified_ruby_files[@]}"; do - [[ "${file}" == 'Casks/'* ]] && modified_casks+=("${file}") || casks_wrong_dir+=("${file}") -done +modified_casks=($(git diff --name-only --diff-filter=AMR "${TRAVIS_COMMIT_RANGE}" -- Casks/*.rb)) run export HOMEBREW_NO_AUTO_UPDATE=1 -if [[ ${#casks_wrong_dir[@]} -gt 0 ]]; then - odie "Casks added outside Casks directory: ${casks_wrong_dir[*]}" -elif [[ ${#modified_casks[@]} -gt 0 ]]; then - if [[ ${#modified_casks[@]} -le 3 ]]; then - for cask in "${modified_casks[@]}"; do - if brew cask _stanza gpg "${cask}" &> /dev/null; then - run brew outdated gnupg || run brew upgrade gnupg - fi - done +if [[ ${#modified_casks[@]} -eq 0 ]]; then + onoe 'No Casks modified, skipping' +fi + +run brew cask style "${modified_casks[@]}" + +if [[ "${TRAVIS_REPO_SLUG}" != 'Homebrew/homebrew-cask-fonts' ]]; then + if [[ ${#modified_casks[@]} -gt 1 ]]; then + run brew cask audit "${modified_casks[@]}" + odie "More than 1 Cask modified, didn't check Cask checksums or URLs" fi - run brew cask _audit_modified_casks "${TRAVIS_COMMIT_RANGE}" - run brew cask style "${modified_casks[@]}" - if [[ ${#modified_casks[@]} -le 3 ]]; then - if /usr/bin/grep "depends_on cask:" "${modified_casks[@]}" > /dev/null; then - run brew tap homebrew/bundle - run brew bundle dump --file="${HOME}/Brewfile" + + # check if gnupg is up to date for _audit_modified_casks + for cask in "${modified_casks[@]}"; do + if brew cask _stanza gpg "${cask}" &> /dev/null; then + run brew outdated gnupg || run brew upgrade gnupg fi - for cask in "${modified_casks[@]}"; do - run brew cask reinstall --verbose "${cask}" - run brew cask uninstall --verbose "${cask}" - done - if [[ -f "${HOME}/Brewfile" ]]; then - run brew bundle cleanup --force --file="${HOME}/Brewfile" - fi - else - ohai 'More than 3 Casks modified, skipping install' - fi -else - ohai 'No Casks modified, skipping' + done +fi + +run brew cask _audit_modified_casks "${TRAVIS_COMMIT_RANGE}" + +if /usr/bin/grep --quiet "depends_on cask:" "${modified_casks[@]}"; then + run brew tap homebrew/bundle + run brew bundle dump --file="${HOME}/Brewfile" +fi + +for cask in "${modified_casks[@]}"; do + run brew cask reinstall --verbose "${cask}" + run brew cask uninstall --verbose "${cask}" +done + +if [[ -f "${HOME}/Brewfile" ]]; then + run brew bundle cleanup --force --file="${HOME}/Brewfile" fi sleep 5 # Rerunning the checks too soon can result in false positives diff --git a/developer/bin/sync_templates_and_ci b/developer/bin/sync_templates_and_ci index 67e8a6742c..3061eaf5f3 100755 --- a/developer/bin/sync_templates_and_ci +++ b/developer/bin/sync_templates_and_ci @@ -34,11 +34,6 @@ function copy_templates_and_ci { rsync --archive --delete "${main_repo_dir}"/{.editorconfig,.gitattributes,.github,.gitignore,.travis.yml,ci,CODE_OF_CONDUCT.md} '.' rm '.github/ISSUE_TEMPLATE/02_feature_request.md' # Feature requests only make sense in the main repo /usr/bin/sed -i '' -E "s:homebrew-cask/(pulls|issues):${repo_name}/\1:" '.github/PULL_REQUEST_TEMPLATE.md' # PULL_REQUEST_TEMPLATE has repo-specific links - - # increase script.sh install cap for fonts repo - if [[ "${repo_name}" == 'homebrew-cask-fonts' ]]; then - /usr/bin/sed -i '' -e 's:-le 3:-le 15:' -e 's:than 3 Casks:than 15 Casks:' 'ci/travis/script.sh' - fi } function push_changes {