Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prepare release v0.1.0 #4

Merged
merged 1 commit into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
175 changes: 94 additions & 81 deletions .github/templates/README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@
{{- define "sanatize_string" }}{{ . | strings.ReplaceAll "\n\n" "<br><br>" | strings.ReplaceAll " \n" "<br>" | strings.ReplaceAll "\n" "<br>" | tmpl.Exec "escape_chars" }}{{- end }}
{{- $action := (datasource "action") -}}{{- $version := or (getenv "VERSION") "master" -}}
# {{ $action.name }}
{{ $action.description }} In addition to statically defined directory modules, this module can search specific sub folders or parse atlantis.yaml for module identification and doc generation. This action has the ability to auto commit docs to an open PR or after a push to a specific branch.

{{ $action.description }}
In addition to statically defined directory modules, this module can search specific
subfolders or parse `atlantis.yaml` for module identification and doc generation. This
action has the ability to auto commit docs to an open PR or after a push to a specific
branch.

## Version
{{ $version }}

Using [terraform-docs](https://github.com/terraform-docs/terraform-docs) `v0.8.2`, which is supported and tested on terraform version 0.11+ & 0.12+ but may work for others.
`{{ $version }}` (uses [terraform-docs] v0.10.1, which is supported and tested on Terraform version
0.11+ and 0.12+ but may work for others.)

{{ if eq $version "master" }}
{{- if eq $version "master" }}
| WARNING: You should not rely on master being stable or to have accurate documentation. Please use a git tagged semver or major version tag like `v1`. |
| --- |
{{ end }}
{{- end }}

## Usage

To use terraform-docs github action, configure a YAML workflow file, e.g.
`.github/workflows/documentation.yml`, with the following:

# Usage
To use terraform-docs github action, configure a YAML workflow file, e.g. `.github/workflows/documentation.yml`, with the following:
```yaml
name: Generate terraform docs
on:
Expand All @@ -30,123 +39,127 @@ jobs:
- name: Render terraform docs inside the USAGE.md and push changes back to PR branch
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_working_dir: .
tf_docs_output_file: USAGE.md
tf_docs_output_method: inject
tf_docs_git_push: 'true'
working-dir: .
output-file: USAGE.md
output-method: inject
git-push: "true"
```

| WARNING: If USAGE.md already exists it will need to be updated, with the block delimeters `<!--- BEGIN_TF_DOCS --->` and `<!--- END_TF_DOCS --->`, where the generated markdown will be injected. |
| --- |

### Renders
![Example](examples/example.png?raw=true "Example Output")
## Configuration

# Configuration

## Inputs
### Inputs

| Name | Description | Default | Required |
|------|-------------|---------|----------|
{{- range $key, $input := $action.inputs }}
| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $input "description") }}{{ tmpl.Exec "sanatize_string" $input.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} | {{ if (has $input "default") }}{{ tmpl.Exec "sanatize_string" $input.default }}{{ else }}N/A{{ end }} | {{ if (has $input "required") }}{{ $input.required }}{{ else }}false{{ end }} |
| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $input "description") }}{{ tmpl.Exec "sanatize_string" $input.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} | {{ if (has $input "default") }}`{{ tmpl.Exec "sanatize_string" $input.default }}`{{ else }}N/A{{ end }} | {{ if (has $input "required") }}{{ $input.required }}{{ else }}false{{ end }} |
{{- end }}

## Outputs
#### Output Method (output-method)

| Name | Description |
|------|-------------|
{{- range $key, $output := $action.outputs }}
| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $output "description") }}{{ tmpl.Exec "sanatize_string" $output.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} |
{{- end }}
- `print`

# Important Notes
This will just print the generated output

In addition to the below notes, further documentation on terraform-docs can be found [here](https://github.com/terraform-docs/terraform-docs).
- `replace`

## Output Method (tf\_docs\_output\_method)
This will create or replace the `output-file` at the determined module path(s)

### print
This will just print the generated file
- `inject`

### replace
This will create/replace the tf\_docs\_output\_file at the determined module path(s)
Instead of replacing the `output-file`, this will inject the generated documentation
into the existing file between the predefined delimeters: `<!--- BEGIN_TF_DOCS --->`
and `<!--- END_TF_DOCS --->`. If the file exists but does not contain the delimeters,
the action will fail for the given module. If the file doesn't exist, it will create
it using the value template which MUST have the delimeters.

### inject
Instead of replacing the output file, this will inject the generated documentation into the existing file between the predefined delimeters: `<!--- BEGIN_TF_DOCS --->` and `<!--- END_TF_DOCS --->`. If the file exists but does not contain the delimeters, the action will fail for the given module. If the file doesn't exist, it will create it using the value tf\_docs\_template which MUST have the delimeters.
#### Auto commit changes

## Auto commit changes
To enable you need to ensure a few things first:
- set tf\_docs\_git\_push to 'true'
- use actions/checkout@v2 with the head ref for PRs or branch name for pushes

### PR
```yaml
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: {{"${{"}} github.event.pull_request.head.ref {{"}}"}}
```

### Push
```yaml
on:
push:
branches:
- master
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
```
- set `git-push` to `true`
- use `actions/checkout@v2` with the head ref for PRs or branch name for pushes
- PR

```yaml
on:
- pull_request
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: {{"${{"}} github.event.pull_request.head.ref {{"}}"}}
```

- Push

```yaml
on:
push:
branches:
- master
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: master
```

### Outputs

## Content type (tf\_docs\_content\_type)
- document - long form document
- table - github formatted table
- json - pure json output
| Name | Description |
|------|-------------|
{{- range $key, $output := $action.outputs }}
| {{ tmpl.Exec "escape_chars" $key }} | {{ if (has $output "description") }}{{ tmpl.Exec "sanatize_string" $output.description }}{{ else }}{{ tmpl.Exec "escape_chars" $key }}{{ end }} |
{{- end }}

## Examples

# Examples
### Single folder

## Simple / Single folder
```
```yaml
- name: Generate TF Docs
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_working_dir: .
tf_docs_output_file: README.md
working-dir: .
output-file: README.md
```

## Multi folder
```
### Multi folder

```yaml
- name: Generate TF Docs
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_working_dir: .,example1,example3/modules/test
tf_docs_output_file: README.md
working-dir: .,example1,example3/modules/test
output-file: README.md
```

## Use atlantis.yaml v3 to find all dirs
```
### Use `atlantis.yaml` v3 to find all directories

```yaml
- name: Generate TF docs
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_atlantis_file: atlantis.yaml
atlantis-file: atlantis.yaml
```

## Find all .tf file folders under a given directory
### Find all `.tf` file under a given directory

```yaml
- name: Generate TF docs
uses: terraform-docs/gh-actions@{{ $version }}
with:
tf_docs_find_dir: examples/
find-dir: examples/
```

Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/{{ $version }}/examples)
Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/{{ $version }}/examples).

[terraform-docs]: https://github.com/terraform-docs/terraform-docs
40 changes: 19 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# terraform-docs

A Github action for generating Terraform module documentation using [terraform-docs](terraform-docs)
and gomplate. In addition to statically defined directory modules, this module can
search specific subfolders or parse `atlantis.yaml` for module identification and
doc generation. This action has the ability to auto commit docs to an open PR or
after a push to a specific branch.
A Github action for generating Terraform module documentation using terraform-docs and gomplate.
In addition to statically defined directory modules, this module can search specific
subfolders or parse `atlantis.yaml` for module identification and doc generation. This
action has the ability to auto commit docs to an open PR or after a push to a specific
branch.

## Version

`v0.1.0` (uses terraform-docs v0.10.1, which is supported and tested on terraform version 0.11+ and
0.12+ but may work for others.)
`v0.1.0` (uses [terraform-docs] v0.10.1, which is supported and tested on Terraform version
0.11+ and 0.12+ but may work for others.)

## Usage

Expand Down Expand Up @@ -46,17 +46,17 @@ jobs:

| Name | Description | Default | Required |
|------|-------------|---------|----------|
| working-dir | Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set) | `.` | false |
| args | Additional arguments to pass to the command (see [full documentation](https://github.com/terraform-docs/terraform-docs/tree/master/docs)) | `` | false |
| atlantis-file | Name of Atlantis file to extract list of directories by parsing it. To enable, provide the file name (e.g. `atlantis.yaml`) | `disabled` | false |
| find-dir | Name of root directory to extract list of directories by running `find ./find_dir -name *.tf` (ignored if atlantis-file is set) | `disabled` | false |
| output-format | terraform-docs format to generate content (see [all formats]) | `markdown table` | false |
| output-method | Method should be one of `replace`, `inject`, or `print` (see below for detail) | `inject` | false |
| output-file | File in module directory where the docs should be placed | `USAGE.md` | false |
| template | When provided will be used as the template if/when the `output-file` does not exist | <pre># Usage<br><br><!--- BEGIN\_TF\_DOCS ---><br><!--- END\_TF\_DOCS ---><br></pre> | false |
| args | Additional arguments to pass down to the command (see [full documentation]) | `""` | false |
| indention | Indention level of Markdown sections [1, 2, 3, 4, 5] | `2` | false |
| git-push | If true it will commit and push the changes | `false` | false |
| find-dir | Name of root directory to extract list of directories by running `find ./find\_dir -name \*.tf` (ignored if `atlantis-file` is set) | `disabled` | false |
| git-commit-message | Commit message | `terraform-docs: automated action` | false |
| git-push | If true it will commit and push the changes | `false` | false |
| indention | Indention level of Markdown sections [1, 2, 3, 4, 5] | `2` | false |
| output-file | File in module directory where the docs should be placed | `USAGE.md` | false |
| output-format | terraform-docs format to generate content (see [all formats](https://github.com/terraform-docs/terraform-docs/blob/master/docs/FORMATS\_GUIDE.md)) | `markdown table` | false |
| output-method | Method should be one of `replace`, `inject`, or `print` | `inject` | false |
| template | When provided will be used as the template if/when the `output-file` does not exist | `# Usage<br><br><!--- BEGIN\_TF\_DOCS ---><br><!--- END\_TF\_DOCS ---><br>` | false |
| working-dir | Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set) | `.` | false |

#### Output Method (output-method)

Expand Down Expand Up @@ -116,7 +116,7 @@ To enable you need to ensure a few things first:

| Name | Description |
|------|-------------|
| num-changed | Number of files changed |
| num\_changed | Number of files changed |

## Examples

Expand Down Expand Up @@ -158,8 +158,6 @@ To enable you need to ensure a few things first:
find-dir: examples/
```

Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/master/examples).
Complete examples can be found [here](https://github.com/terraform-docs/gh-actions/tree/v0.1.0/examples).

[terraform-docs]: https://github.com/terraform-docs/terraform-docs
[all formats]: https://github.com/terraform-docs/terraform-docs/blob/master/docs/FORMATS_GUIDE.md
[full documentation]: https://github.com/terraform-docs/terraform-docs/tree/master/docs
[terraform-docs]: https://github.com/terraform-docs/terraform-docs
14 changes: 7 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,39 @@ description: A Github action for generating Terraform module documentation using

inputs:
working-dir:
description: Comma separated list of directories to generate docs for (ignored if atlantis-file or find-dir is set)
description: Comma separated list of directories to generate docs for (ignored if `atlantis-file` or `find-dir` is set)
required: false
default: "."
atlantis-file:
description: Name of Atlantis file to extract list of directories by parsing it. To enable, provide the file name (e.g. atlantis.yaml)
description: Name of Atlantis file to extract list of directories by parsing it. To enable, provide the file name (e.g. `atlantis.yaml`)
required: false
default: "disabled"
find-dir:
description: Name of root directory to extract list of directories by running 'find ./find_dir -name *.tf' (ignored if atlantis-file is set)
description: Name of root directory to extract list of directories by running `find ./find_dir -name *.tf` (ignored if `atlantis-file` is set)
required: false
default: "disabled"
output-format:
description: terraform-docs format to generate content (see https://github.com/terraform-docs/terraform-docs/blob/master/docs/FORMATS_GUIDE.md)
description: terraform-docs format to generate content (see [all formats](https://github.com/terraform-docs/terraform-docs/blob/master/docs/FORMATS_GUIDE.md))
required: false
default: "markdown table"
output-method:
description: Method should be one of (replace, inject, or print) where replace will replace the output_file, inject will inject the content between start and close delims and print will just print the output
description: Method should be one of `replace`, `inject`, or `print`
required: false
default: "inject"
output-file:
description: File in module directory where the docs should be placed
required: false
default: "USAGE.md"
template:
description: When provided will be used as the template if/when the OUTPUT_FILE does not exist
description: When provided will be used as the template if/when the `output-file` does not exist
default: |
# Usage

<!--- BEGIN_TF_DOCS --->
<!--- END_TF_DOCS --->
required: false
args:
description: Additional arguments to pass to the command (see https://github.com/terraform-docs/terraform-docs/tree/master/docs)
description: Additional arguments to pass to the command (see [full documentation](https://github.com/terraform-docs/terraform-docs/tree/master/docs))
required: false
default: ""
indention:
Expand Down
5 changes: 1 addition & 4 deletions scripts/pre-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ fi
# Update the README
VERSION=$NEW_VERSION gomplate -d action=action.yml -f .github/templates/README.tpl -o README.md

# Update Dockerfile
gsed -i "s|FROM derekrada/terraform-docs:.*|FROM derekrada/terraform-docs:${NEW_VERSION}|" ./Dockerfile

git commit -am "chore: prepare release ${NEW_VERSION}"
git commit -a -s -m "chore: prepare release ${NEW_VERSION}"
git push --set-upstream origin "release/${NEW_VERSION}"