The Gitea Actions workflows were incorrectly capturing the exit code from the terraform plan command. The command was using | tee to display the output while saving it to a file, but this caused the $? variable to capture the exit code of tee (which is always 0) instead of terraform plan. This meant:
In terraform-deploy.yml: The has_changes output was always false, preventing the apply job from running even when changes were detected
In terraform-pr.yml: The exitcode output was always 0, making it impossible to distinguish between no changes and changes detected
Solution
Modified both workflow files to:
Replace the pipe to tee with a direct redirect to file: > plan_output.txt 2>&1
Add a separate cat plan_output.txt command to display the output in the logs
This preserves Terraform's exit code (0 for no changes, 2 for changes detected, 1 for errors) so the workflows can properly determine if changes exist and proceed with deployment.
Testing
The changes maintain the same functionality:
Plan output is still captured to plan_output.txt for later use
Plan output is still displayed in the workflow logs via cat
The exit code is now correctly captured from the terraform plan command
## Problem
The Gitea Actions workflows were incorrectly capturing the exit code from the `terraform plan` command. The command was using `| tee` to display the output while saving it to a file, but this caused the `$?` variable to capture the exit code of `tee` (which is always 0) instead of `terraform plan`. This meant:
- In `terraform-deploy.yml`: The `has_changes` output was always `false`, preventing the `apply` job from running even when changes were detected
- In `terraform-pr.yml`: The `exitcode` output was always `0`, making it impossible to distinguish between no changes and changes detected
## Solution
Modified both workflow files to:
1. Replace the pipe to `tee` with a direct redirect to file: `> plan_output.txt 2>&1`
2. Add a separate `cat plan_output.txt` command to display the output in the logs
This preserves Terraform's exit code (0 for no changes, 2 for changes detected, 1 for errors) so the workflows can properly determine if changes exist and proceed with deployment.
## Testing
The changes maintain the same functionality:
- Plan output is still captured to `plan_output.txt` for later use
- Plan output is still displayed in the workflow logs via `cat`
- The exit code is now correctly captured from the `terraform plan` command
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
The Gitea Actions workflows were incorrectly capturing the exit code from the
terraform plancommand. The command was using| teeto display the output while saving it to a file, but this caused the$?variable to capture the exit code oftee(which is always 0) instead ofterraform plan. This meant:terraform-deploy.yml: Thehas_changesoutput was alwaysfalse, preventing theapplyjob from running even when changes were detectedterraform-pr.yml: Theexitcodeoutput was always0, making it impossible to distinguish between no changes and changes detectedSolution
Modified both workflow files to:
teewith a direct redirect to file:> plan_output.txt 2>&1cat plan_output.txtcommand to display the output in the logsThis preserves Terraform's exit code (0 for no changes, 2 for changes detected, 1 for errors) so the workflows can properly determine if changes exist and proceed with deployment.
Testing
The changes maintain the same functionality:
plan_output.txtfor later usecatterraform plancommandPull request closed