GitHub Actionsをローカルでテストする方法を理解する

# 目次
1. 背景
2. homebrewのinstall
3. actのinstall
4. actで色々動かしてみる

# 1. 背景
[こちらの検証](https://qiita.com/yamatai12/items/52c7c01c034bc57959c2)でgithub-actionsのworkflowファイルを作る必要が出た為です。

こちらに従って進めます。
https://github.com/nektos/act#act-user-guide

# 2. homebrewのinstall
https://brew.sh/
以下をコピーするように言われますので、コピーして実行します。
```terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

以下のような警告が表示されました。
```terminal
Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.
==> Installation successful!
```

vi ~/.zshrcで.zshrcを開いて
以下を貼り付けます。
```.zshrc
export PATH="/usr/local/bin:$PATH"
```

```terminal
source ~/.zshrc
brew -v
Homebrew 4.1.12
```

これでhomebrewが使えます。

# 3. actのinstall
```terminal
brew install act
```

# 4. actで色々動かしてみる
### すべてのアクションをリストアップ
```terminal
act -l
WARN  ⚠ You are using Apple M-series chip and you have not specified container architecture, you might encounter issues while running act. If so, try running it with '--container-architecture linux/amd64'. ⚠ 
```
警告が出ました。
container-architectureを指定しないといけないそうです。

```terminal
act -l --container-architecture linux/amd64
Stage  Job ID  Job name  Workflow name  Workflow file  Events           
0      build   build     Test CI        test.yml       push,pull_request
```
これで正常にコマンド実行できました。

imageサイズを聞かれましたのでMediumにしました。
```terminal
~/Desktop/github.com/yamatai12/jest-lab(main) $ act  --container-architecture -j build  
? Please choose the default image you want to use with act:

  - Large size image: +20GB Docker image, includes almost all tools used on GitHub Actions (IMPORTANT: currently only ubuntu-18.04 platform is available)
  - Medium size image: ~500MB, includes only necessary tools to bootstrap actions and aims to be compatible with all actions
  - Micro size image: <200MB, contains only NodeJS required to bootstrap actions, doesn't work with all actions

Default image and other options can be changed manually in ~/.actrc (please refer to https://github.com/nektos/act#configuration for additional information about file structure) Medium
```

Docker daemonに接続できないというエラーが出ました。
```terminal
~/Desktop/github.com/yamatai12/jest-lab(main) $ act pull_request --container-architecture linux/amd64
[Test CI/build] 🚀  Start image=catthehacker/ubuntu:act-latest
[Test CI/build]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform=linux/amd64 username= forcePull=true
Error: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
```

DockerDesktopを起動したら上のコマンドを実行できました。

vオプションをつけるとログが表示されます。
```terminal
act pull_request -v --container-architecture linux/amd64
~~~~
[Test CI/build] [DEBUG] Writing entry to tarball workflow/3 len:14
[Test CI/build] [DEBUG] Extracting content to '/var/run/act'
[Test CI/build]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/3] user= workdir=
[Test CI/build] [DEBUG] Exec command '[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/3]'
[Test CI/build] [DEBUG] Working directory '/Users/yamanetaisei/Desktop/github.com/yamatai12/jest-lab'
| 
| > jest-lab@1.0.0 test
| > jest
| 
|  PASS  tests/processNumbers1.test.ts (13.534 s)
|  PASS  tests/processNumbers2.test.ts (13.825 s)
|  PASS  tests/processNumbers3.test.ts (13.763 s)
|  PASS  tests/test3.test.ts
|  PASS  tests/test2.test.ts
|  PASS  tests/test1.test.ts
|  PASS  tests/fetchData3.test.ts (16.532 s)
|  PASS  tests/fetchData1.test.ts (5.003 s)
|  PASS  tests/fetchData2.test.ts (5.252 s)

| Test Suites: 9 passed, 9 total
| Tests:       15 passed, 15 total
| Snapshots:   0 total
| Time:        20.65 s
| Ran all test suites.
[Test CI/build]   ✅  Success - Main Run Jest tests
~~~~~~~
```

# 参考
- [setup-node](https://github.com/actions/setup-node)
- [actを使ってGitHub Actionsをローカル実行する](https://zenn.dev/yumemi_inc/articles/203779a4eba922)
- [actを使ってGithub Actionsをローカルで実行する](https://qiita.com/nijigen_plot/items/7f7eb67b254d7b4d58e8)