Skip to main content

리포지토리에 대한 코드 검사 설정

별도의 타사 검사 서비스에 대한 비용을 지불하거나 유지 관리하지 않고 끌어오기 요청에서 직접 코드 검사에 대한 가시성을 팀에 제공합니다.

누가 이 기능을 사용할 수 있나요?

관리자 역할이 있는 리포지토리 소유자, 조직 소유자 및 사용자

GitHub Team 또는 GitHub Enterprise Cloud

이 기사에서

다음 두 가지 방법으로 리포지토리에 대한 코드 검사를 설정할 수 있습니다.

  • 자동 설정: AI 기반 에이전트를 사용하여 워크플로를 자동으로 생성합니다. 다음과 같은 경우 이 옵션을 선택합니다.
    • YAML 구성을 작성하지 않고 빠르게 시작하려고 합니다.
    • 프로젝트는 일반적인 테스트 프레임워크 및 빌드 패턴을 사용합니다.
    • AI에서 생성된 워크플로를 반복하는 것이 편합니다.
  • 수동 설정: CI 워크플로를 직접 구성합니다. 다음과 같은 경우 이 옵션을 선택합니다.
    • 검사 프로세스를 정확하게 제어해야 합니다.
    • 복잡한 CI 요구 사항(예: 프라이빗 레지스트리 또는 사용자 지정 빌드 단계)이 있습니다.
    • 적용 범위가 구성되는 방법을 정확하게 이해하려고 합니다.

자동 설정

CI 구성을 수동으로 작성하지 않고 자동 설정 옵션을 사용하여 작업 코드 검사 워크플로를 생성할 수 있습니다. 에이전트는 리포지토리를 분석하고 테스트 프레임워크를 식별하며 검토 준비가 된 검사 워크플로를 사용하여 끌어오기 요청을 엽니다.

참고

자동 설정은 AI를 사용하여 워크플로 파일을 생성합니다. 이 기능을 사용하는 데 추가 비용은 없습니다.

자동 설치를 위한 필수 구성 요소

  • Code Quality 는 리포지토리에 대해 사용하도록 설정되어 있습니다. GitHub Code Quality 사용을(를) 참조하세요.
  • 리포지토리에 기존 테스트 도구 모음이 있습니다.

자동으로 검사 워크플로 생성

  1. GitHub에서 리포지토리의 기본 페이지로 이동합니다.

  2. 리포지토리 이름 아래에서 Settings를 클릭합니다. "설정" 탭이 표시되지 않으면 드롭다운 메뉴를 선택한 다음 설정을 클릭합니다.

    탭을 보여 주는 리포지토리 헤더의 스크린샷. "설정" 탭이 진한 주황색 윤곽선으로 강조 표시됩니다.

  3. 사이드바의 "보안" 아래에서 " 코드 품질" 페이지를 표시하려면 **** 을 클릭합니다.

  4. "코드 검사 분석" 섹션에서 설치 드롭다운 상자를 클릭합니다.

  5. 목록에서 AI를 사용하여 워크플로 생성을 선택합니다. 에이전트가 리포지토리를 분석할 때까지 기다립니다. 에이전트는 초안 끌어오기 요청을 열고 진행 중인 단계의 검사 목록을 게시합니다.

  6. 끌어오기 요청을 검토하려면 끌어오기 요청 검토를 클릭합니다. 에이전트가 작업을 완료하면 끌어오기 요청을 검토합니다. 끌어오기 요청 설명에는 프로젝트 구성 업데이트, 워크플로 파일 변경 내용 및 검사 출력 설정을 포함한 변경 내용이 요약되어 있습니다.

  7. 워크플로가 CI에서 성공적으로 실행되고 적용 범위가 올바르게 업로드되면 끌어오기 요청을 병합합니다.

    워크플로에 조정이 필요한 경우 자동 코드 검사 설정 에서 다양한 결과 및 반복 방법에 대한 지침을 참조하세요.

에이전트 작동 방식 및 예상되는 작업에 대한 자세한 내용은 자동 코드 검사 설정을 참조하세요.

수동 설치

기본 제공 코드 검사를 사용하면 도구 체인 또는 예산에 타사 서비스를 추가하지 않고도 테스트가 코드를 얼마나 철저하게 연습하는지 추적할 수 있습니다. 다음 절차에서는 테스트 스위트에서 Cobertura XML 커버리지 보고서를 생성하고, 이를 GitHub에 업로드한 다음, 풀 리퀘스트에서 커버리지 결과를 확인합니다.

수동 설치를 위한 필수 구성 요소

  • Code Quality 는 리포지토리에 대해 사용하도록 설정되어 있습니다.
  • 리포지토리에는 GitHub Actions에서 실행되는 테스트 모음이 있습니다.
  • 테스트 프레임워크는 Cobertura XML 형식으로 검사 보고서를 생성할 수 있습니다.

1단계: Cobertura XML 검사 보고서 생성

Cobertura XML 형식으로 검사 보고서를 출력하도록 테스트 프레임워크를 구성합니다. 코드 검사는 이 형식을 생성할 수 있는 모든 프로그래밍 언어에서 작동합니다.

  1. 아래 표에서 해당 언어의 커버리지 도구를 식별하세요.
  2. 테스트를 실행할 때마다 Cobertura XML 파일이 생성되도록 CI 워크플로에 적절한 명령 또는 구성을 추가합니다.
