Skip to content

Commit

Permalink
Correctly collapse long outputs
Browse files Browse the repository at this point in the history
Adds tests for very long outputs
  • Loading branch information
dflook committed Dec 7, 2023
1 parent 98582c7 commit 4e66479
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 5 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test-apply.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1173,3 +1173,22 @@ jobs:
uses: ./terraform-apply
with:
path: tests/workflows/test-apply/long_outputs

outputs:
runs-on: ubuntu-latest
name: Apply a plan with outputs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Plan
uses: ./terraform-plan
with:
path: tests/workflows/test-apply/outputs

- name: Apply
uses: ./terraform-apply
with:
path: tests/workflows/test-apply/outputs
6 changes: 3 additions & 3 deletions image/src/github_pr_comment/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,13 @@ def format_plan_text(plan_text: str) -> Tuple[str, str]:

def format_output_status(outputs: Optional[dict], remaining_size: int) -> str:
status = f':white_check_mark: Plan applied in {job_markdown_ref()}'
if outputs is not None:
stripped_output = render_outputs(outputs).strip()
stripped_output = render_outputs(outputs).strip()

if stripped_output:
if len(stripped_output) > remaining_size:
stripped_output = truncate(stripped_output, remaining_size, 'Outputs are too large to fit in a PR comment. See the full outputs in the workflow log.')

open_att = ' open' if len(stripped_output.splitlines()) > 6 else ''
open_att = ' open' if len(stripped_output.splitlines()) < 6 else ''

status += f'''\n<details{open_att}><summary>Outputs</summary>
Expand Down
4 changes: 2 additions & 2 deletions tests/workflows/test-apply/long_outputs/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
variable "input" {
type = string
default = "This is my long string\n"
default = "This is my long string"
}

output "output" {
value = repeat(var.input, 5000)
value = join('\n', [for i in range(0, 5000): var.input])
}
26 changes: 26 additions & 0 deletions tests/workflows/test-apply/outputs/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
output "sensitive" {
value = "This is a sensistive value"
sensitive = true
}

output "not_sensitive" {
value = "This is not a sensistive value"
}

output "sensitive_map" {
value = {
"password" = "passw0rd"
}
sensitive = true
}

output "not_sensitive_complex" {
value = [
{
"hello" = "world"
},
{
"hello" = "again"
}
]
}

0 comments on commit 4e66479

Please sign in to comment.