github actions auto labeling 파싱 오류 해결기

·2026년 1월 10일

[DIVE SOPT 37th] Web

목록 보기
6/6

지난 프로젝트에서 팀의 리드 언니가 github actions 활용법 중 자동 라벨링(auto-label)을 설정하는 법을 알려줘서 매번 세팅하고 열심히 쓰고 있었다

팀원이 많으면 매번 라벨 세팅하기도 귀찮고 신기술 같아서 자주 활용하고 있었고 .. 암튼 그런데 ..

time="2026-01-09T18:36:17Z" level=fatal msg="failed to execute: could not parse \\".github/labeler.yml\\""

이번 프로젝트에서는 자꾸 빌드 오류가 찍히는 거 아닌가? ..

라벨 세팅만 세 번 해봤는데 이런 적이 처음이라 도저히 감이 안 잡혔다

원인 분석

오류 메세지에도 나와있듯 .github/labeler.yml 파일이 파싱을 못하고 있다는게 원인이었다

그렇다면 뭐 떄문에 파싱이 안됐을까?

우선 나는 auto label 세팅을 위해 총 두가지 파일을 작성했다

.github/workflows 경로의 auto-label.yml

name: Auto Labeler
on:
  issues:
    types: [opened]
  pull_request_target:
    types: [opened]
    branches: [develop]
    
jobs:
  labeler:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      issues: write
      pull-requests: write
    steps:
      - name: Check Labels
        id: labeler
        uses: jimschubert/labeler-action@v2
        with:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      - name: Add labels based on user
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const author = context.payload.pull_request 
              ? context.payload.pull_request.user.login 
              : context.payload.issue.user.login;
            const userLabels = {
              "jeonghoon11": "🦊 정훈",
              "huniversal": "🐶 훈진",
              "sonnnnhe": "🐯 하은",
              "yooncandooit":"🪼 윤지",
            };
            const labelToAdd = userLabels[author];
            if (labelToAdd) {
              github.rest.issues.addLabels({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.payload.pull_request 
                  ? context.payload.pull_request.number 
                  : context.payload.issue.number,
                labels: [labelToAdd]
              });
            }

.github 경로의 labeler.yml

enable:
  issues: true
  prs: true

labels:
  - label: '🐛 FIX'
    patterns:
      - "\bFix\b"
      - "\bfix\b"
      - "\bFIX\b"
      - "\bBug\b"
      - "\bbug\b"
      - "\bBUG\b"
    title: true
    body: false

  - label: '⭐️ FEAT'
    patterns:
      - "\bFeat\b"
      - "\bFEAT\b"
      - "\bfeat\b"
    title: true
    body: false

  - label: '✏️ DOCS'
    patterns:
      - "\bDocs\b"
      - "\bDOCS\b"
      - "\bdocs\b"
    title: true
    body: false

  - label: '🎉 INIT'
    patterns:
      - "\bInit\b"
      - "\bINIT\b"
      - "\binit\b"
    title: true
    body: false

  - label: '🧁 STYLE'
    patterns:
      - "\bStyle\b"
      - "\bSTYLE\b"
      - "\bstyle\b"
      - "\bDesign\b"
      - "\bDESIGN\b"
      - "\bdesign\b"
    title: true
    body: false

  - label: '🧹 CHORE'
    patterns:
      - "\bCHORE\b"
      - "\bChore\b"
      - "\bchore\b"
    title: true
    body: false

  - label: '🛠️ REFACTOR'
    patterns:
      - "\bRefactor\b"
      - "\bREFACTOR\b"
      - "\brefactor\b"
    title: true
    body: false

  - label: '🔎 TEST'
    patterns:
      - "\bTest\b"
      - "\bTEST\b"
      - "\btest\b"
    title: true
    body: false

  - label: '🚀 DEPLOY'
    patterns:
      - "\bDeploy\b"
      - "\bDEPLOY\b"
      - "\bdeploy\b"
    title: true
    body: false

처음 생각했던 파싱 오류는 .github/labeler.yml 파일에서 정규식 패턴의 백슬래시(\b)가 제대로 이스케이프되지 않아 발생한 문제라고 생각했다

그래서 백슬래시를 두 번 쓰면 나아질까? 싶어서 작성해보았는데

결과는 ….

도저히 파싱 오류의 원인을 알 수가 없어서 기존에 고수하던 방법을 내려두고

