0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘録】GitHub Actionsをローカルで動かす!`act` 導入ガイド

Posted at

概要

GitHub Actions をローカルで検証したいとき、最も有力なツールが act です。

CIへpushする前にローカルで .github/workflows/*.yml がちゃんと動くか確認したい人向けに、Ubuntu / WSL2 環境での導入方法をまとめました。

act とは?

  • GitHub Actions のワークフロー(.yml)を ローカルでそのまま再現実行できるCLIツール
  • Dockerコンテナ内でActionsをシミュレートする
  • CIのデバッグ高速化・効率化にとても便利

前提

  • Ubuntu 20.04〜 または WSL2(Windows + Ubuntu)
  • Docker Desktop for Windows がインストール・起動済み(WSL統合有効)
  • WSL側で docker info が正常に通ること

act のインストール手順

# 圧縮ファイルダウンロード
curl -LO https://github.com/nektos/act/releases/download/v0.2.78/act_Linux_x86_64.tar.gz

# 解凍して配置
tar -xzf act_Linux_x86_64.tar.gz
sudo mv act /usr/local/bin/

# 動作確認
which act
act --version

出力例:

/usr/local/bin/act
act version 0.2.78

実行してみる

act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest

## envを指定して実行
act -P ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest --env-file .github/workflows/.env.ci

このコマンドは以下のように動作します:

  • .github/workflows を読み込み
  • ubuntu-latest イメージを使って各ジョブをシミュレーション
  • CIとほぼ同じ流れでローカル実行される

注意点

  • act は内部で Docker を使います
  • WSL2 の Ubuntu から実行する場合、Windows側の Docker Desktop が起動している必要あり

最後に

ローカルで GitHub Actions を叩けると、CI失敗の試行錯誤が劇的に早くなります。
ぜひ導入して、CIの無駄待ちを減らしていきましょう!

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?