언어프레임워크/도구Cobertura XML을 생성하는 방법
Pythonpytest + pytest-covpytest --cov=. --cov-report=xml
JavaJaCoCo
cover2cover.py 스크립트 또는 JaCoCo-to-Cobertura Gradle/Maven 플러그 인 사용
자바스크립트/타입스크립트이스탄불/ nycnyc report --reporter=cobertura
RubySimpleCov
SimpleCov::Formatter::CoberturaFormatter 추가
Gogo test + gocover-coberturago test -coverprofile=cover.out && gocover-cobertura < cover.out > coverage.xml

프레임워크가 위에 나열되지 않은 경우 해당 설명서에서 Cobertura 출력 지원을 확인합니다. 많은 도구가 직접 지원하거나 다른 형식에서 Cobertura XML로 변환할 수 있습니다.

2단계: 검사 보고서 업로드

테스트에서 Cobertura XML 보고서를 생성한 후, 풀 리퀘스트에 커버리지 결과가 표시되도록 이를 GitHub에 업로드하세요.

  1. 리포지토리의 CI 워크플로 파일(예: .github/workflows/ci.yml)을 엽니다.

  2. 테스트를 실행하고 검사 보고서를 생성하는 단계 다음에 다음 단계를 추가합니다.

    YAML
    - name: Upload coverage report
      if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
      uses: actions/upload-code-coverage@v1
      with:
        file: COVERAGE-FILE-PATH.xml
        language: LANGUAGE
        label: LABEL
    
  3. 다음 값을 바꿉니다.

    • COVERAGE-FILE-PATH.xml: Cobertura XML 보고서의 경로(예: coverage.xml 또는 target/site/jacoco/cobertura.xml)입니다.
    • LANGUAGE: 적용되는 코드의 기본 언어입니다(예: Python, Java, JavaScript).
    • LABEL: 이 검사 보고서를 식별하는 선택적 레이블(예: code-coverage/pytest)입니다.
  4. 워크플로 변경 내용을 커밋하고 푸시합니다.

전체 워크플로 예제

이 예제에서는 pytest-cov 사용하여 Python 테스트를 실행하고 검사 보고서를 업로드합니다.

YAML
name: Code Coverage

This workflow runs your test suite, generates a Cobertura XML coverage report, and uploads it to GitHub. Once this workflow is committed, coverage results appear automatically on every pull request.

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

Run on pushes to the default branch (to establish the baseline) and on pull requests (to compare against it). Code Quality compares PR branch coverage to the default branch, so both triggers are needed.

permissions:
  contents: read
  code-quality: write
jobs:
  test:
    runs-on: ubuntu-latest
    steps:

The code-quality: write permission is required to upload coverage data. No other elevated permissions are needed.

      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}

Check out the PR head commit (not the merge commit) so coverage line numbers map correctly to the diff.

      - uses: actions/setup-python@v5
        with:
          python-version: "3.x"
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install pytest pytest-cov

Replace this step with whatever language setup your project uses (Node.js, Java, Go, etc.). The upload action works with any language that produces a Cobertura XML report.

      - name: Run tests with coverage
        run: pytest --cov=. --cov-report=xml

Adapt this step for your test framework. The key requirement is producing a Cobertura XML file. For other languages, see the framework table earlier in this article.

      - name: Upload coverage report
        if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
        uses: actions/upload-code-coverage@v1
        with:
          file: coverage.xml
          language: Python
          label: code-coverage/pytest

This step replaces any third-party coverage upload (Codecov, Coveralls, etc.). After this runs, the github-code-quality[bot] bot posts a coverage summary directly on the pull request.

# This workflow runs your test suite, generates a Cobertura XML coverage report, and uploads it to GitHub. Once this workflow is committed, coverage results appear automatically on every pull request.
name: Code Coverage

# Run on pushes to the default branch (to establish the baseline) and on pull requests (to compare against it). Code Quality compares PR branch coverage to the default branch, so both triggers are needed.
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

# The `code-quality: write` permission is required to upload coverage data. No other elevated permissions are needed.
permissions:
  contents: read
  code-quality: write

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      # Check out the PR head commit (not the merge commit) so coverage line numbers map correctly to the diff.
      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.head.sha || github.sha }}

      # Replace this step with whatever language setup your project uses (Node.js, Java, Go, etc.). The upload action works with any language that produces a Cobertura XML report.
      - uses: actions/setup-python@v5
        with:
          python-version: "3.x"

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          pip install pytest pytest-cov

      # Adapt this step for your test framework. The key requirement is producing a Cobertura XML file. For other languages, see the framework table earlier in this article.
      - name: Run tests with coverage
        run: pytest --cov=. --cov-report=xml

      # This step replaces any third-party coverage upload (Codecov, Coveralls, etc.). After this runs, the `github-code-quality[bot]` bot posts a coverage summary directly on the pull request.
      - name: Upload coverage report
        if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
        uses: actions/upload-code-coverage@v1
        with:
          file: coverage.xml
          language: Python
          label: code-coverage/pytest

3단계: 끌어오기 요청에 대한 검사 결과 보기

  1. 구성한 워크플로를 트리거하는 끌어오기 요청(또는 기존 요청으로 푸시)을 엽니다.
  2. 워크플로가 완료되면 풀 리퀘스트에서 github-code-quality[bot]의 댓글을 확인하세요. 주석에는 다음이 포함됩니다.
    • 기본 브랜치와 비교한 풀 리퀘스트 브랜치의 전체 커버리지 비율입니다.
    • 적용 범위를 얻었거나 손실된 파일을 보여 주는 파일별 분석입니다.

다음 단계