diff --git a/.ih-pre-commit-config.yaml b/.ih-pre-commit-config.yaml new file mode 100644 index 0000000..0c13ea1 --- /dev/null +++ b/.ih-pre-commit-config.yaml @@ -0,0 +1,10 @@ +languages: +- markdown +- pem +- plist +- shell +- text +- yaml +ignored_directories: + - formula/ + - Casks/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da0b8bd..448ed42 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,16 +1,37 @@ repos: -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.2.0 + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: check-added-large-files - - id: check-executables-have-shebangs -- repo: https://github.com/jumanjihouse/pre-commit-hooks - rev: 2.1.5 - hooks: - - id: shellcheck - - id: script-must-have-extension - - id: script-must-not-have-extension - - id: shfmt + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-executables-have-shebangs + - id: check-json + - id: check-merge-conflict + - id: check-symlinks + - id: check-xml + - id: no-commit-to-branch + args: + - --branch + - master + - --branch + - main + - --branch + - trunk + - --branch + - develop + - id: detect-private-key + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 2.1.5 + hooks: + - id: shellcheck + - id: script-must-have-extension + - id: script-must-not-have-extension + - id: shfmt + - repo: https://github.com/gruntwork-io/pre-commit + rev: v0.1.20 + hooks: + - id: shellcheck + types: + - shell diff --git a/VERSION b/VERSION index 0e7400f..7db2672 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.25 +0.1.26 diff --git a/formula/ih-core.rb b/formula/ih-core.rb index 981627e..112abde 100644 --- a/formula/ih-core.rb +++ b/formula/ih-core.rb @@ -1,5 +1,5 @@ class IhCore < Formula - VERSION="0.1.25" + VERSION="0.1.26" desc "Brew formula for installing core tools used at Included Health engineering." homepage "https://github.com/ConsultingMD/homebrew-ih-public" license "CC BY-NC-ND 4.0" @@ -13,6 +13,7 @@ class IhCore < Formula depends_on "git" depends_on "gnu-getopt" depends_on "jq" + depends_on "yq" depends_on "go-jira" depends_on "virtualenv" depends_on "envconsul" @@ -21,6 +22,7 @@ class IhCore < Formula depends_on "yamllint" depends_on "wget" depends_on "rancher-cli" + depends_on "ripgrep" def install lib.install Dir["lib/*"] @@ -30,7 +32,7 @@ def install def caveat - "Run `ih-setup install` to install IH compontents" + "Run `ih-setup install` to install IH components" end diff --git a/lib/core/git/step.sh b/lib/core/git/step.sh index ece75bb..0ba0c2a 100644 --- a/lib/core/git/step.sh +++ b/lib/core/git/step.sh @@ -8,7 +8,7 @@ function ih::setup::core.git::help() { This will not overwrite any existing settings that you have set. - Create $GR_HOME if it doesn't exist. - Create a default global .gitignore if one doesn't exist. - - Set up pre-commit to install automatically when repos are cloned." + - Set up linting pre-commit hook to be installed automatically when repos are cloned." } @@ -53,17 +53,6 @@ function ih::setup::core.git::install() { # make git use ssh for everything git config --global url.git@github.com:ConsultingMD/.insteadOf https://github.com/ConsultingMD/ - # set up pre-commit to automatically be set up for all cloned repos, - # if the user doesn't have a templateDir already - if git config --global init.templateDir; then - ih::log::warn "Detected existing templateDir, not setting up pre-commit auto-enable." - else - local GIT_TEMPLATE_DIR="${IH_DIR}/git-template" - mkdir "$GIT_TEMPLATE_DIR" 2>/dev/null || : - git config --global init.templateDir "$GIT_TEMPLATE_DIR" - pre-commit init-templatedir "$GIT_TEMPLATE_DIR" - fi - # Make sure the desired src directory exists if GR_HOME is declared [[ -n ${GR_HOME} ]] && mkdir -p "${GR_HOME}" diff --git a/lib/core/toolrepos/step.sh b/lib/core/toolrepos/step.sh index 3633d71..9404040 100644 --- a/lib/core/toolrepos/step.sh +++ b/lib/core/toolrepos/step.sh @@ -8,7 +8,7 @@ function ih::setup::core.toolrepos::help() { This repo contains tools for - Clone the ConsultingMD/image-builder repo This repo contains tools for building images - and for setting up development enviroments" + and for setting up development environments" } function ih::setup::core.toolrepos::test() { @@ -16,7 +16,6 @@ function ih::setup::core.toolrepos::test() { } function ih::setup::core.toolrepos::deps() { - # echo "other steps" echo "core.github" } @@ -27,7 +26,6 @@ function ih::setup::core.toolrepos::install() { # If $1 is "test", this will check if install is needed and return 1 if it is. # Otherwise, this will install the repos. function ih::setup::core.toolrepos::test-or-install() { - if [ "$1" == "install" ]; then mkdir -p "${GR_HOME}" fi @@ -37,7 +35,7 @@ function ih::setup::core.toolrepos::test-or-install() { return 1 fi ih::log::info "Cloning engineering repo..." - git clone git@github.com:ConsultingMD/engineering.git --filter=blob:limit=1m --depth=5 "${GR_HOME}/engineering" || return + git clone git@github.com:ConsultingMD/engineering.git --filter=blob:limit=1m "${GR_HOME}/engineering" || return fi if [ ! -d "${GR_HOME}/image-builder" ]; then @@ -45,7 +43,7 @@ function ih::setup::core.toolrepos::test-or-install() { return 1 fi ih::log::info "Cloning image-builder repo.." - git clone git@github.com:ConsultingMD/image-builder.git --filter=blob:limit=1m --depth=5 "${GR_HOME}/image-builder" || return + git clone git@github.com:ConsultingMD/image-builder.git --filter=blob:limit=1m "${GR_HOME}/image-builder" || return fi if [ ! -d "${GR_HOME}/kore" ]; then @@ -67,14 +65,37 @@ function ih::setup::core.toolrepos::test-or-install() { ih::setup::core.toolrepos::set-auto-update-repositories-job fi - if [ "$1" = "test" ]; then - ih::file::check-file-in-sync "$toolsrepo_src_path" "$toolsrepo_tgt_path" - return + if ! ih::file::check-file-in-sync "$toolsrepo_src_path" "$toolsrepo_tgt_path"; then + if [ "$1" = "test" ]; then + return 1 + fi + cp -f "$toolsrepo_src_path" "$toolsrepo_tgt_path" + export IH_WANT_RE_SOURCE=1 fi - export IH_WANT_RE_SOURCE=1 + PRE_COMMIT_HOOK_DST="${IH_DIR}/git-template/hooks/pre-commit" + if [ ! -f "$PRE_COMMIT_HOOK_DST" ]; then + if [ "$1" == "test" ]; then + return 1 + fi - cp -f "$toolsrepo_src_path" "$toolsrepo_tgt_path" + export IMAGE_BUILDER_ROOT="${IH_HOME}/image-builder" + ( + cd "$IMAGE_BUILDER_ROOT" || exit + CURRENT_BRANCH=$(git branch --show-current) + if [ "$CURRENT_BRANCH" != "master" ]; then + ih::log::warn "You have a non-master branch of image-builder checked out. +You will need to check out and pull the master branch and run +'ih-pre-commit install --global' +manually in order to have pre-commit configured correctly." + return 1 + else + git pull + ih::log::info "Installing ih-pre-commit hook everywhere..." + "$IMAGE_BUILDER_ROOT/bin/ih-pre-commit" install --global + fi + ) + fi } function ih::setup::core.toolrepos::set-auto-update-repositories-job() { @@ -84,11 +105,12 @@ function ih::setup::core.toolrepos::set-auto-update-repositories-job() { PLIST_FILE="com.includedhealth.auto-update-repositories" LAUNCH_AGENTS_PATH="${HOME}/Library/LaunchAgents/${PLIST_FILE}.plist" + # shellcheck disable=SC2001 GR_HOME_ESC=$(echo "$GR_HOME" | sed 's_/_\\/_g') - sed "s/\$IH_HOME/${GR_HOME_ESC}/g" "${THIS_DIR}/${PLIST_FILE}.plist" > "${LAUNCH_AGENTS_PATH}" + sed "s/\$IH_HOME/${GR_HOME_ESC}/g" "${THIS_DIR}/${PLIST_FILE}.plist" >"${LAUNCH_AGENTS_PATH}" - if launchctl list | grep -q ${PLIST_FILE} ; then + if launchctl list | grep -q ${PLIST_FILE}; then launchctl unload "${LAUNCH_AGENTS_PATH}" fi diff --git a/lib/utils/file.sh b/lib/utils/file.sh index be25417..8dd5728 100644 --- a/lib/utils/file.sh +++ b/lib/utils/file.sh @@ -76,10 +76,15 @@ function ih::file::check-file-in-sync() { return 1 fi + ih::log::debug "Checking for differences between $SRC and $DST ..." + if ! diff -q "$DST" "$SRC" >/dev/null; then ih::log::debug "File $DST does not match source" return 1 fi + + ih::log::debug "Files match" + } # Returns 0 if the directory at $2 has all