Search code examples
node.jsgithubgithub-actionsworkflow

Deprecated Github Action ::set-output name=key::value in javascript


I'm working on a GitHub Actions workflow using Node.js, and I need to set an output value to be used in subsequent steps. I am getting deprecated warning for for the line.

process.stdout.write(`::set-output name=my-key::'${value}'`);

Action.yml:

name: Test New Output
description: 'Task to test new output'



runs:
  using: 'node16'
  main: 'test-output.js'

Full node.js is below

const fs = require('fs');


async function run() {
  try {
    // Calculate the value for 'blocks'
    const blocks = "some value";
    process.stdout.write(`::set-output name=my-key::'${blocks}'`);
  } catch (error) {
    console.error(error);
    process.exit(1);
  }
}

run();

Can anybody suggest what is the alternative for this deprecated usage.


Solution

  • Thanks to @Azeem. For anyone looking for a quick solution.

    The .js file will look like this.

    const { exec } = require('child_process');
    
    const outputValue = 'Your output value'; // Replace this with your actual output value
    
    exec(`echo "MY_OUTPUT_NAME=${outputValue}" >> $GITHUB_OUTPUT`);