背景

GitHub ActionsをいちいちGitHubのページから実行するのは時間がかかるので、 ローカルである程度テストしてから実行したい。

ユーザーガイドがあるのでこちらを参考に動かしてみる。

環境

  • Ubuntu 22.04
  • Homebrew 4.2.20
    • dnfは用意されていたがaptがなさそうだったので別途Homebrewを入れた
  • Docker 26.1.0
    • actの実行に必要

導入

brewでactをインストールする。

brew install act

サンプルのリポジトリをクローンしてくる。

git clone https://github.com/cplee/github-actions-demo

実行する。

cd github-actions-demo
act

初回実行時にactの実行イメージの選択を迫られたので、Mediumを選んだ。

  • Large size image (17GB+53GB=80GB)
    • GitHub Hosted Runnerのスナップショット
  • Medium size image (~500GB)
    • ほとんどのアクションに必要なツール群がそろっているイメージ
  • Micro size image (<200MB)
    • 最低限のNodeJSのみのイメージ

作ってみる

  • .github/workflows以下にymlファイルを設置する
  • 試したときはgithubにリポジトリをつくってpushしなければエラーとなった
    • actions/checkout@v2を使っているためと思われる
  • echoするだけの設定で実行してみる
name: CI
on: push

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - run: echo the beating of the drums.

動いた。

INFO[0000] Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock' 
[CI/test] 🚀  Start image=catthehacker/ubuntu:act-latest
[CI/test]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[CI/test]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[CI/test]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[CI/test] ⭐ Run Main actions/checkout@v2
[CI/test]   🐳  docker cp src=/home/xxx/downloads/notify_github_issues_deadline/. dst=/home/xxx/downloads/notify_github_issues_deadline
[CI/test]   ✅  Success - Main actions/checkout@v2
[CI/test] ⭐ Run Main echo the beating of the drums.
[CI/test]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1] user= workdir=
| the beating of the drums.
[CI/test]   ✅  Success - Main echo the beating of the drums.
[CI/test] Cleaning up container for job test
[CI/test] 🏁  Job succeeded