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

Added support of readme generation #35

Merged
merged 13 commits into from
Dec 8, 2017
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./terraform
49 changes: 48 additions & 1 deletion modules/docs/Makefile.docs
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
GOMPLATE_VERSION ?= v2.2.0
GOMPLATE_REPO ?= hairyhenderson/gomplate
GOMPLATE ?= gomplate

TEMPLATES ?= $(BUILD_HARNESS_PATH)/templates/docs

.PHONY : docs\:toc-update
## Update table of contents in README.md
docs\:toc-update:
@doctoc --notitle --github README.md
@doctoc --notitle --github README.md

## Install dependencies
docs\:deps:
@make github:download-public-release \
REPO=$(GOMPLATE_REPO) \
FILE=$(GOMPLATE)_$(OS)-amd64 \
VERSION=$(GOMPLATE_VERSION) \
OUTPUT=/usr/local/bin/$(GOMPLATE) > /dev/null
@chmod +x /usr/local/bin/$(GOMPLATE)

.PHONY : docs\:create
## Create basic minimalistic .README.md template file
docs\:create:
@cp $(BUILD_HARNESS_PATH)/templates/README.md ./.README.md

.PHONY : docs\:build
## Create README.md by building it from .README.md file
docs\:build:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be called build-readme since it's very specific to readme. Or docs: should be renamed to readme:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@NAME='$(NAME)' \
DESCRIPTION='$(DESCRIPTION)' \
$(GOMPLATE) \
--file ./.README.md \
--out ./README.md \
--datasource section=file://$(TEMPLATES)/sections.yml \
--datasource license=file://$(TEMPLATES)/licenses.yml \
--datasource contributor=file://$(TEMPLATES)/contributors.yml \
--datasource terraform=file://$(TEMPLATES)/terraform.yml

.PHONY : docs\:make
## Cleanup placeholders in README.md
docs\:make:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the make target name as it's overloading the meaning of make

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@make docs:build > /dev/null
@NAME='$(NAME)' \
DESCRIPTION='$(DESCRIPTION)' \
$(GOMPLATE) \
--file ./README.md \
--out ./README.md \
--datasource section=file://$(TEMPLATES)/sections.yml \
--datasource license=file://$(TEMPLATES)/licenses.yml \
--datasource contributor=file://$(TEMPLATES)/contributors.yml \
--datasource terraform=file://$(TEMPLATES)/terraform.yml
31 changes: 31 additions & 0 deletions modules/terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ TERRAFORM ?= $(BUILD_HARNESS_PATH)/terraform
TERRAFORM_VERSION ?= 0.10.7
TERRAFORM_URL ?= https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(OS)_amd64.zip

TERRAFORM_DOCS_REPO ?= segmentio/terraform-docs
TERRAFORM_DOCS_VERSION ?= v0.3.0
TERRAFORM_DOCS = terraform-docs

## Install terraform
terraform\:install:
@[ -x $(TERRAFORM) ] || ( \
Expand All @@ -14,6 +18,33 @@ terraform\:install:
)
$(TERRAFORM) version

## Install dependencies
terraform\:deps:
@make github:download-public-release \
REPO=$(TERRAFORM_DOCS_REPO) \
FILE=$(TERRAFORM_DOCS)_$(OS)_amd64 \
VERSION=$(TERRAFORM_DOCS_VERSION) \
OUTPUT=/usr/local/bin/$(TERRAFORM_DOCS) > /dev/null
@chmod +x /usr/local/bin/$(TERRAFORM_DOCS)

.PHONY : terraform\:docs
## Postprocess README.md by filling terraform module data
terraform\:docs:
@make docs:build > /dev/null
@$(eval TMP := $(shell date +'%Y%m%d-%H%M%S'))
@$(TERRAFORM_DOCS) json . > /tmp/$(TMP).json
@NAME='$(NAME)' \
DESCRIPTION='$(DESCRIPTION)' \
$(GOMPLATE) \
--file ./README.md \
--out ./README.md \
--datasource section=file://$(TEMPLATES)/sections.yml \
--datasource license=file://$(TEMPLATES)/licenses.yml \
--datasource contributor=file://$(TEMPLATES)/contributors.yml \
--datasource terraform=file://$(TEMPLATES)/terraform.yml \
--datasource terraform_data=file:///tmp/$(TMP).json
@rm -f /tmp/$(TMP).json

## Ensure all plugins can be fetched
terraform\:get-plugins:
@$(TERRAFORM) init -get-plugins -backend=false -input=false >/dev/null
Expand Down
16 changes: 16 additions & 0 deletions templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## {{ .Env.NAME }}
{{ (datasource "section").warning }}
{{ .Env.DESCRIPTION }}

{{ (datasource "section").help }}
{{ (datasource "section").contributing }}
{{ (datasource "license").apache2 }}
{{ (datasource "section").about }}

### Contributors

|
{{- (datasource "contributor").erik }} |
|---|

