-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DT-142] ih-pre-commit integration (#40)
This adds a new, custom pre-commit handler (ih-pre-commit) which resides in the image-builder repository. This change updates the git step to remove its installation of the standard pre-commit hook, and updates the toolrepos step to install the ih-pre-commit step as a template and to update all existing IH repositories. This also adds a couple useful tools as dependency, yq and ripgrep.
- Loading branch information
1 parent
c33cb79
commit db65553
Showing
7 changed files
with
90 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
languages: | ||
- markdown | ||
- pem | ||
- plist | ||
- shell | ||
- text | ||
- yaml | ||
ignored_directories: | ||
- formula/ | ||
- Casks/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.1.25 | ||
0.1.26 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected]: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}" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,14 @@ 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() { | ||
ih::setup::core.toolrepos::test-or-install "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,15 +35,15 @@ function ih::setup::core.toolrepos::test-or-install() { | |
return 1 | ||
fi | ||
ih::log::info "Cloning engineering repo..." | ||
git clone [email protected]:ConsultingMD/engineering.git --filter=blob:limit=1m --depth=5 "${GR_HOME}/engineering" || return | ||
git clone [email protected]:ConsultingMD/engineering.git --filter=blob:limit=1m "${GR_HOME}/engineering" || return | ||
fi | ||
|
||
if [ ! -d "${GR_HOME}/image-builder" ]; then | ||
if [ "$1" == "test" ]; then | ||
return 1 | ||
fi | ||
ih::log::info "Cloning image-builder repo.." | ||
git clone [email protected]:ConsultingMD/image-builder.git --filter=blob:limit=1m --depth=5 "${GR_HOME}/image-builder" || return | ||
git clone [email protected]: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 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters