[GitHub Actions] aws-actions/configure-aws-credentials@v1がdeprecatedとなっていたのでアップデート対応する

2022.11.24

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、CX事業本部 IoT事業部の若槻です。

今回は、GitHub Actionsでaws-actions/configure-aws-credentials@v1deprecatedとなっていたのでアップデート対応してみました。

先に結論

GitHub ActionsのWorkflowでaws-actions/configure-aws-credentials@v1を使用している場合は、@v1-node16を使用するようにします。

      - name: Assume Role
-         uses: aws-actions/configure-aws-credentials@v1
+         uses: aws-actions/configure-aws-credentials@v1-node16
        with:
          role-to-assume: ${{ env.AWS_OIDC_ROLE_ARN }}
          aws-region: ${{ env.AWS_REGION }}

aws-actions/configure-aws-credentialsはAWSが公式提供しているActionsで、AssumeRoleによるクレデンシャルの取得をシンプルに実装することができます。

事象、原因

GitHub ActionsのWorkflow実行でいつの間にかWarningが2つ出ていることに気が付きました。

Node.js 12 actions are deprecated. For more information see: https://github.blog/changelog/2022-09-22-github-actions-all-actions-will-begin-running-on-node16-instead-of-node12/. Please update the following actions to use Node.js 16: aws-actions/configure-aws-credentials@v1

The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

前者のWarningは、Node12でActionが実行されるaws-actions/configure-aws-credentials@v1はdeprecatedとなっているため、Node16を使うように促されています。記述中のURLによると、Node12は2022年4月以降は非サポートとなるため、GitHub Actionsでも2023年の夏を期限としてすべてのActionがNode16で実行されるようにするとのことです。よってNode12でActionが実行されているWorkflowでは2022/9/27以降Warningを出しているとのことです。

一方で後者のWarningは、記述中のURLによると、save-stateおよびset-outputを使用すると意図しないデータ収集が行われる可能性があるため、これらのコマンドを使用しているWorkflowでは2022/10/11以降Warningを出しているとのことです。

save-stateおよびset-outputに関しては、Workflowで次のように使用している場合は、

- name: Save state
  run: echo "::save-state name={name}::{value}"

- name: Set output
  run: echo "::set-output name={name}::{value}"

次のようにGITHUB_STATEおよびGITHUB_OUTPUTを使用するように修正すれば良いとのことです。

- name: Save state
  run: echo "{name}={value}" >> $GITHUB_STATE

- name: Set output
  run: echo "{name}={value}" >> $GITHUB_OUTPUT

アップデート対応

前者のWarningでaws-actions/configure-aws-credentials@v1をアップデートするようにあったので対応してみます。

ドキュメントを見ると、NOTICE: node12 deprecation warningという項目で、Warningを抑制するためにはaws-actions/configure-aws-credentials@v1-node16を使うように案内されていますね。

GitHub actions has recently started throwing warning messages regarding the deprecation of Node 12. If you would like to stop seeing this warning, configure your action to use aws-actions/configure-aws-credentials@v1-node16. Both the v1 branch and the v1-node16 branch will receive the same updates moving forward.

というわけでWorkflow fileを修正して使用するaws-actions/configure-aws-credentialsをアップデートします。

      - name: Assume Role
-         uses: aws-actions/configure-aws-credentials@v1
+         uses: aws-actions/configure-aws-credentials@v1-node16
        with:
          role-to-assume: ${{ env.AWS_OIDC_ROLE_ARN }}
          aws-region: ${{ env.AWS_REGION }}

するとWarningを抑制することができました。

引き続きWarningが出る場合

別のWorkflowでは、aws-actions/configure-aws-credentialsのアップデート後も、Node.js 12 actions are deprecated.のWarningが引き続き出ていました。Workflow内で使用しているjossef/action-set-json-field@v1というActionsで対応が必要なようです。

Node.js 12 actions deprecation warning on github - General Usage - Julia Programming Languageによると、actions/checkout@v2から@v3へアップデート対応していない場合にもNode.js 12 actions are deprecated.Warningが出るとのことです。

そしてjossef/action-set-json-fieldについては@2.1へアップデートすることにより、Actions内で実行されているactions/checkout@v3へアップデートできるとのことです。

この対応をしたらWarningを抑制することができました。

このように、今回のWarningを抑制するためには、aws-actions/configure-aws-credentials以外にもNode.js12set-outputを使用するすべてのActionsでアップデート対応をする必要があります。もしActions側が未対応の場合は、アップデート対応されるまで待つか、自身がコントリビュートするか、他のActionsへの乗り換えを検討するようにしましょう。

以上