LoginSignup
2
0

More than 1 year has passed since last update.

GitHub Actionsを使ってGitHubのPRのラベルを自動生成しよう!

Last updated at Posted at 2022-12-31

概要

プロジェクトによって使用しているラベルの色や名称がバラバラだと困るかと思います
そのため、ラベルの運用を統一すべきだと私は考えています
今回は手動で作成せずにラベルを自動生成及び定期的に更新できるようGitHub Actionsを使って自動化したいと思います

使用するAction

今回はlabel-syncerを使用します

workflowを書いてみよう

今回作成するファイルは

  • .github/worklfows/label-syncer.yml
  • .github/labels.yml

の2種類です

tree
.
└── .github
        ├──workflows
        │     └──label-syncer.yml
        └──labels.yml

label-syncer.ymlにラベルを自動生成するワークフローを作成します
また、チェックアウトについて詳しく知りたい方は以下の記事を参照してください

.github/worklfows/label-syncer.yml
name: Sync labels

on: pull_request
jobs:
  build:
    name: Sync labels
    runs-on: ubuntu-latest
    steps:
      # リポジトリのチェックアウト
      - uses: actions/checkout@v2
      # label-syncerを使用
      - uses: micnncim/action-label-syncer@v0.3.1
        env:
          # GITHUB_TOKENはデフォルトで使用できるため、secretsへの追記は不要
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          # .github/labels.ymlに自動生成するラベルの設定を記載
          manifest: .github/labels.yml

ラベルの設定を行います
ymlファイルに

  • 説明
  • ラベル名

を指定します

.github/labels.yml
- color: d73a4a
  description: Something isn't working
  name: bug
- color: 0075ca
  description: Improvements or additions to documentation
  name: documentation
- color: a2eeef
  description: New feature or request
  name: enhancement
- color: b60205
  description: An urgent pull request to look
  name: emergency
- color: f9d0c4
  description: Refactor Code
  name: refactor
- color: 1d76db
  description: Test Code
  name: test

ラベルを確認してみよう!

ラベルの初期設定は以下の通りです
スクリーンショット 2023-01-01 6.26.57.png

先ほど設定したラベルに変更されていることが確認できました!
スクリーンショット 2023-01-01 6.28.11.png

ラベルの更新を決まった時間に定期的に行うには?

ラベルの作成及び更新は初回に作成する以外頻繁に変えるものではないので
下記のようにcronを使って例えば毎週月曜日朝9時に更新する運用をしてもいいかと思います

.github/worklfows/label-syncer.yml
name: Sync labels
on:
  schedule:
    - cron: "0 9 * * 1"
jobs:
  build:
    name: Sync labels
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: micnncim/action-label-syncer@v0.3.1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          manifest: .github/labels.yml

schedule及びcronの使い方は以下の公式ドキュメントを参照してください

記事の紹介

下記の記事も書きましたのでよかったら読んでみてください

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0