Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FMT #37

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
55 changes: 55 additions & 0 deletions .github/workflows/pr_fmt.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# 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
else
echo "No formatting issues found."
fi

- name: Post PR review 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: 'REQUEST_CHANGES',
});
2 changes: 1 addition & 1 deletion .github/workflows/pr_lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:

jobs:
linting:
name: Format and Lint Checks
name: Terraform Lint Checks
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand Down
Loading