javascript - 如何将对象传递给 GitHub 操作中的矩阵?
问题描述
我有一个 JavaScript GitHub 操作,它输出一个简单的对象数组,如下所示:
[
{
prop1: val1a,
prop2: val2a,
prop3: val3a
},
{
prop1: val1b,
prop2: val2b,
prop3: val3b
}
]
在一项新工作中,我想读取这个数组,循环它,并在循环的每次迭代期间打印属性值。这是怎么做的,尤其是最后一部分?
使用下面的代码,我设法创建了一个新作业,并让它遍历数组中的每个元素。但是在每次迭代期间,如何访问每个元素的属性值?
提前致谢。
我的代码
我的动作.yml
name: GitHub Actions Demo
on: [push]
jobs:
job1:
outputs:
matrix: ${{ steps.hello.outputs.matrix }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: Test JS action # Run the JavaScript action to output an array of objects.
id: hello
uses: ghusername/myreponame@master
# Run the second job here, to read in the output of the previous job, set its value to a matrix, then iterate over that matrix.
job2:
needs: [job1]
runs-on: ubuntu-latest
strategy:
matrix: ${{fromJSON(needs.job1.outputs.matrix)}}
steps:
- run: echo "I want to outputted objects from job1 to print here"
myJavaScriptAction.js(位于 GitHub 上的 ghusername/myreponame@master
const core = require("@actions/core");
const myArr = [
{
prop1: 111,
prop2: 222,
prop3: 333
},
{
prop1: 444,
prop2: 555,
prop3: 666
}
]
/* Convert output array to valid JSON, then stringify it. This is required in order to pass it to the next GitHub action.*/
outputArr = {
include: myArr,
};
core.setOutput(
"matrix",
JSON.stringify(outputArr)
);
解决方案
推荐阅读
- angular - Angular 6 - 将值从出口传递到组件
- ios - 关键字“协议”作为函数参数
- excel - 在 VBA 脚本中使用 MSXML 提取网站数据
- python-2.6 - 在 Python 的打印命令中调用 Sys.argv
- pyomo - Pyomo游戏作家
- windows - 无法运行 MSBuild 命令获取 VCTargetsPath 的值
- typescript - 为什么 Storage 的索引 getter 返回 'any' 而不是 'string | null' 像 getItem
- ssas - 计算过滤成本
- javascript - Object.assign() 和对象数组
- maven - 如何从 Windows 10 CMD 中删除“mvn”