GithubActionsで変数やSecretを間接参照したい


## やりたいこと
- 変数を間接参照させたい
- Linuxコマンドのevalみたいなことをやりたい


## サンプル
- `- run: echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}`がミソ
    - 最終的には、`secrets[DB_USERPASSWORD_DEV]`が評価されている
    - よく見るサンプルなどでは、`secrets.DB_USERPASSWORD_DEV`という形で見かけるけれど、実はインデックス構文に対応しているので上記の書き方ができる
    - 文字列結合などの関数がないようで、format関数を使うとうまく組める

全体

```yaml
name: test-matrix

on:
  workflow_dispatch:

jobs:
  job-matrix:
    strategy:
      matrix:
        env: [DEV, STG, PRD]
    runs-on: ubuntu-latest

    steps:
    - run: echo ${{ matrix.env }}

    - run: echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}
```

渡したいSecret

```
DB_USERPASSWORD_DEV=12345
DB_USERPASSWORD_STG=aiueo
DB_USERPASSWORD_PRD=kakiku
```

## 実行結果
secretなので、マスクされてはいるが取得できている模様。

```
act -P ubuntu-latest=nektos/act-environments-ubuntu:18.04-lite workflow_dispatch -j 'job-matrix'  --secret-file .secrets
[test-matrix/job-matrix-1] 🚀  Start image=nektos/act-environments-ubuntu:18.04-lite
[test-matrix/job-matrix-2] 🚀  Start image=nektos/act-environments-ubuntu:18.04-lite
[test-matrix/job-matrix-3] 🚀  Start image=nektos/act-environments-ubuntu:18.04-lite
[test-matrix/job-matrix-3]   🐳  docker pull image=nektos/act-environments-ubuntu:18.04-lite platform= username= forcePull=false
[test-matrix/job-matrix-2]   🐳  docker pull image=nektos/act-environments-ubuntu:18.04-lite platform= username= forcePull=false
[test-matrix/job-matrix-1]   🐳  docker pull image=nektos/act-environments-ubuntu:18.04-lite platform= username= forcePull=false
[test-matrix/job-matrix-2]   🐳  docker create image=nektos/act-environments-ubuntu:18.04-lite platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test-matrix/job-matrix-3]   🐳  docker create image=nektos/act-environments-ubuntu:18.04-lite platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test-matrix/job-matrix-1]   🐳  docker create image=nektos/act-environments-ubuntu:18.04-lite platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test-matrix/job-matrix-3]   🐳  docker run image=nektos/act-environments-ubuntu:18.04-lite platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test-matrix/job-matrix-1]   🐳  docker run image=nektos/act-environments-ubuntu:18.04-lite platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test-matrix/job-matrix-2]   🐳  docker run image=nektos/act-environments-ubuntu:18.04-lite platform= entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[test-matrix/job-matrix-1] 🧪  Matrix: map[env:DEV]
[test-matrix/job-matrix-2] 🧪  Matrix: map[env:STG]
[test-matrix/job-matrix-3] 🧪  Matrix: map[env:PRD]
[test-matrix/job-matrix-2] ⭐ Run Main echo ${{ matrix.env }}
[test-matrix/job-matrix-3] ⭐ Run Main echo ${{ matrix.env }}
[test-matrix/job-matrix-1] ⭐ Run Main echo ${{ matrix.env }}
[test-matrix/job-matrix-3]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/0] user= workdir=
[test-matrix/job-matrix-2]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/0] user= workdir=
[test-matrix/job-matrix-1]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/0] user= workdir=
| STG
| PRD
| DEV
[test-matrix/job-matrix-3]   ✅  Success - Main echo ${{ matrix.env }}
[test-matrix/job-matrix-2]   ✅  Success - Main echo ${{ matrix.env }}
[test-matrix/job-matrix-1]   ✅  Success - Main echo ${{ matrix.env }}
[test-matrix/job-matrix-1] ⭐ Run Main echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}
[test-matrix/job-matrix-2] ⭐ Run Main echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}
[test-matrix/job-matrix-3] ⭐ Run Main echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}
[test-matrix/job-matrix-1]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1] user= workdir=
[test-matrix/job-matrix-3]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1] user= workdir=
[test-matrix/job-matrix-2]   🐳  docker exec cmd=[bash --noprofile --norc -e -o pipefail /var/run/act/workflow/1] user= workdir=
| ***
| ***
| ***
[test-matrix/job-matrix-2]   ✅  Success - Main echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}
[test-matrix/job-matrix-1]   ✅  Success - Main echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}
[test-matrix/job-matrix-3]   ✅  Success - Main echo ${{ secrets[format('DB_USERPASSWORD_{0}', matrix.env)] }}
[test-matrix/job-matrix-2] 🏁  Job succeeded
[test-matrix/job-matrix-1] 🏁  Job succeeded
[test-matrix/job-matrix-3] 🏁  Job succeeded
 yuta   release/v220206  ~  vamdemic  githubactions-terraform-sample  
```


## 参考
https://dev.classmethod.jp/articles/github-actions-variable-indirection-reference/