블로그나 다른 팀의 세팅보다는 actinos 공식 문서를 보기로 했다

해결 방법

해결 후에 제대로된 원인을 분석해보자면 ..
기존에 사용하던 jimschubert/labeler-action은 서드파티 액션이라 설정 형식이 까다롭고, YAML 파일 파싱에서 자주 오류가 발생하는 것 같았다

파싱 오류가 나던 파일은 workflows의 파일이 아니라 github 폴더 내의 labeler.yml 파일이었기 때문에

과감하게 해당 파일을 삭제하고 외부 액션 대신 GitHub 공식 actions/github-script를 사용하여 JavaScript로 직접 구현하니 해결이 됐다 ..

아래는 .github/workflows/auto-label.yml의 최종 코드이다

name: Auto Labeler

on:
  issues:
    types: [opened]
  pull_request_target:
    types: [opened, reopened, synchronize]
    branches: [develop]

jobs:
  labeler:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      issues: write
      pull-requests: write

    steps:
      # 제목 기반 라벨링
      - name: Auto Labeling based on title
        if: github.event_name == 'pull_request_target' || github.event_name == 'issues'
        uses: actions/github-script@v7
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          script: |
            const payload = context.payload;
            const isPR = !!payload.pull_request;
            const target = isPR ? payload.pull_request : payload.issue;

            const title = target.title;
            const author = target.user.login;
            const issueNumber = target.number;

            const labelsToAdd = [];

            // 제목 기반 라벨 매칭
            const labelPatterns = {
              '🐛 FIX': /\b(fix|Fix|FIX|bug|Bug|BUG|hotfix|Hotfix|HOTFIX|HotFix)\b/i,
              '⭐️ FEAT': /\b(feat|Feat|FEAT|feature|Feature|FEATURE)\b/i,
              '✏️ DOCS': /\b(docs|Docs|DOCS)\b/i,
              '🎉 INIT': /\b(init|Init|INIT)\b/i,
              '🧁 STYLE': /\b(style|Style|STYLE|design|Design|DESIGN)\b/i,
              '🧹 CHORE': /\b(chore|Chore|CHORE)\b/i,
              '🛠️ REFACTOR': /\b(refactor|Refactor|REFACTOR)\b/i,
              '🔎 TEST': /\b(test|Test|TEST)\b/i,
              '🚀 DEPLOY': /\b(deploy|Deploy|DEPLOY)\b/i
            };

            // 제목에서 패턴 매칭
            for (const [label, pattern] of Object.entries(labelPatterns)) {
              if (pattern.test(title)) {
                labelsToAdd.push(label);
              }
            }

            // 사용자 기반 라벨 매칭
            const userLabels = {
              "jeonghoon11": "🦊 정훈", 
              "huniversal": "🐶 훈진",
              "sonnnnhe": "🐯 하은",
              "yooncandooit": "🪼 윤지"
            };

            if (userLabels[author]) {
              labelsToAdd.push(userLabels[author]);
            }

            const uniqueLabels = [...new Set(labelsToAdd)];

            if (uniqueLabels.length > 0) {
              try {
                await github.rest.issues.addLabels({
                  owner: context.repo.owner,
                  repo: context.repo.repo,
                  issue_number: issueNumber,
                  labels: uniqueLabels
                });
              } catch (error) {
                // 라벨 추가 실패 시 무시
              }
            }

해당 코드를 통해

  • PR과 issue의 제목 기반 라벨 매칭
    • fix, bug, hotfix 등등의 키워드가 title에 있으면 🐛 FIX 라벨이 붙는다
  • assignee 기반 라벨 매칭
    • yooncandooit의 아이디를 가진 사람이 issue / PR을 올리면 🪼 윤지 라벨이 붙는다
  • issue를 open 했을 때, PR을 open 했을 때, close 했다가 reopen 했을 때, 추가 커밋을 했을 때(synchronize) auto-label 체크가 활성화되고 자동으로 조건에 맞는 라벨이 붙는다

그냥 초기세팅에서의 단순한 이슈라고 하기엔 다른 PR의 check 검사까지 작동을 안하는 바람에 식은 땀을 쥐었던 이슈였다

공식 GitHub Actions 사용해서 해결이 되니 다행인 트러블 슈팅..

다른 프로젝트에서는 같은 이슈로 리소스 쓰지 말자 !!!

profile
🫧

0개의 댓글