From 8606bd256a455ff64a9254ba54a7f6d0b89a7b04 Mon Sep 17 00:00:00 2001 From: Dave Arnold Date: Fri, 21 Mar 2025 22:32:39 -0700 Subject: [PATCH] Enhance terraform-test workflow to conditionally push changes based on event type and repository origin; add .tflog to .gitignore --- .github/workflows/terraform-test.yml | 11 ++++++++++- .gitignore | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform-test.yml b/.github/workflows/terraform-test.yml index 150d655..d462958 100644 --- a/.github/workflows/terraform-test.yml +++ b/.github/workflows/terraform-test.yml @@ -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 diff --git a/.gitignore b/.gitignore index 2faf43d..4522103 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ override.tf.json # Ignore CLI configuration files .terraformrc terraform.rc +.tflog \ No newline at end of file