terraform-docs / gh-actions

A Github action for generating Terraform module documentation using terraform-docs and gomplate
Apache License 2.0
156 stars 62 forks source link

feat: allow verified commits #110

Open exaucae opened 11 months ago

exaucae commented 11 months ago

fixes https://github.com/terraform-docs/gh-actions/issues/63 with the least amount of changes by leveraging -S option of git commit.

I use it like so (focus on last step):


name: Generate terraform docs
on:
  workflow_dispatch:
  pull_request:

jobs:
  generate-docs:
    permissions:
      contents: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.ref }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
      - name: get target modules
        run: |
          echo "TARGET_MODULES=$(ls -dm -- terraform/*/ | xargs)" >>${GITHUB_ENV}
      - name: Import GPG key
        id: import-gpg
        uses: crazy-max/ghaction-import-gpg@v4
        with:
          gpg_private_key: ${{ secrets.GT_BOT_GPG_PRIVATE_KEY }}
          passphrase: ${{ secrets.GT_BOT_GPG_PASSPHRASE }}
          git_user_signingkey: true
          git_commit_gpgsign: true
          git_config_global: true
      - name: Render terraform docs and push changes back to PR
        uses: terraform-docs/gh-actions@v1.0.0
        with:
          working-dir: ${{ env.TARGET_MODULES }}
          config-file: terraform/.terraform-docs.yml
          output-method: replace
          git-push: "true"
          git-commit-gpg-sign: "true"    #  <--------- gpg verification activated
          git-commit-message: "docs(terraform): autogenerate docs"
          git-push-user-email: ${{ steps.import-gpg.outputs.email }}
          git-push-user-name: ${{ steps.import-gpg.outputs.name }}