최근들어서는 jenkins, github나 gitlab에서 정적분석, 코딩스타일 체크하도록 구성하여 사용하고 있죠.
push하고 스타일이 잘못됐네? 수정하고 push하고 CI에서 확인하는 것을 반복하는 것도 시간 낭비인 것 같습니다.
push하기 전에 로컬에서 미리 체크하는 방법으로 git hook에 스크립트를 작성하여 사용하시는데요.
편리하게 사용할 수 있는 lefthook이라는 것이 있어 소개해드립니다.
설치방법
시스템에 따라 아래를 참고하여 설치합니다.
go
go get github.com/Arkweid/lefthook
npm
npm i @arkweid/lefthook --save-dev # or yarn: yarn add -D @arkweid/lefthook
Rubygems
gem install lefthook
Homebrew for macOS
brew install Arkweid/lefthook/lefthook
Windows
- https://github.com/Arkweid/lefthook/releases/download/v0.7.2/lefthook_0.7.2_Windows_x86_64.zip
- 압축풀기
- C:\Programe Files\Git\usr\bin\ 폴더에 lefthook.exe 복사하기
lefthook 사용방법
저장소 루트에서 아래 커맨드를 이용하여 초기화합니다.
lefthook.yml가 생성됩니다.$ lefthook install
lefthook 수정하기
예로 커밋하기 전에 플러터의 코딩스타일 체크와 정적분석 하도록 수정해본다.pre-commit: parallel: true commands: check-dart-format: run: flutter format --set-exit-if-changed lib analyze-dart-code: run: flutter analyze .
바로 실행하는 방법
$ lefthook run pre-commit
테스트로 commit해보기
git commit하게되면 pre-commit command가 실행되는 것을 확인할 수 있다.# 소스 수정후 $ git commit RUNNING HOOKS GROUP: pre-commit EXECUTE > check-dart-format Waiting for another flutter command to release the startup lock... Formatting directory lib: Unchanged blocs\authentication\authentication_bloc.dart Unchanged blocs\authentication\authentication_event.dart Unchanged blocs\authentication\authentication_state.dart Unchanged blocs\blocs.dart Unchanged blocs\comments\comments_bloc.dart Unchanged blocs\comments\comments_event.dart Unchanged blocs\comments\comments_state.dart Unchanged blocs\community\community_bloc.dart Unchanged blocs\community\community_event.dart Unchanged blocs\community\community_state.dart Unchanged blocs\dolls\dolls_bloc.dart Unchanged blocs\dolls\dolls_event.dart Unchanged blocs\dolls\dolls_state.dart Unchanged blocs\simple_bloc_observer.dart Unchanged blocs\tab\tab.dart Unchanged blocs\tab\tab_bloc.dart Unchanged blocs\tab\tab_event.dart Unchanged common\admob_manager.dart Unchanged main.dart Unchanged models\app_tab.dart Unchanged models\community_order.dart Unchanged models\extra_action.dart Unchanged models\models.dart Unchanged screens\add_edit_doll_screen.dart Unchanged screens\add_edit_post_screen.dart Unchanged screens\community_screen.dart Unchanged screens\details_doll_screen.dart Unchanged screens\details_post_screen.dart Unchanged screens\home_screen.dart Unchanged screens\login_screen.dart Unchanged screens\main_screen.dart Unchanged screens\profile_screen.dart Unchanged screens\screens.dart Unchanged screens\setting_screen.dart Unchanged widgets\avatar.dart Unchanged widgets\community_order_button.dart Unchanged widgets\custom_dialog.dart Unchanged widgets\delete_post_snack_bar.dart Unchanged widgets\exit_dialog.dart Unchanged widgets\extra_actions.dart Unchanged widgets\loading_indicator.dart Unchanged widgets\post_item.dart Unchanged widgets\tab_selector.dart Unchanged widgets\time_text.dart Unchanged widgets\widgets.dart Formatting directory community_repository: Unchanged lib\community_repository.dart Unchanged lib\src\community_repository.dart Unchanged lib\src\entities\entities.dart Unchanged lib\src\entities\like_entity.dart Unchanged lib\src\entities\post_entity.dart Unchanged lib\src\firebase_community_repository.dart Unchanged lib\src\models\like.dart Unchanged lib\src\models\models.dart Unchanged lib\src\models\post.dart Formatting directory comments_repository: Unchanged lib\comments_repository.dart Unchanged lib\src\comments_repository.dart Unchanged lib\src\entities\comments_entity.dart Unchanged lib\src\entities\entities.dart Unchanged lib\src\firebase_comments_repository.dart Unchanged lib\src\models\comment.dart Unchanged lib\src\models\models.dart Formatting directory user_repository: Unchanged lib\src\entities\entities.dart Unchanged lib\src\entities\user.dart Unchanged lib\src\firebase_user_repository.dart Unchanged lib\src\user_repository.dart Unchanged lib\user_repository.dart Formatting directory dolls_repository: Unchanged lib\dolls_repository.dart Unchanged lib\src\dolls_repository.dart Unchanged lib\src\entities\doll_entity.dart Unchanged lib\src\entities\entities.dart Unchanged lib\src\firebase_dolls_repository.dart Unchanged lib\src\models\doll.dart Unchanged lib\src\models\models.dart EXECUTE > analyze-dart-code Analyzing 2 directories... No issues found! (ran in 24.7s) SUMMARY: (done in 31.76 seconds) ✔️ check-dart-format ✔️ analyze-dart-code
참조
https://github.com/Arkweid/lefthook/blob/master/docs/full_guide.md
이상입니다!!
반응형
'개발일지 > CI & CD - Git, Jenkins' 카테고리의 다른 글
Git - PR 반영시 지워진 브랜치 쌓여있는 문제, prune 옵션 사용 (0) | 2021.06.10 |
---|---|
Git - Encoding, Line Ending 오류 해결 방법 (0) | 2021.04.22 |
Git - Fork 한 repository 최신으로 동기화하기 (0) | 2021.02.11 |