Skip to main content

GitHub Actions를 통한 Dependabot 자동화

GitHub Actions를 사용하여 일반적인 Dependabot 관련 작업을 자동화하는 방법의 예입니다.

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

쓰기 권한이 있는 사용자

참고 항목

이 문서에서는 GitHub Actions을(를) 사용하여 Dependabot 관련 작업을 자동화하는 방법을 설명합니다. GitHub Actions을 사용하여 Dependabot updates를 실행하는 것에 대한 자세한 내용은 GitHub Actions 실행기의 Dependabot 정보을(를) 참조하세요.

GitHub Actions을 사용하여 Dependabot에서 종속성을 업데이트하기 위한 끌어오기 요청을 만들 때 자동화된 작업을 수행할 수 있습니다. 다음을 수행하려는 경우 이 유용한 정보를 찾을 수 있습니다.

  • Dependabot 끌어오기 요청(버전 업데이트 및 보안 업데이트)이 레이블 및 이름을 비롯한 작업 프로세스에 적합한 데이터로 생성되었는지 확인합니다.

  • 검토 프로세스에 Dependabot 끌어오기 요청(버전 업데이트 및 보안 업데이트)을 보내거나 자동으로 병합하도록 워크플로를 트리거합니다.

엔터프라이즈에서 Dependabot 활성화하기

Dependabot 및 GitHub Actions 정보

중요

Dependabot이(가) 리포지토리에 활성화된 경우, 항상 GitHub Actions에서 실행되어 리포지토리 또는 조직 수준에서 작업 정책 검사 및 비활성화를 모두 우회합니다. 이렇게 하면 보안 및 버전 업데이트 워크플로가 Dependabot을 사용할 때도 항상 실행됩니다.

Dependabot은 종속성을 최신 상태로 유지하기 위한 끌어오기 요청을 만듭니다. 이러한 끌어오기 요청을 만들 때 GitHub Actions을 사용하여 자동화된 작업을 수행할 수 있습니다. 예를 들어 추가 아티팩트 가져오기, 레이블 추가, 테스트 실행 또는 끌어오기 요청 수정 등이 있습니다.

Dependabot은 끌어오기 요청 및 댓글에서 GitHub Actions 워크플로를 트리거할 수 있지만 다른 방식으로 처리되는 이벤트도 있습니다. 자세한 내용은 GitHub Actions의 Dependabot 문제 해결을(를) 참조하세요.

GitHub Actions을 사용하여 자동화할 수 있는 끌어오기 요청의 몇 가지 일반적인 시나리오는 다음과 같습니다.

끌어오기 요청에 대한 메타데이터 가져오기

대량의 자동화를 위해서는 끌어오기 요청의 내용에 대한 정보, 즉 종속성 이름, 프로덕션 종속성인지 여부, 주 업데이트인지, 부 업데이트인지, 패치 업데이트인지에 대한 정보를 알아야 합니다. 작업을 사용하여 Dependabot에서 생성된 끌어오기 요청에 의해 업데이트되는 종속성에 대한 정보를 검색할 수 있습니다.

예제:

YAML
{% data reusables.actions.actions-not-certified-by-github-comment %}
name: Dependabot fetch metadata
on: pull_request

permissions:
  pull-requests: write
  issues: write

jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
    steps:
      - name: Dependabot metadata
        id: metadata
        uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7
        with:
          github-token: "${{ secrets.GITHUB_TOKEN }}"
      # The following properties are now available:
      #  - steps.metadata.outputs.dependency-names
      #  - steps.metadata.outputs.dependency-type
      #  - steps.metadata.outputs.update-type

자세한 내용은 dependabot/fetch-metadata 리포지토리를 참조하세요.

끌어오기 요청 레이블 지정

GitHub 레이블을 기반으로 하는 다른 자동화 또는 심사 워크플로가 있는 경우 제공된 메타데이터에 따라 레이블을 할당하도록 작업을 구성할 수 있습니다.

레이블을 사용하여 모든 프로덕션 종속성 업데이트에 플래그를 지정하는 예제:

YAML
{% data reusables.actions.actions-not-certified-by-github-comment %}
name: Dependabot auto-label
on: pull_request

permissions:
  pull-requests: write
  issues: write

jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
    steps:
      - name: Dependabot metadata
        id: metadata
        uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7
        with:
          github-token: "${{ secrets.GITHUB_TOKEN }}"
      - name: Add a label for all production dependencies
        if: steps.metadata.outputs.dependency-type == 'direct:production'
        run: gh pr edit "$PR_URL" --add-label "production"
        env:
          PR_URL: ${{github.event.pull_request.html_url}}

