为本地测试设置 GitHub 操作输入值
set GitHub Actions input value for local testing
我正在编写一个 GitHub 操作,它使用 @actions/core
库接收名为 file
的必填输入字段。
const core = require("@actions/core");
async function run() {
try {
let file = core.getInput('file', {required: true});
// rest of my action ...
我可以在本地 运行 它并且它按原样失败(未提供输入)。
是否有提供输入的内置方式(类似于 env-vars)以便我可以 运行 并在本地进行测试?
Error: Input required and not supplied: file
at Object.getInput (.../node_modules/@actions/core/lib/core.js:78:15)
at run (.../src/main.js:6:25)
at Object.<anonymous> (.../src/main.js:40:5)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
::error::Input required and not supplied: file
如果你查看the sources of getInput
,你可以看到它正在使用环境变量:
const val: string =
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
知道这些,你可以直接设置这个环境变量:
const setInput = (name,value)=>
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`]=value;
我正在编写一个 GitHub 操作,它使用 @actions/core
库接收名为 file
的必填输入字段。
const core = require("@actions/core");
async function run() {
try {
let file = core.getInput('file', {required: true});
// rest of my action ...
我可以在本地 运行 它并且它按原样失败(未提供输入)。 是否有提供输入的内置方式(类似于 env-vars)以便我可以 运行 并在本地进行测试?
Error: Input required and not supplied: file
at Object.getInput (.../node_modules/@actions/core/lib/core.js:78:15)
at run (.../src/main.js:6:25)
at Object.<anonymous> (.../src/main.js:40:5)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
::error::Input required and not supplied: file
如果你查看the sources of getInput
,你可以看到它正在使用环境变量:
const val: string =
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
知道这些,你可以直接设置这个环境变量:
const setInput = (name,value)=>
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`]=value;