[GitHub Actions] PR Labeling 자동화

Chex·2024년 5월 31일
0
post-thumbnail

actions/labeler를 참고했습니다.

PR을 생성할 때마다 라벨링을 직접 선택해야하는 번거로움을 줄이고자 GitHub Actions를 사용하여 해당 과정을 자동화했습니다.

1. PR 라벨링 워크플로우 생성

.github/workflows/label.yml 파일을 생성합니다.(*파일명 변경 가능)

name: "Pull Request Labeler"
on:
	pull_request_target: # PR이 open(reopen) 되거나 새로운 commit push된 경우
		types: [opened, reopened, synchronize]

jobs:
  triage:
    permissions:        	# workflows 권한 지정
      contents: read        # 레포 읽기 권한
      pull-requests: write  # PR 쓰기 권한
    runs-on: ubuntu-latest
    steps:
	    - name: Check Labels
	      uses: actions/labeler@v5 # actions/labeler@v5 사용
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          sync-labels: true      # 규칙에 맞지 않는 라벨 제거

2. 라벨링 규칙 작성

.github/labeler.yml 파일을 생성합니다.(*파일명 변경 불가)

🍳 Frontend:
  - changed-files:
      - any-glob-to-any-file: 'Frontend/**/*'
🚀 Backend:
  - changed-files:
      - any-glob-to-any-file: 'Backend/**/*'
🧢 Data:
  - changed-files:
      - any-glob-to-any-file: 'Data/**/*'
✨ Feature:
  - head-branch: ['^feat', 'feat']
🐛 Bug Report:
  - head-branch: ['^hotfix', 'hotfix', '^fix', 'fix']
🛫 Release:
  - base-branch: 'main'
  • 🍳 Frontend 라벨은 Frontend 하위 폴더에서 변화가 있을 경우 추가합니다.
  • 🚀 Backend 라벨은 Backend 하위 폴더에서 변화가 있을 경우 추가합니다.
  • 🧢 Data 라벨은 Data 하위 폴더에서 변화가 있을 경우 추가합니다.
  • ✨ Feature 라벨은 head branch 명에 ‘feat’이 포함된 경우 추가합니다.
  • 🐛 Bug Report 라벨은 head branch 명에 ‘fix’ 또는 ‘hotfix’가 포함된 경우 추가합니다.
  • 🛫 Release 라벨은 main branch에 PR이 open될 경우 추가합니다.

*주의) yml파일에는 Tab 문자가 포함되면 안됩니다. (공백 문자만 가능)

vscodeprettier를 사용하고 있는 경우 아래와 같이 작성하여 공백 문자만 사용하도록 설정해줄 수 있습니다.

// settings.json
"prettier.useTabs": false, // false면 공백 사용, true면 탭 사용

3. 실행결과

라벨링 자동화 결과

profile
Fake It till you make It!

0개의 댓글