Skip to content

Commit

Permalink
ci: add terraform format and docs generation
Browse files Browse the repository at this point in the history
  • Loading branch information
gmichels committed Dec 5, 2024
1 parent da97370 commit fef1d26
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Generate terraform docs

on:
pull_request:
types: ["opened", "synchronize"]

env:
GOPROXY: https://proxy.golang.org,direct
DEBIAN_FRONTEND: noninteractive
GO_VERSION: "1.23"

jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
- name: Format and generate docs
run: go generate ./...
- name: Check for changes
id: check_changes
run: |
if [[ -n "$(git diff --exit-code)" ]]; then
echo "Changes detected."
echo "::set-output name=has_changes::true"
else
echo "No changes detected."
echo "::set-output name=has_changes::false"
fi
- name: Commit and push Changes
if: steps.check_changes.outputs.has_changes == 'true'
run: |
# configure user
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
# stage any file changes to be committed
git add .
# make commit with staged changes
git commit -m 'Terraform format/docs changes'
# push the commit back up to source GitHub repository
git push
9 changes: 7 additions & 2 deletions tools/tools.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
//go:build tools
//go:build generate

package tools

import (
// Ensure documentation generator is not removed from go.mod.
_ "github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs"
)

// format terraform code for use in documentation
//go:generate terraform fmt -recursive ../examples/

// generate documentation
//go:generate go run github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs generate --provider-dir .. -provider-name adguard

0 comments on commit fef1d26

Please sign in to comment.