@@ -99,14 +99,35 @@ runs:
9999 else
100100 echo "tf_docs=false" >> "$GITHUB_OUTPUT"
101101 fi
102- - name : Render terraform docs inside the README.md and push changes back to PR branch
102+ - name : Render terraform docs inside the README.md
103103 if : ${{ steps.tf_docs.outputs.tf_docs == 'true' }}
104+ id : terraform_docs
104105 uses : terraform-docs/gh-actions@v1.3.0
105106 with :
106107 working-dir : ${{ inputs.package-name }}
107108 output-file : README.md
108- git-push : " true"
109109 config-file : .terraform-docs.yml
110+ - name : If documentation is updated, push to PR branch with a signed commit
111+ if : ${{ steps.terraform_docs.outputs.num_changed != '0' }}
112+ env :
113+ DESTINATION_BRANCH : ${{ github.event.pull_request.head.ref }}
114+ FILE_TO_COMMIT : ${{ inputs.package-name }}/README.md
115+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
116+ shell : bash
117+ run : |
118+ ### Signed commit workaround - if we do a normal `git commit` here, it will be unsigned
119+ # GHA doesn't have a good native way to sign commits (https://github.com/actions/runner/issues/667)
120+ # Commits submitted via the API do get signed, so do that instead - adapted from https://gist.github.com/swinton/03e84635b45c78353b1f71e41007fc7c
121+ export TODAY=$( date -u '+%Y-%m-%d' )
122+ export MESSAGE="chore(docs): ${FILE_TO_COMMIT}"
123+ export SHA=$( git rev-parse $DESTINATION_BRANCH:$FILE_TO_COMMIT )
124+ export CONTENT=$( base64 -i $FILE_TO_COMMIT )
125+ gh api --method PUT /repos/:owner/:repo/contents/$FILE_TO_COMMIT \
126+ --field message="$MESSAGE" \
127+ --field content="$CONTENT" \
128+ --field encoding="base64" \
129+ --field branch="$DESTINATION_BRANCH" \
130+ --field sha="$SHA"
110131 - name : Sparse checkout unmodified changelogs from main
111132 uses : actions/checkout@v4
112133 with :
0 commit comments