mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-25 12:47:06 +00:00
Update example to truncate long plans
This commit is contained in:
parent
c23d9fb1b7
commit
2b4d59a15c
1 changed files with 24 additions and 8 deletions
32
README.md
32
README.md
|
|
@ -108,16 +108,23 @@ steps:
|
||||||
|
|
||||||
- name: Terraform Plan
|
- name: Terraform Plan
|
||||||
id: plan
|
id: plan
|
||||||
run: terraform plan -no-color
|
run: |
|
||||||
|
terraform plan -no-color > plan.out
|
||||||
|
cat plan.out
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v7
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
env:
|
|
||||||
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const data = fs.readFileSync('terraform/plan.out', 'utf8');
|
||||||
|
const plan = "terraform\n" + data.length > 65000 ? `${data.substring(data.length - 65000)}...` : data
|
||||||
|
let truncated = '';
|
||||||
|
if (data.length > 65000) {
|
||||||
|
truncated = 'plan was truncated, view the <a href="${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }}">job log</a> for the full plan';
|
||||||
|
}
|
||||||
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
|
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
|
||||||
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
|
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
|
||||||
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
|
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
|
||||||
|
|
@ -134,10 +141,11 @@ steps:
|
||||||
<details><summary>Show Plan</summary>
|
<details><summary>Show Plan</summary>
|
||||||
|
|
||||||
\`\`\`\n
|
\`\`\`\n
|
||||||
${process.env.PLAN}
|
${plan}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
${truncated}
|
||||||
|
|
||||||
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
|
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
|
||||||
|
|
||||||
|
|
@ -176,16 +184,23 @@ steps:
|
||||||
|
|
||||||
- name: Terraform Plan
|
- name: Terraform Plan
|
||||||
id: plan
|
id: plan
|
||||||
run: terraform plan -no-color
|
run: |
|
||||||
|
terraform plan -no-color > plan.out
|
||||||
|
cat plan.out
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
|
||||||
- uses: actions/github-script@v7
|
- uses: actions/github-script@v7
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
env:
|
|
||||||
PLAN: "terraform\n${{ steps.plan.outputs.stdout }}"
|
|
||||||
with:
|
with:
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
script: |
|
script: |
|
||||||
|
const fs = require('node:fs');
|
||||||
|
const data = fs.readFileSync('terraform/plan.out', 'utf8');
|
||||||
|
const plan = "terraform\n" + data.length > 65000 ? `${data.substring(data.length - 65000)}...` : data
|
||||||
|
let truncated = '';
|
||||||
|
if (data.length > 65000) {
|
||||||
|
truncated = 'plan was truncated, view the <a href="${{ github.server_url}}/${{ github.repository }}/actions/runs/${{ github.run_id }}">job log</a> for the full plan';
|
||||||
|
}
|
||||||
// 1. Retrieve existing bot comments for the PR
|
// 1. Retrieve existing bot comments for the PR
|
||||||
const { data: comments } = await github.rest.issues.listComments({
|
const { data: comments } = await github.rest.issues.listComments({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
|
|
@ -213,10 +228,11 @@ steps:
|
||||||
<details><summary>Show Plan</summary>
|
<details><summary>Show Plan</summary>
|
||||||
|
|
||||||
\`\`\`\n
|
\`\`\`\n
|
||||||
${process.env.PLAN}
|
${plan}
|
||||||
\`\`\`
|
\`\`\`
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
${truncated}
|
||||||
|
|
||||||
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
|
*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Working Directory: \`${{ env.tf_actions_working_dir }}\`, Workflow: \`${{ github.workflow }}\`*`;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue