[GitHub Actions] Pull request 라벨 검사하기

[GitHub Actions] Pull request 라벨 검사하기

2023-05-11 hit count image

GitHub Actions의 PR Labels Checker를 사용하여 Pull request에 라벨이 설정되었는지 확인하는 방법에 대해서 알아보도록 하겠습니다.

개요

GitHub에서 Pull request를 관리할 때, 라벨(Label) 기능을 사용합니다. 또한, Release Drafter와 같이 Pull request의 라벨을 기준으로 동작하는 GitHub Actions도 존재합니다.

이번 블로그 포스트에서는 GitHub ActionsPR Labels Checker를 사용하여 Pull request의 라벨이 잘 설정되었는지 검토하는 방법에 대해서 알아보도록 하겠습니다.

블로그 시리즈

이 블로그는 시리즈로 제작되었습니다. 다음 링크를 통해 다른 블로그 포스트도 확인해 보시기 바랍니다.

PR Labels Checker

PR Labels CheckerPull request의 라벨이 적용되었는지 확인하는 GitHub Actions입니다.

PR Labels Checker를 사용하기 위해 .github/workflows/labels-checker.yml 파일을 만들고 다음과 같이 수정합니다.

name: Labels Checker

on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - labeled
      - unlabeled
      - synchronize

jobs:
  check_labels:
    runs-on: ubuntu-latest
    steps:
      - uses: danielchabr/[email protected]
        with:
          hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies
          githubToken: $

이와 같이 GitHub Actions를 생성하였다면, Pull requestbreaking change, feature, bug, style, refactor, test, chore, docs, ci, dependencies중 하나의 라벨이 설정되지 않으면 에러가 발생하게 됩니다.

여기서 설정한 라벨은 Release Drafter에서 Release note를 자동으로 작성하기 위해 사용한 라벨입니다.

Release Drafter

저는 GitHubRelease note를 자동화하기 위해 Release Drafter를 사용하고 있습니다. Release Drafter에 대한 자세한 내용은 다음 링크를 참고하시기 바랍니다.

저는 Release Drafterautolabeler에 의해 라벨이 잘 적용 되었는지 확인하기 위해 다음과 같은 GitHub Actions를 사용하고 있습니다.

name: Release Drafter

on:
  push:
    branches:
      - main
  pull_request:
    types:
      - opened
      - reopened
      - synchronize

permissions:
  contents: read

jobs:
  update_release_draft:
    permissions:
      contents: write
      pull-requests: write
      checks: write
    runs-on: ubuntu-latest
    steps:
      - uses: release-drafter/[email protected]
        env:
          GITHUB_TOKEN: $
      - uses: danielchabr/[email protected]
        with:
          hasSome: breaking change,feature,bug,style,refactor,test,chore,docs,ci,dependencies
          githubToken: $

이렇게 GitHub Actions를 구성하면 Pull request가 생성될 때, Release Drafter에 의해 자동으로 라벨이 설정되고, 이후 PR Labels Checker가 라벨이 잘 적용되었는지 확인하게 됩니다. Release Drafterautolabeler이 라벨을 잘 작성해 주지만, 만약을 위해 한번 더 체크하도록 구성하였습니다.

완료

이것으로 GitHub ActionsPR Labels Checker를 사용하여 Pull request의 라벨이 잘 적용이 되었는지 확인하는 방법에 대해서 알아보았습니다. Pull request의 라벨을 이용한 GitHub Actions를 사용하거나, 라벨을 사용하여 프로젝트 관리를 하고 있다면, PR Labels Checkers의 도입을 추천합니다.

제 블로그가 도움이 되셨나요? 하단의 댓글을 달아주시면 저에게 큰 힘이 됩니다!

앱 홍보

책 홍보

스무디 한 잔 마시며 끝내는 React Native 책을 출판한지 벌써 2년이 다되었네요.
이번에도 좋은 기회가 있어서 스무디 한 잔 마시며 끝내는 리액트 + TDD 책을 출판하게 되었습니다.

아래 링크를 통해 제가 쓴 책을 구매하실 수 있습니다.
많은 분들에게 도움이 되면 좋겠네요.

스무디 한 잔 마시며 끝내는 React Native, 비제이퍼블릭
스무디 한 잔 마시며 끝내는 리액트 + TDD, 비제이퍼블릭
Posts