我正在使用 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();
任何人都可以建议这种已弃用的用法的替代方案是什么。
感谢@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`);