{{ (datasource "contributor")._links }}
43 changes: 43 additions & 0 deletions templates/docs/contributors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
andrew: |-
[![Andriy Knysh][andriy_img]][andriy_web]<br/>[Andriy Knysh][andriy_web]

erik: |-
[![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web]

igor: |-
[![Igor Rodionov][igor_img]][igor_web]<br/>[Igor Rodionov][igor_img]

konstantin: |-
[![Konstantin B][konstantin_img]][konstantin_web]<br/>[Konstantin B][konstantin_web]

sergey: |-
[![Sergey Vasilyev][sergey_img]][sergey_web]<br/>[Sergey Vasilyev][sergey_web]

valeriy: |-
[![Valeriy][valeriy_img]][valeriy_web]<br/>[Valeriy][valeriy_web]

vladimir: |-
[![Vladimir][vladimir_img]][vladimir_web]<br/>[Vladimir][vladimir_web]

_links: |-
[andriy_img]: https://avatars0.githubusercontent.com/u/7356997?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[andriy_web]: https://github.com/aknysh/

[erik_img]: http://s.gravatar.com/avatar/88c480d4f73b813904e00a5695a454cb?s=144
[erik_web]: https://github.com/osterman/

[igor_img]: http://s.gravatar.com/avatar/bc70834d32ed4517568a1feb0b9be7e2?s=144
[igor_web]: https://github.com/goruha/

[konstantin_img]: https://avatars1.githubusercontent.com/u/11299538?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[konstantin_web]: https://github.com/comeanother/

[sergey_img]: https://avatars1.githubusercontent.com/u/1134449?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[sergey_web]: https://github.com/s2504s/

[valeriy_img]: https://avatars1.githubusercontent.com/u/10601658?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[valeriy_web]: https://github.com/drama17/

[vladimir_img]: https://avatars1.githubusercontent.com/u/26582191?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[vladimir_web]: https://github.com/SweetOps/
24 changes: 24 additions & 0 deletions templates/docs/licenses.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
apache2: |-
## License

[APACHE 2.0](LICENSE) © 2017 [Cloud Posse, LLC](https://cloudposse.com)

See [LICENSE](LICENSE) for full details.

Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
43 changes: 43 additions & 0 deletions templates/docs/sections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
warning: |-
<!--------------------------------DO NOT EDIT README.md-------------------------------->
Copy link
Member

@osterman osterman Nov 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<!--- 
  --- This file was automatically generated by the `build-harness` 
  --- Make changes instead to `.README.md` and rebuild.
  --->

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

about: |-
## About

This module is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at <[email protected]>

We love [Open Source Software](https://github.com/cloudposse/)!

See [our other projects][community]
or [hire us][hire] to help build your next cloud-platform.

[website]: http://cloudposse.com/
[community]: https://github.com/cloudposse/
[hire]: http://cloudposse.com/contact/
help: |-
## Help

**Got a question?**

File a GitHub [issue](https://github.com/cloudposse/{{ .Env.NAME }}/issues), send us an [email](mailto:[email protected]) or reach out to us on [Gitter](https://gitter.im/cloudposse/).

contributing: |-
## Contributing

### Bug Reports & Feature Requests

Please use the [issue tracker](https://github.com/cloudposse/{{ .Env.NAME }}/issues) to report any bugs or file feature requests.

### Developing

If you are interested in being a contributor and want to get involved in developing `{{ .Env.NAME }}`, we would love to hear from you! Shoot us an [email](mailto:[email protected]).

In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

1. **Fork** the repo on GitHub
2. **Clone** the project to your own machine
3. **Commit** changes to your own branch
4. **Push** your work back up to your fork
5. Submit a **Pull request** so that we can review your changes

**NOTE:** Be sure to merge the latest from "upstream" before making a pull request!
34 changes: 34 additions & 0 deletions templates/docs/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
input: |-
## Input

<!--------------------------------REQUIRE POSTPROCESSING-------------------------------->
| Name | Default | Description |
|:------|:---------:|:--------------:|
{{- range $index, $element := (datasource "terraform_data").Inputs }}
| {{ $element.Name }} |
{{- if $element.Default }}
{{- if eq $element.Default.Type "map" }}
{{- "{}" }}
{{- else }}
{{- if eq $element.Default.Type "list" -}}
[]
{{- else -}}
"{{ $element.Default.Literal }}"
{{- end }}
{{- end }}
{{- else -}}
__REQUIRED__
{{- end }} |
{{- $element.Description | strings.ReplaceAll "\n" " " }} |
{{- end }}

output: |-
## Output

<!--------------------------------REQUIRE POSTPROCESSING-------------------------------->
| Name | Description |
|:------|:------------:|
{{- range $index, $element := (datasource "terraform_data").Outputs }}
| {{ $element.Name }} | {{ $element.Description | strings.ReplaceAll "\n" " " }} |
{{- end }}