Skip to content

Commit

Permalink
Enhance terraform-test workflow to conditionally push changes based o…
Browse files Browse the repository at this point in the history
…n event type and repository origin; add .tflog to .gitignore
  • Loading branch information
Dave Arnold committed Mar 22, 2025
1 parent 04c037c commit 8606bd2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion .github/workflows/terraform-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ jobs:
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add .
git commit -m "chore: format terraform files"
git push origin "HEAD:${{ github.event.pull_request.head.ref }}"
# Only push directly if we're on the main branch
if [[ "${{ github.event_name }}" == "push" ]]; then
git push
elif [[ "${{ github.event.pull_request.head.repo.fork }}" == "false" ]]; then
# Only push to the PR branch if it's from the same repository (not a fork)
git push origin "HEAD:${{ github.event.pull_request.head.ref }}"
else
echo "Changes detected but not pushing to a fork PR. Please update your PR with these formatting changes."
fi
- name: Terraform Init
id: init
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ override.tf.json
# Ignore CLI configuration files
.terraformrc
terraform.rc
.tflog

0 comments on commit 8606bd2

Please sign in to comment.