FMT #14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright (c) Microsoft Corporation | |
# Licensed under the MIT License. | |
# | |
name: PR Fmt | |
on: | |
pull_request: | |
types: [opened, synchronize, reopened] | |
env: | |
TF_VERSION: "1.8.4" | |
jobs: | |
fmt_check: | |
name: Terraform formatting Checks | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: latest | |
- name: Check Terraform formatting | |
id: fmt | |
run: | | |
FMT_OUTPUT=$(terraform fmt -check -recursive) | |
echo "fmt_output=${FMT_OUTPUT}" >> $GITHUB_OUTPUT | |
if [ -n "$FMT_OUTPUT" ]; then | |
echo "Formatting issues found in the following files:" | |
echo "$FMT_OUTPUT" | |
exit 1 | |
fi | |
- name: Post PR comment on fmt failure | |
if: failure() && steps.fmt.outcome == 'failure' | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const fmtOutput = "${{ steps.fmt.outputs.fmt_output }}"; | |
const body = `Please run \`terraform fmt\` to format your Terraform files. The following files need formatting:\n\`\`\`\n${fmtOutput}\n\`\`\``; | |
github.rest.pulls.createReview({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number, | |
body: body, | |
event: 'COMMENT', | |
}); |