Github Actionsでsetup-nodeを使用する際に、プロジェクトに含まれているファイルに記載のバージョンを利用できたのでメモ
node-version-fileの設定を使うとできる。
ファイルパスは .github ディレクトリが置かれている場所をルートとしてパスを設定する

# 使用しない場合
- name: Install Node.js
  uses: actions/setup-node@v3
  with:
    node-version: '22.x'

# node-version-fileを使用する場合
- name: Install Node.js
  uses: actions/setup-node@v3
  with:
    node-version-file: ./.node-version

./.node-versionには、CIで使用するNode.jsのバージョンを記載する

22.6.0

また、setup-nodeがバージョン3.5以上だと、package.jsonengines.nodeに記載されているバージョンを使うこともできる

{
  "engines": {
    "node": "22.x"
  }
}
- name: Install Node.js
  uses: actions/setup-node@v3
  with:
    node-version-file: ./package.json