How to fix "set-output" when reading nvmrc from the GitHub Actions?

You may be getting the issue "The set-output command is deprecated and will be disabled soon. Please upgrade to using Environment Files." from your Github workflow.

Screenshot showing the 'set-output' issue from the Github workflows

Few months ago, I choose to update some of my Github workflows to read from my .nvmrc file instead of manually specifying my node version.

.github/workflows/production.yml
on: push

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Detect Node version
        run: echo ::set-output name=NODE_VERSION::$(cat .nvmrc)
        id: nvmrc

      - name: Use Node.js ${{ steps.nvmrc.outputs.NODE_VERSION }}
        uses: actions/setup-node@v3
        with:
          node-version: ${{ steps.nvmrc.outputs.NODE_VERSION }}

But since October 2022 and the runner version 2.298.2, Github shows a warning regarding a future depreciation of the set-output command.

After few trials, I figured out how to update using the $GITHUB_OUTPUT instead:

.github/workflows/update-production.yml
on: push

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Detect Node version
        run: echo "NODE_VERSION=$(cat .nvmrc)" >> $GITHUB_OUTPUT
        id: nvmrc
        # shell: bash (to be added if you use composite actions)

      - name: Use Node.js ${{ steps.nvmrc.outputs.NODE_VERSION }}
        uses: actions/setup-node@v3
        with:
          node-version: '${{ steps.nvmrc.outputs.NODE_VERSION }}'

And "voilà", the warning should have disappeared and you should see the number of the version right after Use Node.js XXXX in your workflow.

Webmentions

Tweet about this post and have it showing up here!

Comments

Don't hesitate to leave your comment! In case you don't have a Github account, you can always tweet about it!