设置GitHub Actions输入值以进行本地测试

问题描述

我正在编写一个GitHub动作,该动作使用file库接收名为@actions/core的强制输入字段。

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;

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...