From 850f4febf2edd45a978a43d22d47e393a9881b31 Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Sun, 7 Jul 2024 14:38:34 +0900 Subject: [PATCH 1/2] chore: githook install --- scripts/install-dev.sh | 43 ++++++++++++++++++++++++++++++++++++++++++ scripts/pre-commit | 13 +++++++++++++ scripts/pre-commit.sh | 14 ++++++++++++++ scripts/pre-push | 12 ++++++++++++ scripts/pre-push.sh | 38 +++++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+) create mode 100644 scripts/install-dev.sh create mode 100644 scripts/pre-commit create mode 100755 scripts/pre-commit.sh create mode 100644 scripts/pre-push create mode 100755 scripts/pre-push.sh diff --git a/scripts/install-dev.sh b/scripts/install-dev.sh new file mode 100644 index 0000000..62f6ecf --- /dev/null +++ b/scripts/install-dev.sh @@ -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 diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100644 index 0000000..90bcce5 --- /dev/null +++ b/scripts/pre-commit @@ -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 Original Author +# 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 "$@" + diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 0000000..8f2323c --- /dev/null +++ b/scripts/pre-commit.sh @@ -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 Original Author +# 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 \ No newline at end of file diff --git a/scripts/pre-push b/scripts/pre-push new file mode 100644 index 0000000..188b706 --- /dev/null +++ b/scripts/pre-push @@ -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 Original Author +# 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 "$@" diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh new file mode 100755 index 0000000..8e7f761 --- /dev/null +++ b/scripts/pre-push.sh @@ -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 Original Author +# 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 다른_검사 From 339813775586aba4f480734311527ab29581c16f Mon Sep 17 00:00:00 2001 From: mirageoasis Date: Sat, 13 Jul 2024 14:44:02 +0900 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=EC=9B=90=EC=9E=91=EC=9E=90=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/pre-commit | 2 +- scripts/pre-commit.sh | 2 +- scripts/pre-push | 2 +- scripts/pre-push.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/pre-commit b/scripts/pre-commit index 90bcce5..9fccad5 100644 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -2,7 +2,7 @@ # implementation: baribari pre-push hook # This script is based on a LGPL 3.0 licensed script. # -# Original Script Copyright (C) 2023 Original Author +# 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. diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index 8f2323c..fd28afe 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -2,7 +2,7 @@ # implementation: baribari pre-push hook # This script is based on a LGPL 3.0 licensed script. # -# Original Script Copyright (C) 2023 Original Author +# 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. diff --git a/scripts/pre-push b/scripts/pre-push index 188b706..926295f 100644 --- a/scripts/pre-push +++ b/scripts/pre-push @@ -2,7 +2,7 @@ # implementation: baribari pre-push hook # This script is based on a LGPL 3.0 licensed script. # -# Original Script Copyright (C) 2023 Original Author +# 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. diff --git a/scripts/pre-push.sh b/scripts/pre-push.sh index 8e7f761..b96ffe9 100755 --- a/scripts/pre-push.sh +++ b/scripts/pre-push.sh @@ -2,7 +2,7 @@ # implementation: baribari pre-push hook # This script is based on a LGPL 3.0 licensed script. # -# Original Script Copyright (C) 2023 Original Author +# 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.