GitHub Actionsで特定のコマンドをリトライするだけのAction

仕事でも利用している個人で作った特定のコマンドをリトライするだけのGitHub Actionを公開しました。
似たようなActionは既にMarketplaceにあるのですが、大体がそのコマンドの出力結果を取得できないため、自前でActionを書くにいたりました。

github.com

github.com

使い方としてはシンプルでして例えばterraform planであれば、

- uses: corrupt952/retry-command@v1
  with:
    command: terraform plan -no-color
    max_attempts: 3
    retry_interval: 10

のようにすれば、リトライ間隔10秒で最大で3回実行してくれます。(リトライは2回)

実態はまだシェルスクリプトということもあり、$((RANDOM % 31)) とように書くだけで指定の範囲内でランダムにスリープしてくれます。

- uses: corrupt952/retry-command@v1
  with:
    command: terraform plan -no-color
    retry_interval: $((RANDOM % 31))

そして元々個人的に必要だったのはコマンドの実行結果で以下のように取得することができます。

- uses: corrupt952/retry-command@v1
  id: terraform_plan
  continue-on-error: true
  with:
    command: terraform plan -no-color
    max_attempts: 3
- if: steps.terraform_plan.outcome == 'failure'
  run: |
    echo "Exit code: ${{ steps.terraform_plan.outputs.exit_code }}"
    echo "Result: ${{ steps.terraform_plan.outputs.result }}

取得できるのは、現状最後に成功・失敗した時の結果になります。 もし似たようなことをしたい時は使ってみてください。