From ff3253b248b67fbc711023e9f031df04a3c87179 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Wed, 9 Oct 2024 20:45:09 +0200 Subject: [PATCH 01/17] Added labels to PR on commit --- .github/workflows/release.yml | 2 +- action.yml | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7013360..a003071 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,5 +10,5 @@ permissions: jobs: github-action: - uses: cloudposse/.github/.github/workflows/shared-release-branches.yml@main + uses: cloudposse-github-actions/.github/.github/workflows/shared-release-branches.yml@main secrets: inherit diff --git a/action.yml b/action.yml index 5484042..3854849 100644 --- a/action.yml +++ b/action.yml @@ -85,7 +85,7 @@ inputs: description: "The title to use when creating a Pull Request (when commit_method: pr)" pr_labels: - description: "Whitespace-separated list of labels to apply to Pull Requests (when commit_method: pr)" + description: "Whitespace-separated list of labels to apply to Pull Requests (when commit_method: pr or ( commit_method: commit and github context is a PR) )" required: false default: | auto-update @@ -246,6 +246,18 @@ runs: file_pattern: '${{ steps.banner.outputs.file }} ${{ steps.readme.outputs.file }}' push_options: '${{ inputs.commit_push_options }}' + - uses: actions/github-script@v7 + if: ${{ inputs.commit_method == 'commit' && github.context.event_name == 'pull_request' }} + with: + script: | + labels = '${{ inputs.pr_labels }}'.split(' ') + await github.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: labels + }) + - name: Add Image to Step Summary if: steps.auto-commit.outputs.changes_detected == 'true' && inputs.banner_enabled == 'true' && inputs.commit_method == 'commit' shell: bash From 35efeee822a54245c80816c63770bef5acc5dce8 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Wed, 9 Oct 2024 22:18:41 +0300 Subject: [PATCH 02/17] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 3854849..5de3d9e 100644 --- a/action.yml +++ b/action.yml @@ -247,7 +247,7 @@ runs: push_options: '${{ inputs.commit_push_options }}' - uses: actions/github-script@v7 - if: ${{ inputs.commit_method == 'commit' && github.context.event_name == 'pull_request' }} + if: inputs.readme_enabled == 'true' && inputs.commit_method == 'commit' && github.event_name == 'pull_request' with: script: | labels = '${{ inputs.pr_labels }}'.split(' ') From c96a27ecae62a4b1b37d416b47761a479ceef337 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Wed, 9 Oct 2024 21:31:35 +0200 Subject: [PATCH 03/17] Added labels to PR on commit --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5de3d9e..7c85fad 100644 --- a/action.yml +++ b/action.yml @@ -251,7 +251,7 @@ runs: with: script: | labels = '${{ inputs.pr_labels }}'.split(' ') - await github.issues.addLabels({ + await github.rest.issues.addLabels({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, From 0d1475a4111332d37b969580889c371b00212a04 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Wed, 9 Oct 2024 23:43:19 +0200 Subject: [PATCH 04/17] Added labels to PR on commit --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7c85fad..2b38bab 100644 --- a/action.yml +++ b/action.yml @@ -247,7 +247,7 @@ runs: push_options: '${{ inputs.commit_push_options }}' - uses: actions/github-script@v7 - if: inputs.readme_enabled == 'true' && inputs.commit_method == 'commit' && github.event_name == 'pull_request' + if: steps.auto-commit.outputs.changes_detected == 'true' && inputs.commit_method == 'commit' && github.event_name == 'pull_request' with: script: | labels = '${{ inputs.pr_labels }}'.split(' ') From 3dcf0c69618c520fbee11ece1d1e88b188a9963c Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Tue, 15 Oct 2024 16:56:46 +0300 Subject: [PATCH 05/17] Update action.yml --- action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/action.yml b/action.yml index 2b38bab..aa7b8b8 100644 --- a/action.yml +++ b/action.yml @@ -99,6 +99,9 @@ outputs: readme_file: description: "Generated README file path (if readme_enabled: true)" value: "${{ steps.readme.outputs.file }}" + changes_detected: + description: "Changes detected" + value: "${{ steps.auto-commit.outputs.changes_detected }}" runs: using: "composite" From 62d829f5b9f44c0f6402058431b43fd9959ca4a3 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Tue, 15 Oct 2024 19:25:21 +0300 Subject: [PATCH 06/17] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index aa7b8b8..b43cf30 100644 --- a/action.yml +++ b/action.yml @@ -101,7 +101,7 @@ outputs: value: "${{ steps.readme.outputs.file }}" changes_detected: description: "Changes detected" - value: "${{ steps.auto-commit.outputs.changes_detected }}" + value: "${{ steps.auto-commit.outputs.changes_detected || steps.auto-pr.outputs.pull-request-number != false }}" runs: using: "composite" From 68cba60312ba509341afce81f6939472a2382dc3 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Thu, 31 Oct 2024 22:00:54 +0100 Subject: [PATCH 07/17] Added submodules support --- action.yml | 22 ++++ templates/terraform-docs.yml | 225 +++++++++++++++++++++++++++++++++++ 2 files changed, 247 insertions(+) create mode 100644 templates/terraform-docs.yml diff --git a/action.yml b/action.yml index b43cf30..693d2ca 100644 --- a/action.yml +++ b/action.yml @@ -228,6 +228,28 @@ runs: fi echo "file=README.md" >> $GITHUB_OUTPUT + - id: rebuild-submodules + if: inputs.readme_enabled == 'true' + shell: bash + run: | + dirs=$(find . -type d \( -name '.terraform*' -o -name 'obsolete*' \) -prune -o \ + -name '*.tf' \ + -not -path '*/.terraform/*' \ + -exec dirname {} \; \ + | sort \ + | uniq ) + + for item in "${dirs[@]}"; do + current_dir=$(pwd) + cd $item + + if [[ -f README.md ]]; then + terraform-docs markdown ./ --config ${GITHUB_ACTION_PATH}/templates/terraform-docs.yml + fi + + cd $current_dir + done + - uses: gaurav-nelson/github-action-markdown-link-check@v1 if: inputs.readme_enabled == 'true' && inputs.validate_readme == 'true' with: diff --git a/templates/terraform-docs.yml b/templates/terraform-docs.yml new file mode 100644 index 0000000..12666e7 --- /dev/null +++ b/templates/terraform-docs.yml @@ -0,0 +1,225 @@ +# https://pkg.go.dev/github.com/terraform-docs/terraform-docs/terraform#Module +content: |- + {{- $context_variables := list "context" "enabled" "namespace" "tenant" "environment" "stage" "name" "delimiter" "attributes" "tags" "additional_tag_map" "label_order" "regex_replace_chars" "id_length_limit" "label_key_case" "label_value_case" "descriptor_formats" "labels_as_tags" -}} + + {{ .Header }} + + ## Variables + + ### Required Variables + +
+ {{- range .Module.Inputs }} + {{- if and (not (has .Name $context_variables)) .Required }} +
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} required{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
+ {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} + {{- range $lines }} + {{ . }}
+ {{- end }} + + {{ if gt (len (split "\n" (tostring .Type))) 2 }} + **Type:** + ```hcl + {{ .Type.Raw }} + ``` +
+ {{ end }} + +
+ {{- end }} + {{- end }} +
+ + {{ $optional := false -}} + {{ range .Module.Inputs }}{{ if not .Required }}{{ $optional = true -}}{{ end -}}{{ end -}} + + {{ if $optional -}} + + ### Optional Variables + +
+ {{- range .Module.Inputs }} + {{- if and (not (has .Name $context_variables)) (not .Required) }} +
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} optional{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
+ {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} + {{- range $lines }} + {{ . }}
+ {{- end }} +
+ {{ if gt (len (split "\n" (tostring .Type))) 2 }} + **Type:** + ```hcl + {{ tostring .Type }} + ``` +
+ {{ end }} + **Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue | replace "{}" "{ }" | replace "[]" "[ ]" }}`{{ else }} + ```hcl + {{- $lines := regexSplit "\n" .GetValue -1 -}} + {{- range $lines }} + {{ . }} + {{- end }} + ``` + {{ end }} +
+ {{- end -}} + {{ end -}} +
+ {{ end }} + + ### Context Variables + +
+ + The following variables are defined in the `context.tf` file of this module and part of the [terraform-null-label](https://registry.terraform.io/modules/cloudposse/label/null) pattern. + + +
+ {{- range .Module.Inputs }} + {{- if and (has .Name $context_variables) }} +
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} {{ ternary .Required "required" "optional" }}{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
+ {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} + {{- range $lines }} + {{ . }}
+ {{- end }} + **Required:** {{ ternary .Required "Yes" "No" }}
+ {{ if gt (len (split "\n" (tostring .Type))) 2 }} + **Type:** + ```hcl + {{ .Type.Raw }} + ``` +
+ {{ end }} + **Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue | replace "{}" "{ }" | replace "[]" "[ ]" }}`{{ else }} + ```hcl + {{- $lines := regexSplit "\n" .GetValue -1 -}} + {{- range $lines }} + {{ . }} + {{- end }} + ``` + {{ end }} +
+ {{- end }} + {{- end }} +
+
+ + {{ if ne (len .Module.Outputs) 0 -}} + ## Outputs + +
+ {{- range .Module.Outputs }} +
`{{ .Name }}`{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
+
+ {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "" | default "n/a" ) -1 -}} + {{- range $lines }} + {{ . }}
+ {{- end }} +
+ {{- end }} +
+ {{- end }} + + ## Dependencies + + {{ if ne (len .Module.Requirements) 0 -}} + ### Requirements + {{ range .Module.Requirements }} + - `{{ .Name }}`{{ if .Version }}, version: `{{ .Version }}`{{ end }} + {{- end }} + {{- end }} + + {{ if ne (len .Module.Providers) 0 -}} + ### Providers + {{ range .Module.Providers }} + - `{{ .Name }}`{{ if .Version }}, version: `{{ .Version }}`{{ end }} + {{- end }} + {{- end }} + + {{ if ne (len .Module.ModuleCalls) 0 -}} + ### Modules + + Name | Version | Source | Description + --- | --- | --- | --- + {{ range .Module.ModuleCalls }} + {{- $baseUrl := "https://registry.terraform.io/modules" -}} + {{ if contains "//" .Source -}} + {{- $moduleParts := regexSplit "//" .Source 2 -}} + {{- $moduleName := first $moduleParts -}} + {{- $submodulePath := last $moduleParts -}} + `{{ .Name }}` | {{ .Version | default "latest" }} | {{ printf "[`%s`](%s/%s/%s/%s)" .Source $baseUrl $moduleName $submodulePath .Version }} | {{ tostring .Description | default "n/a" }} + {{ else -}} + `{{ .Name }}` | {{ .Version | default "latest" }} | {{ printf "[`%s`](%s/%s/%s)" .Source $baseUrl .Source .Version }} | {{ tostring .Description | default "n/a" }} + {{ end }} + {{- end -}} + {{- end -}} + + {{- if ne (len .Module.Resources) 0 }} + + ## Resources + + The following resources are used by this module: + {{ range .Module.Resources }} + {{- $isResource := and $.Config.Sections.Resources ( eq "resource" (printf "%s" .GetMode)) }} + {{- if $isResource }} + {{- $fullspec := ternary .URL (printf "[`%s`](%s)" .Spec .URL) .Spec }} + - {{ $fullspec }} {{ printf "(%s)" .GetMode -}} + {{- end }} + {{- end }} + + ## Data Sources + + The following data sources are used by this module: + {{ range .Module.Resources }} + {{- $isDataResource := and $.Config.Sections.DataSources ( eq "data source" (printf "%s" .GetMode)) }} + {{- if $isDataResource }} + {{- $fullspec := ternary .URL (printf "[`%s`](%s)" .Spec .URL) .Spec }} + - {{ $fullspec }} {{ printf "(%s)" .GetMode -}} + {{- end }} + {{- end }} + {{- end }} + +formatter: "markdown document" # this is required +version: "" + +recursive: + enabled: false + path: modules + +sections: + hide: [] + show: [] + +sort: + enabled: true + by: required + +output-values: + enabled: false + from: '' + +output: + file: README.md + mode: inject + template: |- + + {{ .Content }} + + +settings: + anchor: true + color: true + default: true + description: true + escape: true + hide-empty: false + html: true + indent: 2 + lockfile: false + read-comments: true + required: true + sensitive: true + type: true \ No newline at end of file From 5d3e906c2976e3638d4a7502503d6322e00b849b Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Thu, 31 Oct 2024 22:05:08 +0100 Subject: [PATCH 08/17] Added submodules support --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 693d2ca..8cb4a78 100644 --- a/action.yml +++ b/action.yml @@ -241,6 +241,7 @@ runs: for item in "${dirs[@]}"; do current_dir=$(pwd) + echo "${item}" cd $item if [[ -f README.md ]]; then From 9f4cde97da986e5f53a53902b5db8027a966fa74 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Thu, 31 Oct 2024 22:08:28 +0100 Subject: [PATCH 09/17] Added submodules support --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 8cb4a78..8046ec5 100644 --- a/action.yml +++ b/action.yml @@ -232,12 +232,12 @@ runs: if: inputs.readme_enabled == 'true' shell: bash run: | - dirs=$(find . -type d \( -name '.terraform*' -o -name 'obsolete*' \) -prune -o \ + dirs=($(find . -type d \( -name '.terraform*' -o -name 'obsolete*' \) -prune -o \ -name '*.tf' \ -not -path '*/.terraform/*' \ -exec dirname {} \; \ | sort \ - | uniq ) + | uniq )) for item in "${dirs[@]}"; do current_dir=$(pwd) From 4422274565f183bd478384ed503e802abe2a8f63 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Thu, 31 Oct 2024 22:17:12 +0100 Subject: [PATCH 10/17] Added submodules support --- action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 8046ec5..3c9d6b9 100644 --- a/action.yml +++ b/action.yml @@ -228,6 +228,13 @@ runs: fi echo "file=README.md" >> $GITHUB_OUTPUT + - name: "Install terraform-docs" + uses: jaxxstorm/action-install-gh-release@v1.12.0 + with: + repo: terraform-docs/terraform-docs + tag: v0.19.0 + cache: enable + - id: rebuild-submodules if: inputs.readme_enabled == 'true' shell: bash From 23931964a77333dd4819157435b3668edbf7470a Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Thu, 31 Oct 2024 23:47:08 +0100 Subject: [PATCH 11/17] Added submodules support --- action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/action.yml b/action.yml index 3c9d6b9..ad805fc 100644 --- a/action.yml +++ b/action.yml @@ -317,6 +317,7 @@ runs: add-paths: | ${{ steps.banner.outputs.file }} ${{ steps.readme.outputs.file }} + **/README.md docs/* body: |- From f9a083868448e3351361f214a540ade7afedf3a2 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Thu, 31 Oct 2024 23:47:59 +0100 Subject: [PATCH 12/17] Added submodules support --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index ad805fc..9bf6c97 100644 --- a/action.yml +++ b/action.yml @@ -276,7 +276,7 @@ runs: commit_user_name: "${{ inputs.commit_user_name }}" commit_user_email: "${{ inputs.commit_user_email }}" commit_author: "${{ inputs.commit_author }}" - file_pattern: '${{ steps.banner.outputs.file }} ${{ steps.readme.outputs.file }}' + file_pattern: '${{ steps.banner.outputs.file }} ${{ steps.readme.outputs.file }} **/README.md' push_options: '${{ inputs.commit_push_options }}' - uses: actions/github-script@v7 From d6ef07fac9769f369b779db43955308b4673fba5 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Fri, 1 Nov 2024 10:32:09 +0100 Subject: [PATCH 13/17] Fix readme markdown --- action.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9bf6c97..59924cc 100644 --- a/action.yml +++ b/action.yml @@ -252,7 +252,10 @@ runs: cd $item if [[ -f README.md ]]; then - terraform-docs markdown ./ --config ${GITHUB_ACTION_PATH}/templates/terraform-docs.yml + terraform-docs markdown ./ \ + --output-file ./README.md \ + --output-mode inject \ + --output-template "\n{{ .Content }}\n" fi cd $current_dir From e079ede98560d18c480bdeeb8d979e265b7c7197 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Fri, 1 Nov 2024 12:16:27 +0100 Subject: [PATCH 14/17] Fix readme markdown --- action.yml | 14 +-- templates/terraform-docs.yml | 225 ----------------------------------- 2 files changed, 4 insertions(+), 235 deletions(-) delete mode 100644 templates/terraform-docs.yml diff --git a/action.yml b/action.yml index 59924cc..f6501eb 100644 --- a/action.yml +++ b/action.yml @@ -246,19 +246,13 @@ runs: | sort \ | uniq )) - for item in "${dirs[@]}"; do - current_dir=$(pwd) - echo "${item}" - cd $item - - if [[ -f README.md ]]; then - terraform-docs markdown ./ \ - --output-file ./README.md \ + for dir in "${dirs[@]}"; do + if [[ -f ${dir}/README.md ]]; then + terraform-docs markdown ${dir} \ + --output-file ${dir}/README.md \ --output-mode inject \ --output-template "\n{{ .Content }}\n" fi - - cd $current_dir done - uses: gaurav-nelson/github-action-markdown-link-check@v1 diff --git a/templates/terraform-docs.yml b/templates/terraform-docs.yml deleted file mode 100644 index 12666e7..0000000 --- a/templates/terraform-docs.yml +++ /dev/null @@ -1,225 +0,0 @@ -# https://pkg.go.dev/github.com/terraform-docs/terraform-docs/terraform#Module -content: |- - {{- $context_variables := list "context" "enabled" "namespace" "tenant" "environment" "stage" "name" "delimiter" "attributes" "tags" "additional_tag_map" "label_order" "regex_replace_chars" "id_length_limit" "label_key_case" "label_value_case" "descriptor_formats" "labels_as_tags" -}} - - {{ .Header }} - - ## Variables - - ### Required Variables - -
- {{- range .Module.Inputs }} - {{- if and (not (has .Name $context_variables)) .Required }} -
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} required{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
-
- {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} - {{- range $lines }} - {{ . }}
- {{- end }} - - {{ if gt (len (split "\n" (tostring .Type))) 2 }} - **Type:** - ```hcl - {{ .Type.Raw }} - ``` -
- {{ end }} - -
- {{- end }} - {{- end }} -
- - {{ $optional := false -}} - {{ range .Module.Inputs }}{{ if not .Required }}{{ $optional = true -}}{{ end -}}{{ end -}} - - {{ if $optional -}} - - ### Optional Variables - -
- {{- range .Module.Inputs }} - {{- if and (not (has .Name $context_variables)) (not .Required) }} -
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} optional{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
-
- {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} - {{- range $lines }} - {{ . }}
- {{- end }} -
- {{ if gt (len (split "\n" (tostring .Type))) 2 }} - **Type:** - ```hcl - {{ tostring .Type }} - ``` -
- {{ end }} - **Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue | replace "{}" "{ }" | replace "[]" "[ ]" }}`{{ else }} - ```hcl - {{- $lines := regexSplit "\n" .GetValue -1 -}} - {{- range $lines }} - {{ . }} - {{- end }} - ``` - {{ end }} -
- {{- end -}} - {{ end -}} -
- {{ end }} - - ### Context Variables - -
- - The following variables are defined in the `context.tf` file of this module and part of the [terraform-null-label](https://registry.terraform.io/modules/cloudposse/label/null) pattern. - - -
- {{- range .Module.Inputs }} - {{- if and (has .Name $context_variables) }} -
`{{ .Name }}`{{ if lt (len (split "\n" (tostring .Type))) 2 }} (`{{ tostring .Type }}`){{end}} {{ ternary .Required "required" "optional" }}{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
-
- {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "") -1 -}} - {{- range $lines }} - {{ . }}
- {{- end }} - **Required:** {{ ternary .Required "Yes" "No" }}
- {{ if gt (len (split "\n" (tostring .Type))) 2 }} - **Type:** - ```hcl - {{ .Type.Raw }} - ``` -
- {{ end }} - **Default value:** {{ if lt (len (split "\n" .GetValue)) 2 }}`{{ .GetValue | replace "{}" "{ }" | replace "[]" "[ ]" }}`{{ else }} - ```hcl - {{- $lines := regexSplit "\n" .GetValue -1 -}} - {{- range $lines }} - {{ . }} - {{- end }} - ``` - {{ end }} -
- {{- end }} - {{- end }} -
-
- - {{ if ne (len .Module.Outputs) 0 -}} - ## Outputs - -
- {{- range .Module.Outputs }} -
`{{ .Name }}`{{ if contains "OBSOLETE: " (tostring .Description) }} OBSOLETE{{ end }}
-
- {{- $lines := regexSplit "\n" (tostring .Description | replace "OBSOLETE: " "" | default "n/a" ) -1 -}} - {{- range $lines }} - {{ . }}
- {{- end }} -
- {{- end }} -
- {{- end }} - - ## Dependencies - - {{ if ne (len .Module.Requirements) 0 -}} - ### Requirements - {{ range .Module.Requirements }} - - `{{ .Name }}`{{ if .Version }}, version: `{{ .Version }}`{{ end }} - {{- end }} - {{- end }} - - {{ if ne (len .Module.Providers) 0 -}} - ### Providers - {{ range .Module.Providers }} - - `{{ .Name }}`{{ if .Version }}, version: `{{ .Version }}`{{ end }} - {{- end }} - {{- end }} - - {{ if ne (len .Module.ModuleCalls) 0 -}} - ### Modules - - Name | Version | Source | Description - --- | --- | --- | --- - {{ range .Module.ModuleCalls }} - {{- $baseUrl := "https://registry.terraform.io/modules" -}} - {{ if contains "//" .Source -}} - {{- $moduleParts := regexSplit "//" .Source 2 -}} - {{- $moduleName := first $moduleParts -}} - {{- $submodulePath := last $moduleParts -}} - `{{ .Name }}` | {{ .Version | default "latest" }} | {{ printf "[`%s`](%s/%s/%s/%s)" .Source $baseUrl $moduleName $submodulePath .Version }} | {{ tostring .Description | default "n/a" }} - {{ else -}} - `{{ .Name }}` | {{ .Version | default "latest" }} | {{ printf "[`%s`](%s/%s/%s)" .Source $baseUrl .Source .Version }} | {{ tostring .Description | default "n/a" }} - {{ end }} - {{- end -}} - {{- end -}} - - {{- if ne (len .Module.Resources) 0 }} - - ## Resources - - The following resources are used by this module: - {{ range .Module.Resources }} - {{- $isResource := and $.Config.Sections.Resources ( eq "resource" (printf "%s" .GetMode)) }} - {{- if $isResource }} - {{- $fullspec := ternary .URL (printf "[`%s`](%s)" .Spec .URL) .Spec }} - - {{ $fullspec }} {{ printf "(%s)" .GetMode -}} - {{- end }} - {{- end }} - - ## Data Sources - - The following data sources are used by this module: - {{ range .Module.Resources }} - {{- $isDataResource := and $.Config.Sections.DataSources ( eq "data source" (printf "%s" .GetMode)) }} - {{- if $isDataResource }} - {{- $fullspec := ternary .URL (printf "[`%s`](%s)" .Spec .URL) .Spec }} - - {{ $fullspec }} {{ printf "(%s)" .GetMode -}} - {{- end }} - {{- end }} - {{- end }} - -formatter: "markdown document" # this is required -version: "" - -recursive: - enabled: false - path: modules - -sections: - hide: [] - show: [] - -sort: - enabled: true - by: required - -output-values: - enabled: false - from: '' - -output: - file: README.md - mode: inject - template: |- - - {{ .Content }} - - -settings: - anchor: true - color: true - default: true - description: true - escape: true - hide-empty: false - html: true - indent: 2 - lockfile: false - read-comments: true - required: true - sensitive: true - type: true \ No newline at end of file From a3a61677d7b4d1cd89bc85388d0dcef6ad8aaa0e Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Fri, 1 Nov 2024 12:23:08 +0100 Subject: [PATCH 15/17] Fix readme markdown --- action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index f6501eb..b2159ee 100644 --- a/action.yml +++ b/action.yml @@ -246,10 +246,10 @@ runs: | sort \ | uniq )) - for dir in "${dirs[@]}"; do - if [[ -f ${dir}/README.md ]]; then - terraform-docs markdown ${dir} \ - --output-file ${dir}/README.md \ + for module_dir in "${dirs[@]}"; do + if [[ -f ${module_dir}/README.md ]]; then + terraform-docs markdown ${module_dir} \ + --output-file ${module_dir}/README.md \ --output-mode inject \ --output-template "\n{{ .Content }}\n" fi From 8205ec49f8d5c7d0325b9145121e1b74b003efa7 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Fri, 1 Nov 2024 12:25:58 +0100 Subject: [PATCH 16/17] Fix readme markdown --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index b2159ee..8ec0578 100644 --- a/action.yml +++ b/action.yml @@ -249,7 +249,7 @@ runs: for module_dir in "${dirs[@]}"; do if [[ -f ${module_dir}/README.md ]]; then terraform-docs markdown ${module_dir} \ - --output-file ${module_dir}/README.md \ + --output-file README.md \ --output-mode inject \ --output-template "\n{{ .Content }}\n" fi From 7c9e64286b0dbd2246353301eec0d385b42099ab Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Wed, 27 Nov 2024 12:37:39 +0300 Subject: [PATCH 17/17] Update action.yml --- action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/action.yml b/action.yml index 8ec0578..abde7a6 100644 --- a/action.yml +++ b/action.yml @@ -239,6 +239,11 @@ runs: if: inputs.readme_enabled == 'true' shell: bash run: | + terraform-docs markdown ./src \ + --output-file ../README.md \ + --output-mode inject \ + --output-template "\n{{ .Content }}\n" + dirs=($(find . -type d \( -name '.terraform*' -o -name 'obsolete*' \) -prune -o \ -name '*.tf' \ -not -path '*/.terraform/*' \