我正在關注關于如何設定 GitHub Actions 和 terraform 的 hashcopr 學習指南。除了使用 Terraform 計劃更新 PR 的步驟之外,一切都運行良好。
我遇到以下錯誤:
An error occurred trying to start process '/home/runner/runners/2.287.1/externals/node12/bin/node' with working directory '/home/runner/work/ccoe-aws-ou-scp-manage/ccoe-aws-ou-scp-manage'. Argument list too long
我正在使用的代碼是:
- uses: actions/github-script@0.9.0
if: github.event_name == 'pull_request'
env:
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Format and Style ??\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ??\`${{ steps.init.outcome }}\`
#### Terraform Plan ??\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`${process.env.PLAN}\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`*`;
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
來自檔案的清晰復制/粘貼:https ://learn.hashicorp.com/tutorials/terraform/github-actions
我已經嘗試過操作/github-script 版本 5 和 6,但仍然是同樣的問題,但是當我復制粘貼時,計劃一切都很好。如果我不使用輸出變數并為正文使用一些占位符文本,那么一切都很好。如果我只列印它,我可以看到 step.plan.outputs.stdout 是好的。
如果需要,我很樂意分享更多細節。
uj5u.com熱心網友回復:
我也遇到了類似的問題。我似乎github-script無法為太長的腳本爭論。
參考:
- https://github.com/robburger/terraform-pr-commenter/issues/6#issuecomment-826966670
- https://github.community/t/maximum-length-for-the-comment-body-in-issues-and-pr/148867
我的答案:
- 截斷計劃結果
- 洗掉不必要的行
- name: truncate terraform plan result
run: |
plan=$(cat <<'EOF'
${{ format('{0}{1}', steps.plan.outputs.stdout, steps.plan.outputs.stderr) }}
EOF
)
echo "PLAN<<EOF" >> $GITHUB_ENV
echo "${plan: -60000}" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: create comment from plan result
uses: actions/github-script@0.9.0
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let output = `#### Terraform Initialization ??\`${{ steps.init.outcome }}\`
#### Terraform Plan ??\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${{ env.PLAN }}
\`\`\`
</details>
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ inputs.TF_WORK_DIR }}\`, Workflow: \`${{ github.workflow }}\`*`;
output = output.replace(/^(.*Refreshing state). $\n/gm, '')
// console.log(output)
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/438164.html
