270 文字
1 分

actions/setup-nodeでnode-version-fileの利用を勧める不純な理由

actions/setup-node で Node.js のバージョンを指定する#

node-versionまたはnode-version-fileを利用することで、利用される Node.js のバージョンを指定することが出来る。

node-version を利用する#

- uses: actions/setup-node@v4
with:
node-version: "20.x"

node-version-file を利用する#

package.json.nvmrc.node-versionなどのファイルを元にバージョンを決定させる。

- uses: actions/setup-node@v4
with:
node-version-file: "package.json"

node-version-file を利用する一般的なメリット#

node-version-fileを利用することで、Node.js のバージョンを一元管理することが出来る。 これによって環境毎に Node.js のバージョンがずれてしまうようなことがなくなる。

node-version-file を利用する不純な理由#

node-versionを利用した場合、PullRequest の Status に表示されるラベルが次のような形式になる。

build (18.x) (push)

これは、Node.js のバージョンを変更すると表記が変わる。

build (20.x) (push)

つまり、これをブランチプロテクションで必須にしている場合、Node.js バージョンを変更する度に変更が必要になる。

一方、node-version-fileの場合、次のようになるため変更する必要がなくなる。

build (push)
actions/setup-nodeでnode-version-fileの利用を勧める不純な理由
https://blog.ohirunewani.com/posts/github-actions---impure-reasons-to-proceed-with-node-version-file-in-setup-node/
作者
hrdtbs
公開日
2024-08-27
ライセンス
CC BY-NC-SA 4.0