Skip to content

Commit 22f2221

Browse files
fix: only render readme if tf-docs.yml is present; move tf-docs step (#243)
* fix: only render readme if tf-docs.yml is present; move tf-docs step to after checkout * update readme
1 parent 0a80f40 commit 22f2221

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

.github/actions/action.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ outputs:
2020
runs:
2121
using: "composite"
2222
steps:
23-
- name: Render terraform docs inside the README.md and push changes back to PR branch
24-
uses: terraform-docs/[email protected]
25-
with:
26-
working-dir: ${{ inputs.package-name }}
27-
output-file: README.md
28-
git-push: "true"
29-
config-file: .terraform-docs.yml
3023
- name: Checkout all tags
3124
uses: actions/checkout@v4
3225
with:
@@ -94,6 +87,26 @@ runs:
9487
with:
9588
ref: ${{ github.event.pull_request.head.ref }}
9689
repository: ${{ github.event.pull_request.head.repo.full_name }}
90+
- name: Check for terraform-docs.yml
91+
id: tf_docs
92+
shell: bash
93+
env:
94+
PACKAGE_NAME: ${{ inputs.package-name }}
95+
run: |
96+
TF_DOCS_PATH="$PACKAGE_NAME/.terraform-docs.yml"
97+
if [ -f $TF_DOCS_PATH ] ; then
98+
echo "tf_docs=true" >> "$GITHUB_OUTPUT"
99+
else
100+
echo "tf_docs=false" >> "$GITHUB_OUTPUT"
101+
fi
102+
- name: Render terraform docs inside the README.md and push changes back to PR branch
103+
if: ${{ steps.tf_docs.outputs.tf_docs == 'true' }}
104+
uses: terraform-docs/[email protected]
105+
with:
106+
working-dir: ${{ inputs.package-name }}
107+
output-file: README.md
108+
git-push: "true"
109+
config-file: .terraform-docs.yml
97110
- name: Sparse checkout unmodified changelogs from main
98111
uses: actions/checkout@v4
99112
with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ If you want to ensure specific people or teams have to review changes to certain
5151

5252
### Documentation
5353

54-
A `README.md` is required for each module, and CI will automatically regenerate it using the [tf-docs github action](https://github.com/terraform-docs/gh-actions).
54+
A `README.md` is required for each module, and CI will automatically regenerate it using the [tf-docs github action](https://github.com/terraform-docs/gh-actions) if your module has a `.terraform-docs.yml`.
5555
To include non-generated content in your README, place it outside the `<!-- BEGIN_TF_DOCS -->` block.
5656

5757
## Using these modules

0 commit comments

Comments
 (0)