Skip to content

fix: improve move and remove count parsing in plan parser#32

Open
Laffs2k5 wants to merge 6 commits intomainfrom
breezy-llama
Open

fix: improve move and remove count parsing in plan parser#32
Laffs2k5 wants to merge 6 commits intomainfrom
breezy-llama

Conversation

@Laffs2k5
Copy link
Contributor

Summary

Fixes the parse-terraform-plan action failing to count removed resources, outputting ? instead of the correct count.

Changes

Fix remove count detection

The old code looked for the banner text "Some objects will no longer be managed by Terraform" which is absent in newer Terraform output formats. The new approach counts per-resource comment lines containing "will no longer be managed by Terraform" directly, which works across all Terraform versions.

Fix grep error handling

Replaced the || true pattern with set +e/set -e blocks and explicit exit code checks (grep -c exits 0 on match, 1 on no match, 2+ on error). This ensures ? is properly returned on unexpected errors instead of silently reporting 0.

Fix remove count detection: the old code looked for the banner text
"Some objects will no longer be managed by Terraform" which is absent
in newer Terraform output formats. Now counts per-resource comments
containing "will no longer be managed by Terraform" directly.

Fix grep error handling: replace '|| true' pattern with set +e/set -e
blocks and explicit exit code checks (0=match, 1=no match, 2+=error).
This ensures '?' is returned on unexpected errors instead of silently
reporting 0.
Copy link
Contributor

@Artlvns Artlvns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎖️

Add a clickable '🔗 Job Logs' link below the validation table in PR comments, pointing to the GitHub Actions job logs for the current run. Uses job.check_run_id to resolve the correct job URL per matrix combination without requiring API calls.
Extract inline bash from action.yml into step_parse_plan_output.sh following the action implementation guide conventions.

Fix grep operating on file content variable via echo which caused "Argument list too long" on large plan files. grep now operates directly on the plan file.

Use more specific pattern for removed resource counting ("# .* will no longer be managed by Terraform") to exclude summary warning lines that inflated the count.
Add test data files with plan output for various scenarios: no changes, adds/changes/destroys, moves, and removed resources.

Add run_all_tests.sh with 6 test cases covering all test data files plus edge cases (empty path, empty file).

Add run_local_step_parse_plan_output.sh for manual debugging.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants