제목: "[Github Action] Create Issue Branch를 활용한 Issue 생성 및 feature branch 생성 자동화"
작성자: tistory.com(earth-95)
작성자 수정일: 2021년9월26일
링크: https://earth-95.tistory.com/100
작성일: 2022년7월9일
Git branch 전략을 토대로 개발을 하기 위해 각 Issue 별로 develop 브랜치 내에 feature 브랜치를 각각 따서 사용하기로 하였다.
이 때, JIRA 같은 협업 툴을 이용하면 자동으로 issue에 맞추어 feature 브랜치 생성이 가능하나, github만 사용할 때에는 issue를 생성한 후 직접 develop 브랜치 내에 feature/#issue 브랜치 생성이 필요했다.
Create Issue Branch(Github Action)을 이용하여 자동화된 스크립트를 작성하면 issue별 브랜치 생성을 해보자.
공식 사이트
https://github.com/marketplace/actions/create-issue-branch#license
Create Issue Branch에서 말하는 설치법은 크게 2가지가 있다.
1번 방법의 경우, private repository일 경우 유료이다. private repo를 통해깃허브 액션을 사용해볼것이므로 2번을 사용해보자.
깃허브의 workflow yml에 아래와 같이 작성한다.
아래 내용은 Crerate Issue Branch 설치방법에서 가져온 YML으로 실제 사용할 때에는 변경이 필요하다.
name: Create Issue Branch
on:
issues:
types: [ assigned ]
issue_comment:
types: [ created ]
pull_request:
types: [ closed ]
jobs:
create_issue_branch_job:
runs-on: ubuntu-latest
steps:
- name: Create Issue Branch
uses: robvanderleek/create-issue-branch@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
위 YAML 파일을 간단하게 설명해보면
name
on.<event_name>.types
jobs.<job_id>
job_id
는 String이며 해당 job의 config data의 map이라고 볼 수 있다.create_issue_branch_job
이 job_id
이며, Action 실행 내역을클릭했을 때 해당 이름으로 Action이 실행되었음을 확인할 수 있다.jobs.<job_id>.runs-on
jobs.<job_id>.steps
jobs.<job_id>.steps[*].uses
jobs.<job_id>.steps[*].env
Github workflow 문법 DOCS
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions
Create Issue Branch에서 제공하는 추가 기능이 여러가지 있지만, 위에서 사용한 항목에 대해 간단히 알아보자
아래 항목들은 모두 default 설정에 overwrite하는 부분이므로, repository 내 .github/issue-branch.yml을 생성하여 작성해야 한다.
default로 설정할 경우, PR merge 후 Issue가 자동으로 close되지 않는다. 따라서, true로 해당 설정을 변경하면 자동으로 issue를 close 해준다.
branchName은 아래와 같이 3가지 방식을 제공해주며, custom으로도 설정이 가능하다.
하지만 brachName에는 "/"는 들어가지 않기 때문에
feature/${issue.number}
와 같이 하고 싶다면, Source branch를 따로 생성해주어야 한다.
wildcard(*)
역시 작동하므로, 모든 label에 대해 하나의 prefix로 가기 위해서는 *
로 설정해 볼 수도 있다.comment message를 수정하고자 할 때에는 아래 내용처럼 원하느 메시지로 변경하면 된다.
Create Issue Branch의 경우,source Branch를 repository의 default brach를 기준으로 진행한다.
따라서, default branch가 main 이라면, main을 source branch로 하여 branch가 신규생성 될 것이기 때문에 자신의 레포지토리의 default branch가 어디인지 확인 후 진행해야 한다.
아래 내용은 public repository를 신규 생성하여 create issue branch를 적용해본 예시이다.
naming을 변경하였으며, issue_comment 관련된 속성을 제외하였기 때문에 그 부분을 변경하여 작성하였다.
.github/issue-branch.yml
을 생성하였다.