はじめに
普段開発をしていると、定義ファイルや設定ファイルの更新を行う機会は少なくありません。
".rubocop_todo.yml" を更新するような単純作業は機械にまかせていきたいなと思いこの記事を書きました。
どのように実現するか
GitHub Actions には 定期実行を行う機能が存在します (on.schedule
)
定期実行した job の中で rubocop
を実行し生じた差分を利用し Pull request を作成します。
今回は peter-evans/create-pull-request
を利用します。
GitHub Actions の設定例
.githu/workflows
directory 以下に ファイルを作成します
yml に記載している 処理は以下の通りです。
- repository を checkout
- Ruby の install & bundle install
- rubocop の実行
- Pull request の作成
.githu/workflows/update_rubocop_todo.yml
name: Update .rubocop_todo.yml
on:
schedule:
- cron: "0 1 * * 1-5"
workflow_dispatch:
permissions:
contents: write
pull-requests: write
jobs:
export_emoji:
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v3
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- run: bundle exec rubocop --auto-gen-config --auto-gen-only-exclude --no-exclude-limit
- uses: peter-evans/create-pull-request@v4
with:
commit-message: Update .rubocop_todo.yml
delete-branch: true
title: Update .rubocop_todo.yml
reviewers: mziyut
上記 yml を main (master) branch 等に push し、定義した時間まで待つか、 Actions 内から手動実行すると
以下のような Pull request が作成されます
さいごに
- 今回は、 rubocop を例に記載しましたが、 rubocop 以外にも適用できます
- 自動化して時間を使うべきところに使えるようにしたいですね