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
Merged

Conversation

goruha
Copy link
Member

@goruha goruha commented Nov 5, 2017

What

  • Support of README generation
  • Support pluggable datasources (check how we deal with make & terraform projects)
  • Generate readme with one command

Why

  • We have standard parts in readme files.
  • Different projects need different way to collect data for templates
  • Unify way to generate readme independent of project type

How to use

  1. Create Makefile in repo root dir ( Example https://github.com/cloudposse/terraform-aws-elastic-beanstalk-environment/blob/feature-support-readme-generation/Makefile )
  2. Run $ make readme:init to fetch basic .README.md
  3. Customize .README.md template as you need
  4. Run $ make readme:build to generate README.md based on .README.md

Avaliable placeholders

  • {{ (datasource "git").name }} - Repository name
  • {{ (datasource "git").url }} - Repository URL
  • {{ (datasource "section").help }} - Cloudposse contact us text
  • {{ (datasource "section").contributing }} - Cloudposse code of conduct rules
  • {{ (datasource "license").apache2 }} - Cloudposse short license text
  • {{ (datasource "section").about }} - Cloudposse about text
  • {{ (datasource "section").warning }} - Warning DO NOT EDIT README.md
  • {{- (datasource "contributor").erik }} - Erik's contributor card
  • {{- (datasource "contributor").igor }} - Igor's contributor card
  • {{- (datasource "contributor").andrew }} - Andrew contributor card
  • {{- (datasource "contributor").konstantin }} - Konstantin's contributor card
  • {{- (datasource "contributor").sergey }} - Sergey's contributor card
  • {{- (datasource "contributor").valeriy }} - Valeriy's contributor card
  • {{- (datasource "contributor").vladimir }} - Vladimir's contributor card
  • {{- (datasource "contributor")._links }} - Links to github profiles and images to contributors (Required if at least one contributor specified in README)
  • {{ (datasource "terraform").input }} - Terraform module input variables table
  • {{ (datasource "terraform").output }} - Terraform module outputs table
  • {{ (datasource "make").help }} - Make targets list with descriptions (based on make help)

Under the hood

  1. Gomplate as cli tool for gotempale
  2. Terraform docs as tool to parse terraform module and get input\output

Example

cloudposse/terraform-aws-elastic-beanstalk-environment#19
#35

.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

@osterman
Copy link
Member

osterman commented Nov 9, 2017

What do you think about a templates/readme/.... structure. So then the README.md would go in there along with all data sources.

.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

@osterman
Copy link
Member

osterman commented Nov 9, 2017

Seems like the build-harness should make use of the this convention for it's own README.md

@@ -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

README.md Outdated
@@ -63,14 +65,20 @@ Available targets:
help This help screen
jenkins:run-job-with-tag Run a Jenkins Job with $(TAG)
make:lint Lint all makefiles
readme:build Create README.md by building it from .README.md file
readme:deps Install dependencies
readme:init Create basic minimalistic .README.md template file
Copy link
Member

Choose a reason for hiding this comment

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

Initialize a minimalistic README.md from template file

README.md Outdated
@@ -63,14 +65,20 @@ Available targets:
help This help screen
jenkins:run-job-with-tag Run a Jenkins Job with $(TAG)
make:lint Lint all makefiles
readme:build Create README.md by building it from .README.md file
Copy link
Member

Choose a reason for hiding this comment

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

Generate README.md from template file

output: |-
## Output

<!--------------------------------REQUIRE POSTPROCESSING-------------------------------->
Copy link
Member

Choose a reason for hiding this comment

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

What sort of postprocessing?

endef

define terraform_data-docs-prepare-data
$(shell $(TERRAFORM_DOCS) json . > /tmp/terraform_data.json)
Copy link
Member

Choose a reason for hiding this comment

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

s/terraform_data.json/terraform-docs.json/

--datasource repo_data=file:///tmp/repo_data.yml
endef

define repo-docs-prepare-data
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 know what this does

endef

define repo_data-docs-provide
--datasource repo_data=file:///tmp/repo_data.yml
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 reliance on /tmp without a tmp directory. If we're usnig this in multiple projects, there will be collisions.

.PHONY : docs\:build
## Create $OUT file by building it from $IN template file
docs\:build:
@BUILD_HARNESS_PATH=$(BUILD_HARNESS_PATH) \
Copy link
Member

Choose a reason for hiding this comment

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

This is already exported, so should need to be passed

Copy link
Member Author

Choose a reason for hiding this comment

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

When I remove pass $BUILD_HARNESS_PATH
I got this error

2017/12/04 15:34:19 Can't read /home/goruha/projects/cloudposse/build-harness/: &os.PathError{Op:"read", Path:"/home/goruha/projects/cloudposse/build-harness/", Err:0x15}
README.md doc generated

## Create $OUT file by building it from $IN template file
docs\:build:
@BUILD_HARNESS_PATH=$(BUILD_HARNESS_PATH) \
GOMPLATE=$(GOMPLATE) \
Copy link
Member

Choose a reason for hiding this comment

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

Why not just export it above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do we have example for that?

}

function git_data-docs-cleanup-data {
rm -rf $GIT_DATA_FILE
Copy link
Member

Choose a reason for hiding this comment

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

-f should be good enough and safer

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

## Create README.md by building it from .README.md file
readme\:build:
@IN=$(README_TEMPLATE_FILE) \
OUT=$(README_FILE) \
Copy link
Member

Choose a reason for hiding this comment

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

normalize whitespace

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



function terraform-docs-prepare-data {
if [ ! -s /usr/local/bin/$TERRAFORM_DOCS ]; then
Copy link
Member

Choose a reason for hiding this comment

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

normalize whitespace

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

Makefile Outdated
@@ -1,6 +1,6 @@
BUILD_HARNESS_PATH ?= .
BUILD_HARNESS_PATH ?= $(shell 'pwd')
Copy link
Member

Choose a reason for hiding this comment

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

export

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

REPO=$(GOMPLATE_REPO) \
FILE=$(GOMPLATE)_$(OS)-amd64 \
VERSION=$(GOMPLATE_VERSION) \
OUTPUT=/usr/local/bin/$(GOMPLATE) > /dev/null
Copy link
Member

Choose a reason for hiding this comment

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

This should install to a path relative to the build-harness
a) avoids permission issues
b) avoids conflicts between different build-harness checkouts

@goruha goruha merged commit dbd0e31 into master Dec 8, 2017
@goruha goruha deleted the feature-readme-generation branch December 8, 2017 18:15
charlieparkes added a commit to charlieparkes/build-harness that referenced this pull request May 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants