Skip to content

Commit

Permalink
Merge pull request #29 from bariBari23/build/githook
Browse files Browse the repository at this point in the history
chore: 깃훅 걸고 확인하기
  • Loading branch information
mirageoasis authored Jul 13, 2024
2 parents c28fa7a + 3398137 commit 97ac206
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
43 changes: 43 additions & 0 deletions scripts/install-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# implementation: baribari pre-commit and pre-push hook installer
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Original Author
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

install_git_hooks() {
local magic_str_commit="baribari standard pre-commit hook"
local magic_str_push="baribari standard pre-push hook"

# pre-commit hook 설정
if [ -f .git/hooks/pre-commit ]; then
grep -Fq "$magic_str_commit" .git/hooks/pre-commit
if [ $? -eq 0 ]; then
:
else
echo "" >> .git/hooks/pre-commit
cat scripts/pre-commit.sh >> .git/hooks/pre-commit
fi
else
cp scripts/pre-commit.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
fi

# pre-push hook 설정
if [ -f .git/hooks/pre-push ]; then
grep -Fq "$magic_str_push" .git/hooks/pre-push
if [ $? -eq 0 ]; then
:
else
echo "" >> .git/hooks/pre-push
cat scripts/pre-push.sh >> .git/hooks/pre-push
fi
else
cp scripts/pre-push.sh .git/hooks/pre-push
chmod +x .git/hooks/pre-push
fi
}

install_git_hooks
13 changes: 13 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash
# implementation: baribari pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

# backend.ai monorepo standard pre-commit hook
BASE_PATH=$(cd "$(dirname "$0")"/../.. && pwd)
${BASE_PATH}/scripts/pre-commit.sh "$@"

14 changes: 14 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# implementation: baribari pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

BASE_PATH=$(cd "$(dirname "$0")"/.. && pwd)
echo "Performing lint for changed files ..."

# Gradle을 사용하여 KTlint 검사 수행
./gradlew ktlintCheck
12 changes: 12 additions & 0 deletions scripts/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
# implementation: baribari pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoais
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

# baribari pre-push hook
BASE_PATH=$(cd "$(dirname "$0")"/../.. && pwd)
${BASE_PATH}/scripts/pre-push.sh "$@"
38 changes: 38 additions & 0 deletions scripts/pre-push.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# implementation: baribari pre-push hook
# This script is based on a LGPL 3.0 licensed script.
#
# Original Script Copyright (C) 2023 Lablup Inc.
# Modifications Copyright (C) 2024 mirageoasis
#
# This script is modified under the same license, the GNU Lesser General Public License v3.0.

BASE_PATH=$(cd "$(dirname "$0")"/.. && pwd)

CURRENT_COMMIT=$(git rev-parse --short HEAD)
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -n "$(echo "$CURRENT_BRANCH" | sed -n '/^[[:digit:]]\{1,\}\.[[:digit:]]\{1,\}/p')" ]; then
# if we are on the release branch, use it as the base branch.
BASE_BRANCH="$CURRENT_BRANCH"
else
BASE_BRANCH="main"
fi
if [ "$1" != "origin" ]; then
# extract the owner name of the target repo
ORIGIN="$(echo "$1" | grep -o '://[^/]\+/[^/]\+/' | grep -o '/[^/]\+/$' | tr -d '/')"
cleanup_remote() {
git remote remove "$ORIGIN"
}
trap cleanup_remote EXIT
git remote add "$ORIGIN" "$1"
git fetch -q --depth=1 --no-tags "$ORIGIN" "$BASE_BRANCH"
else
ORIGIN="origin"
fi
echo "Performing lint and check on ${ORIGIN}/${BASE_BRANCH}..HEAD@${CURRENT_COMMIT} ..."

# Gradle을 사용하여 KTlint 검사 수행
./gradlew ktlintCheck

# 필요한 다른 검사 수행
# ./gradlew 다른_검사

0 comments on commit 97ac206

Please sign in to comment.