LoginSignup
8
1
お題は不問!Qiita Engineer Festa 2023で記事投稿!

Homebrew Cask TapのテストをGitHub Actionsでする

Last updated at Posted at 2023-07-02

この記事は お題は不問!Qiita Engineer Festa 2023 で記事投稿! - Qiita の参加記事です。

はじめに

最近、フォントをインストールするための Cask がほしいと思い、Homebrew Tap をつくりました。
そのときに Cask Tap のテストを GitHub Actions でやる方法を調べたので、その方法をまとめます。

実際に書いたもの

今回、GitHub Actions のテストで走らせたいものは以下です。

  • brew readall
  • brew style
  • brew audit
  • brew install

そして、実際に書いた workflow ファイルは以下です。

.github/workflows/test.yml
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-caskci.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 のテストもできるようなので、次やることがあればそちらもやってみたいです。

8
1
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
8
1