javascript - 为本地测试设置 GitHub Actions 输入值
问题描述
我正在编写一个 GitHub 操作,它接收一个名为file
using @actions/core
library 的强制输入字段。
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
解决方案
如果您查看的来源getInput
,您可以看到它正在使用环境变量:
const val: string =
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''
知道了这一点,你可以设置这个环境变量:
const setInput = (name,value)=>
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`]=value;
推荐阅读
- express - 应用在线时向 API 发送请求
- gradle - 带有多项目构建的 Nebula Gradlint 使用 spring 依赖管理插件报告太多
- apache-pig - 如何加载 Pig 关系中的数据?
- linux - 在 Linux / Unix 中,有没有办法列出出现在特定文件夹路径下的每个组所有权?
- java - 如何在基于 Spring Boot (tomcat) 的应用程序中记录可用/使用的线程数?
- django - 如何将 `{'c_like': '99', 'count': 1}` 转换为颜色喜欢按钮并计算 Django 中的喜欢
- javascript - 侧板上的汉堡菜单
- excel - 在 VBA 中,我从文件中读取了一个 excel 公式并尝试将其粘贴到单元格中。但它失败了(没有写任何东西)
- c++ - 将 std::stringstream 的回合行为与 boost::spirit::karma::real_generator 匹配
- rotation - 将欧拉角转换为球角