GitHub Local Actionsとは
GitHub Actionsのローカル実行ツールとして、actは有名なんじゃないかと思います。
GitHub Local Actionsは、GitHub上とほぼ同等のGUI操作・設定でactによるローカル実行ができるVS Code拡張機能になります。
actとの違い
視覚的に使えるかどうかだけならactで良い、と思われる方もいるかもしれません。
が、GitHub Local Actionsで個人的に便利だなと思ったのは シークレットの取り扱い です。
actはGITHUB_TOKENが自動付与されない、シークレットは別途ファイル管理する必要があるなどちょっと面倒なところがありました。
GitHub Local Actionsの場合、GITHUB_TOKENが自動設定されておりそのまま使うことができます。
それ以外のシークレットもUIでポチポチ操作するだけで扱えるので、GitHub(つまりは本番)に近い状態で実行することができるというのが大きな魅力ですね。
インストール方法
actとDockerのインストールが必要です。
公式インストール手順
VS Code上の表示結果
インストールに成功すると下記のように、ワークフローの一覧や実行履歴が表示されます。
DockerインストールしているのにDocker Engineの部分がバツ表示になっている場合、パスが通っていない可能性があるので、docker --versionコマンドが通るか確認してみましょう。
通らない場合はパスを通してあげてください。
操作方法
ワークフローの右側にワークフローの表示および実行アイコンがあります。
それを押下するだけで表示・実行が簡単にできます。
実行結果は下記のように表示されます。
* 実行するタスク: GitHub Local Actions: GitHub Actions Demo #3
act --workflows ".github/workflows/github-actions-demo.yml" --secret-file "" --var-file "" --input-file "" --eventpath ""
Using docker host 'unix:///var/run/docker.sock', and daemon socket 'unix:///var/run/docker.sock'
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Set up job
[GitHub Actions Demo/Explore-GitHub-Actions] 🚀 Start image=catthehacker/ubuntu:act-latest
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] network="host"
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[node --no-warnings -e console.log(process.execPath)] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Set up job
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main echo "🎉 The job was automatically triggered by a push event."
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[bash -e /var/run/act/workflow/0] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] 🎉 The job was automatically triggered by a push event.
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main echo "🎉 The job was automatically triggered by a push event." [82.917375ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main echo "🐧 This job is now running on a Linux server hosted by GitHub!"
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[bash -e /var/run/act/workflow/1] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] 🐧 This job is now running on a Linux server hosted by GitHub!
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main echo "🐧 This job is now running on a Linux server hosted by GitHub!" [96.057542ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main echo "🔎 The name of your branch is refs/heads/main and your repository is KouYuume/github-actions-learning-repo."
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[bash -e /var/run/act/workflow/2] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] 🔎 The name of your branch is refs/heads/main and your repository is KouYuume/github-actions-learning-repo.
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main echo "🔎 The name of your branch is refs/heads/main and your repository is KouYuume/github-actions-learning-repo." [81.4075ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main Check out repository code
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker cp src=/Users/xxx/github-actions-learning-repo/. dst=/Users/xxx/github-actions-learning-repo
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main Check out repository code [33.089125ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main echo "💡 The KouYuume/github-actions-learning-repo repository has been cloned to the runner."
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[bash -e /var/run/act/workflow/4] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] 💡 The KouYuume/github-actions-learning-repo repository has been cloned to the runner.
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main echo "💡 The KouYuume/github-actions-learning-repo repository has been cloned to the runner." [86.631167ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main echo "🖥️ The workflow is now ready to test your code on the runner."
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[bash -e /var/run/act/workflow/5] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] 🖥️ The workflow is now ready to test your code on the runner.
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main echo "🖥️ The workflow is now ready to test your code on the runner." [120.072375ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main List files in the repository
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[bash -e /var/run/act/workflow/6] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] README.md
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main List files in the repository [101.289458ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Main echo "🍏 This job's status is success."
[GitHub Actions Demo/Explore-GitHub-Actions] 🐳 docker exec cmd=[bash -e /var/run/act/workflow/7] user= workdir=
[GitHub Actions Demo/Explore-GitHub-Actions] 🍏 This job's status is success.
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Main echo "🍏 This job's status is success." [77.600208ms]
[GitHub Actions Demo/Explore-GitHub-Actions] ⭐ Run Complete job
[GitHub Actions Demo/Explore-GitHub-Actions] Cleaning up container for job Explore-GitHub-Actions
[GitHub Actions Demo/Explore-GitHub-Actions] ✅ Success - Complete job
[GitHub Actions Demo/Explore-GitHub-Actions] 🏁 Job succeeded
GitHub Actions Demo #3 exited with exit code 0.
簡単ですね。
利用時の注意点とフォローの仕方
actはローカル実行機能であり、ローカルでのテスト機能ではないです。
CIの場合はあまり考慮する必要ないと思いますが、CDの場合は実際にデプロイ処理が走ることになるので、本番環境等に不必要な影響を与えないように注意した方が良いです。
act利用の場合は環境変数ACTにtrueが設定されているので、条件分岐にうまく混ぜることで、ローカル動作確認とGitHub上での設定をうまく使い分けることができます。
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
if: ${{ !env.ACT }}
<実行結果>
Skipping step 'echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."' due to '${{ !env.ACT }}'
経緯・感想
直近案件でGitHub Actionsを久々にいじる予定があり、以前学習していた頃に使っていたactの最新バージョン等確認したところ、拡張機能の案内があって「ほほーん」となりました。
最初はactがGUIで使えるだけかとも思っていたのですが、特にシークレットの扱いが非常に便利だなと思ったので、せっかくなので記事にしてみようかと思った次第です。