끌어오기 요청 자동 승인

워크플로에서 GitHub CLI을 사용하여 Dependabot 끌어오기 요청을 자동으로 승인할 수 있습니다.

예제:

YAML
{% data reusables.actions.actions-not-certified-by-github-comment %}
name: Dependabot auto-approve
on: pull_request

permissions:
  pull-requests: write

jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
    steps:
      - name: Dependabot metadata
        id: metadata
        uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7
        with:
          github-token: "${{ secrets.GITHUB_TOKEN }}"
      - name: Approve a PR
        run: gh pr review --approve "$PR_URL"
        env:
          PR_URL: ${{github.event.pull_request.html_url}}
          GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

끌어오기 요청에서 자동 합계 사용

유지 관리자가 자동 병합에 대한 특정 끌어오기 요청을 표시하도록 허용하려면 GitHub의 자동 병합 기능을 사용할 수 있습니다. 이를 통해 분기 보호 규칙에서 요구하는 테스트 및 승인이 성공적으로 충족될 때 끌어오기 요청을 병합할 수 있습니다.

자세한 내용은 끌어오기 요청 자동 병합분기 보호 규칙 관리을(를) 참조하세요.

대신 GitHub Actions 및 GitHub CLI를 사용할 수 있습니다. 다음은 my-dependency에 대한 모든 패치 업데이트를 자동으로 병합하는 예제입니다.

YAML
{% data reusables.actions.actions-not-certified-by-github-comment %}
name: Dependabot auto-merge
on: pull_request

permissions:
  contents: write
  pull-requests: write

jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: github.event.pull_request.user.login == 'dependabot[bot]' && github.repository == 'owner/my_repo'
    steps:
      - name: Dependabot metadata
        id: metadata
        uses: dependabot/fetch-metadata@d7267f607e9d3fb96fc2fbe83e0af444713e90b7
        with:
          github-token: "${{ secrets.GITHUB_TOKEN }}"
      - name: Enable auto-merge for Dependabot PRs
        if: contains(steps.metadata.outputs.dependency-names, 'my-dependency') && steps.metadata.outputs.update-type == 'version-update:semver-patch'
        run: gh pr merge --auto --merge "$PR_URL"
        env:
          PR_URL: ${{github.event.pull_request.html_url}}
          GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

참고 항목

상태 확인을 사용하여 끌어오기 요청을 테스트하는 경우 Dependabot 끌어오기 요청에 대해 대상 분기에 대해 병합하기 전에 상태 검사 필요를 사용하도록 설정해야 합니다. 이 분기 보호 규칙은 모든 필수 상태 검사를 통과하지 않는 한 끌어오기 요청이 병합되지 않도록 보장합니다. 자세한 내용은 분기 보호 규칙 관리을(를) 참조하세요.

Dependabot 및 GitHub Actions 정책

일반적으로 워크플로가 리포지토리에서 실행될 수 있는지 여부는 GitHub Actions 정책 확인과 GitHub Actions가 조직 또는 리포지토리 수준에서 활성화되었는지 여부에 따라 달라집니다. 이러한 제어는 워크플로 실행을 제한할 수 있습니다. 특히 외부 작업이 차단되었거나 GitHub Actions가 완전히 비활성화된 경우 더욱 그렇습니다.

그러나 Dependabot이 리포지토리에 활성화된 경우, 워크플로는 항상 GitHub Actions에서 실행되어 작업 정책 확인 및 비활성화를 모두 우회합니다.

  • Dependabot 워크플로는 Actions 비활성화 또는 엔터프라이즈 정책 제한으로 인해 차단되지 않습니다.
  • 외부 작업이 허용되지 않더라도 이러한 워크플로 내에서 참조되는 작업은 실행할 수 있습니다.

자세한 내용은 GitHub Actions 실행기의 Dependabot 정보을(를) 참조하세요.

실패한 워크플로 실행 조사

워크플로 실행이 실패하면 다음을 확인합니다.

  • 올바른 작업자가 워크플로를 트리거하는 경우에만 워크플로를 실행합니다.
  •         `ref`에 대해 올바른 `pull_request`를 체크 아웃합니다.
    
  • 비밀은 GitHub Actions 비밀이 아닌 Dependabot 비밀에서 제공됩니다.
  • 올바른 권한이 있는 GITHUB_TOKEN이 있습니다.

GitHub Actions 쓰기 및 디버깅에 대한 자세한 내용은 워크플로 작성을(를) 참조하세요.

워크플로 문제를 해결하는 데 도움이 되는 자세한 팁은 GitHub Actions의 Dependabot 문제 해결을(를) 참조하세요.