MLOps

Black formatter, Github Actions에 적용하기

scone 2024. 1. 26. 13:50

시작합니다.

 

 

  • .github / workflows / black.yml 추가

 

  • name
    • Github Actions 에서 Workflow의 이름
    • "black formatter"
  • on
    • 어떠한 event에서 실행시킬 건지
    • push 와 pull_request에서 실행
    • pull_request에 타입 지정 가능
      • opened, rivew_requested, closed, reopened ...
      • default는 opened
  • jobs
    • workflow에 어떠한 job들이 들어가는지
    • 현재는 black code formatter 하나 적용
  • runs-on
    • Virtual Machine 지정
    • 현재 ubuntu-latest 적용
  • steps
    • setup task, command 실행 가능
    • job에 속한 연속된 tasks
  • uses
  • with
    • 각각의 action들에 의해 정의된 input parameter map 입력
    • ex) black formatter은 options 키워드와 src 키워드를 이용해 argument를 넘긴다.
    • options
      • " -l 79" : 한줄에 허용되는 character 수, 79자 by pep8 (default 88)
      • --diff : 파일을 수정하진 않고, 수정되어야 할 부분을 로그로 알려주고 수정될 형태를 제안
      • --check : 파일을 수정하진 않고 status code 반환
        • 0 : formatting 되어야 할 부분 없음
        • 1 : formatting 되어야 할 부분 있음
        • 123 : code error (internal error)
    • src
      • "./" : 전체 코드에 대해 formatting 확인

 

PR한 결과

 

pr 하자마자 무언가를 잡았네요

 

 

 

Oh no! 💥 💔 💥 8 files would be reformatted. Error: Process completed with exit code 1.

 

 

jobs:
  Black_code_formatter:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: psf/black@stable
        with:
          options: "-l 79 --diff --color --check"
          src: "./"

 

어디가 잘못된지 모르겠어서 options에 --color 를 하나 더 추가해줬습니다.

 

 

색깔로 잘 알려주네요..!!!

 

 

black 으로 수정한 뒤 바로 다시 pr 해보겠습니다.

 

 

 

좋습니다

 

 

 

 

 

참고한 출처 : https://velog.io/@wchoi/Github-Actions-%EB%9E%80