この記事は お題は不問!Qiita Engineer Festa 2023 で記事投稿! - Qiita の参加記事です。
はじめに
最近、フォントをインストールするための Cask がほしいと思い、Homebrew Tap をつくりました。
そのときに Cask Tap のテストを GitHub Actions でやる方法を調べたので、その方法をまとめます。
実際に書いたもの
今回、GitHub Actions のテストで走らせたいものは以下です。
brew readallbrew stylebrew auditbrew install
そして、実際に書いた workflow ファイルは以下です。
name: Test
on:
pull_request:
types:
- opened
- synchronize
- reopened
workflow_dispatch:
permissions:
contents: read
defaults:
run:
shell: bash
jobs:
test:
runs-on: macos-latest
timeout-minutes: 5
strategy:
matrix:
tap:
- "ohakutsu/sample-cask"
steps:
- name: Set up Homebrew
id: set-up-homebrew
uses: Homebrew/actions/setup-homebrew@master
with:
test-bot: false
- name: Cache Homebrew Bundler RubyGems
id: cache
uses: actions/cache@v3
with:
path: ${{ steps.set-up-homebrew.outputs.gems-path }}
key: ${{ runner.os }}-rubygems-${{ steps.set-up-homebrew.outputs.gems-hash }}
restore-keys: ${{ runner.os }}-rubygems-
- name: Install Homebrew Bundler RubyGems
if: steps.cache.outputs.cache-hit != 'true'
run: brew install-bundler-gems
- run: brew readall '${{ matrix.tap }}'
- run: brew style --cask '${{ matrix.tap }}'
- run: brew audit --strict --cask --tap '${{ matrix.tap }}'
- run: brew install --cask --verbose "$(echo '${{ matrix.tap }}' | awk -F '/' '{print $2}')"
主に、Homebrew/homebrew-caskのci.ymlをもとに書きました。
setup-homebrew Action はその名の通り、Homebrew をセットアップします。
setup-homebrew Action では、自動で Tap を追加してくれるようなのでbrew tapは不要です。
test-botは、Homebrew のテストを実行するためのもののようです。Issue などをみた感じ Cask Tap のサポートはあまりしていないようなので、今回は使っていません。
→ Also test Casks · Issue #523 · Homebrew/homebrew-test-bot
ただ、brew test-botの--only-tap-syntaxオプションを使うことで、readall, style, auditを実行することができるようです。(tap-newコマンドで生成されたテンプレートなどを参考に書いた)
test-botを使う場合は以下のようになります。
- - run: brew readall '${{ matrix.tap }}'
- - run: brew style --cask '${{ matrix.tap }}'
- - run: brew audit --strict --cask --tap '${{ matrix.tap }}'
+ - run: brew test-bot --only-cleanup-before
+ - run: brew test-bot --only-setup
+ - run: brew test-bot --only-tap-syntax
最後に
今回は、Homebrew Cask Tap のテストを GitHub Actions でやる方法をまとめました。
test-botを使うと Formula のテストもできるようなので、次やることがあればそちらもやってみたいです。