diff --git a/.github/workflows/terraform.yaml b/.github/workflows/terraform.yaml index 46b1f5ad..1b2f9ab4 100644 --- a/.github/workflows/terraform.yaml +++ b/.github/workflows/terraform.yaml @@ -17,7 +17,7 @@ permissions: id-token: write issues: write pull-requests: write - contents: read + contents: write jobs: pre-commit: @@ -50,16 +50,24 @@ jobs: cd components terraform fmt -recursive + - name: Check for changes + id: git-check + run: | + git diff --exit-code || echo "changes=true" >> $GITHUB_OUTPUT + + - name: Commit and push if changes + if: steps.git-check.outputs.changes == 'true' + run: | + git config --global user.name 'hmcts-platform-operations' + git config --global user.email 'github-platform-operations@HMCTS.NET' + git add . + git commit -m "Apply Terraform formatting changes" + git push + - name: Run Pre-commit uses: pre-commit/action@v3.0.0 with: extra_args: --files components/**/* - - - name: Auto Commit Changes - uses: stefanzweifel/git-auto-commit-action@v5 - with: - commit_message: "Apply Terraform formatting changes" - file_pattern: components/**/* terraform: runs-on: ubuntu-latest