已弃用的 Github 操作 ::set-output name=key::javascript 中的值

问题描述 投票:0回答:1

我正在使用 Node.js 处理 GitHub Actions 工作流程,并且需要设置要在后续步骤中使用的输出值。我收到了该线路已弃用的警告。

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'

完整的node.js如下

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();

任何人都可以建议这种已弃用的用法的替代方案是什么。

node.js github github-actions workflow
1个回答
0
投票

感谢@Azeem。 对于任何寻求快速解决方案的人。

.js 文件将如下所示。

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`);
© www.soinside.com 2019 - 2024. All rights reserved.