본문 바로가기

기타/Github Actions

[Github Actions] 정규식으로 PR Title 확인

name: PR Title Validation

on:
  pull_request:
    types: [opened, edited, reopened]

jobs:
  title-check:
    runs-on: ubuntu-latest
    steps:
      - name: Check PR Title
        run: |
          title=$(jq -r '.pull_request.title' $GITHUB_EVENT_PATH)
          if [[ "$title" =~ ^(\[Feat\]|\[Refactor\]|\[Fix\]|\[Test\]|\[Chore\]|\[Setting\]|\[Docs\]) ]]; then
            echo "PR Title is valid."
          else
            echo "PR Title is invalid."
            exit 1
          fi

 

위의 yaml 파일을 .github/workflows 하위에 위치시키면 워크플로우로 등록된다.

정규식을 사용해 PR title이 [Feat], [Refactor], [Fix], [Test], [Chore], [Setting], [Docs] 로 시작하는 경우만 validation을 통과하도록 작성했다.