提取地形资源变化github-script@v5行动



我有一个github工作流,我想从地形图计划文件中过滤地形图销毁更改,并将其作为注释发布在PR中。

- name: Terraform Plan
id: plan_json
run: |
terraform plan -out planfile 2>error.log
terraform show -json planfile > plan.json
continue-on-error: true
- uses: actions/github-script@v5
id: message
if: ${{ always() }}
with:
result-encoding: string
script: |
const fs = require('fs');
const report = JSON.parse(fs.readFileSync('./plan.json'));
var message = '';
for (const changes in report.resource_changes) {
message += `${changes.change.actions[0]} ${changes.name} (${changes.type})n`
};
console.log('Message: ', message);
return message;

当我运行工作流时,它会出现以下错误:

SyntaxError: Unexpected token c in JSON at position 1
at JSON.parse (<anonymous>)
at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4942:56), <anonymous>:4:21)
at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4943:12)
Error: Unhandled error: SyntaxError: Unexpected token c in JSON at position 1
at main (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4997:26)
at Module.272 (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:4981:1)
at __webpack_require__ (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:24:31)
at startup (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:43:19)
at /home/runner/work/_actions/actions/github-script/v5/dist/index.js:49:18
at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v5/dist/index.js:52:10)
at Module._compile (internal/modules/cjs/loader.js:959:30)

我没有任何nodejs/javascript经验,所以我不知道我在这里做错了什么。

实际的计划文件可以在这里找到。

当我在本地运行nodejs脚本时,它就可以工作了。

❯ node tfplan.js
Message:  create, rg (azurerm_resource_group)
create, rg-name (random_pet)
- uses: hashicorp/setup-terraform@v1
with:
terraform_wrapper: false

terraform_wrapper:false必须添加到terraform设置任务中。有关更多信息,请查看此。

最新更新