[I-project] 프로젝트 세팅(1) - issue 생성시 branch 자동생성 되도록 github actions 설정

Jifrozen·2023년 12월 22일
0

I-project

목록 보기
1/4

issue 생성시 branch 자동생성 되도록 github actions

보통 issue를 생성 -> 브랜치를 생성하는 루틴을 하는데 그렇기 때문에 issue를 만들면 옆에 create branch를 통해 브랜치를 생성하게 된다. 하지만 이러한 루틴자체가 자동화 되면 좋겠다는 생각을 해서 Create Issue Branch를 사용하게 되었다.

.github/workflows/create-issue-branch.yml

name: Create Issue Branch
 on:
   issues:
     types: [assigned]

 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 }}
       - name: Echo branch name
         run: echo ${{ steps.Create_Issue_Branch.outputs.branchName }}

공식문서 를 보면 create-issue-branch.yml 예시가 있다. 거의 그대로 따라하였는데 위에부터 설명하자면
on:
issues:
types: [assigned]
assigned되면 해당 actions가 실행된다.

jobs:
create_issue_branch_job:
runs-on: ubuntu-latest

잡의 이름은 create_issue_branch_job이고
steps:
- name: Create Issue Branch
uses: robvanderleek/create-issue-branch@main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Echo branch name
run: echo ${{ steps.Create_Issue_Branch.outputs.branchName }}

스텝은 2개로 Create Issue Branch를 진행하고 콘솔에 echo해준다.

근데 이제 현재 프로젝트의 경우 branchName을 label에 따라
feat 라벨이면 feat/issue-{이슈번호} / env면 chore/issue-{이슈번호} 를 하기를 원했다.

따라서 issue-branch.yml설정파일을 만들었다.

.github/issue-branch.yml

branchName: short
 autoCloseIssue: true
 branches:
   - label: docs📝
     prefix: docs/
   - label: hotfix🚑
     prefix: hotfix/
   - label: refactor♻️
     prefix: refactor/
   - label: env🔧
     prefix: chore/
   - label: release👷
     prefix: release/
   - label: test✅
     prefix: test/
   - label: bug🐛
     prefix: fix/
   - label: question🏷️
     skip: true
   - label: '*'
     prefix: feature/
 commentMessage: 'Branch ${branchName} created for issue: ${issue.title}'
 copyIssueLabelsToPR: true
 copyIssueAssigneeToPR: true
 copyIssueProjectsToPR: true
 copyIssueMilestoneToPR: true

branchName:short는 브랜치 네임의 옵션중 하나로 issue-이슈번호의 형식은 short이다. 사실 issue제목에 따라 브랜치 네임을 정하는 방법도 생각해보았지만 한글이라 잘 작동하지 않는다.

autoCloseIssue: true
브랜치가 닫히면 자동으로 이슈도 닫힌다,.

branches:

  • label: docs📝
    prefix: docs/
  • label: hotfix🚑
    prefix: hotfix/
  • label: refactor♻️
    prefix: refactor/
  • label: env🔧
    prefix: chore/
  • label: release👷
    prefix: release/
  • label: test✅
    prefix: test/
  • label: bug🐛
    prefix: fix/
  • label: question🏷️
    skip: true
  • label: '*'
    prefix: feature/
    각 라벨에 따라 브랜치의 prefix이다.
    다른 이모지는 작동하지 않기때문에 라벨을 깃모지를 통해 생성해줘야한다.(라벨에 이모티콘 포기몬해!!)
  • label: question🏷️
    skip: true
    question라벨일시 스킵해주었다. commentMessage: 'Branch ${branchName} created for issue: ${issue.title}'

    이슈 커멘트로 달아줄 메시지형식을 지정해주었다.

copyIssueLabelsToPR: true: pr생성시 이슈 라벨 복사
copyIssueAssigneeToPR: true: pr생성시 이슈 Assignee 복사
copyIssueProjectsToPR: true: pr생성시 이슈 Projects 복사
copyIssueMilestoneToPR: true: pr생성시 이슈 Milestone 복사

결과적으로 이슈를 생성하면 자동으로 브랜치를 생성해주기 때문에 사소한부분이지만 반복되는일을 자동화하여 불편함을 개선할 수 있었다.
출처
공식문서

0개의 댓글