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
Show file tree
Hide file tree
Changes from 7 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
54 changes: 54 additions & 0 deletions .README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Cloud Posse Build Harness [![Build Status](https://travis-ci.org/cloudposse/build-harness.svg)](https://travis-ci.org/cloudposse/build-harness)
{{ (datasource "section").warning }}

This `build-harness` is a collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more.

It's designed to work with CI/CD systems such as Travis CI, CircleCI and Jenkins.

It's 100% Open Source and licensed under [APACHE2](LICENSE).


## Usage

At the top of your `Makefile` add, the following...

```make
-include $(shell curl -sSL -o .build-harness "https://git.io/build-harness"; echo .build-harness)
```

This will download a `Makefile` called `.build-harness` and include it at run-time. We recommend adding the `.build-harness` file to your `.gitignore`.

This automatically exposes many new targets that you can leverage throughout your build & CI/CD process.

Run `make help` for a list of available targets.

{{ (datasource "make").help }}

## Real World Examples

- [`github-authorized-keys`](https://github.com/cloudposse/github-authorized-keys/) - A Golang project that leverages `docker:%`, `go:%`, `travis:%` targets
- [`charts`](https://github.com/cloudposse/charts/) - A collection of Helm Charts that leverages `docker:%` and `helm:%` targets
- [`bastion`](https://github.com/cloudposse/bastion/) - A docker image that leverages `docker:%` and `bash:lint` targets
- [`terraform-null-label`](https://github.com/cloudposse/terraform-null-label/) - A terraform module that leverages `terraform:%` targets

{{ (datasource "section").help }}
{{ (datasource "section").contributing }}

Here's how to get started...

1. `git clone https://github.com/cloudposse/{{ (datasource "repo").name }}.git` to pull down the repository
2. `make init` to initialize the [`{{ (datasource "repo").name }}`](https://github.com/cloudposse/{{ (datasource "repo").name }}/)
3. Review the [documentation](docs/) on compiling


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

### Contributors

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

{{ (datasource "contributor")._links }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./terraform
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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

OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
SELF ?= make

Expand Down
69 changes: 46 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Cloud Posse Build Harness [![Build Status](https://travis-ci.org/cloudposse/build-harness.svg)](https://travis-ci.org/cloudposse/build-harness)
<!---
--- This file was automatically generated by the `build-harness`
--- Make changes instead to `.README.md` and rebuild.
--->

This `build-harness` is a collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more.
This `build-harness` is a collection of Makefiles to facilitate building Golang projects, Dockerfiles, Helm charts, and more.

It's designed to work with CI/CD systems such as Travis CI, CircleCI and Jenkins.

Expand All @@ -21,24 +25,22 @@ This automatically exposes many new targets that you can leverage throughout you

Run `make help` for a list of available targets.


## Makefile Targets

```bash
$ make help

Available targets:
Available targets:

bash:lint Lint all bash scripts
docker:build Build docker image
docker:login Login into docker hub
docs:copyright-add Add copyright headers to source code
docs:toc-update Update table of contents in README.md
geodesic:deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG)
git:aliases-update Update git aliases
git:submodules-update Update submodules
github:download-private-release Download release from github
github:download-public-release Download release from github
git:submodules-update Update submodules
go:build Build binary
go:build-all Build binary for all platforms
go:clean Clean compiled binary
Expand All @@ -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

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:toc-update Update table of contents in README.md
terraform:deps Install dependencies
terraform:get-modules Ensure all modules can be fetched
terraform:get-plugins Ensure all plugins can be fetched
terraform:install Install terraform
terraform:lint Lint check Terraform
terraform:validate Basic terraform sanity check
travis:docker-login Login into docker hub
travis:docker-tag-and-push Tag & Push according Travis environment variables
```

```

## Real World Examples

Expand All @@ -81,10 +89,9 @@ Available targets:

## Help

**Got a question?**
**Got a question?**

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

## Contributing

### Bug Reports & Feature Requests
Expand All @@ -93,7 +100,7 @@ Please use the [issue tracker](https://github.com/cloudposse/build-harness/issue

### Developing

If you are interested in being a contributor and want to get involved in developing the `build-harness`, we would love to hear from you! Shoot us an [email](mailto:[email protected]).
If you are interested in being a contributor and want to get involved in developing `build-harness`, 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.

Expand All @@ -107,13 +114,16 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

Here's how to get started...

1. `git clone https://github.com/cloudposse/build-harness.git` to pull down the repository
1. `git clone https://github.com/cloudposse/build-harness.git` to pull down the repository
2. `make init` to initialize the [`build-harness`](https://github.com/cloudposse/build-harness/)
3. Review the [documentation](docs/) on compiling


## License

[APACHE 2.0](LICENSE) © 2016-2017 [Cloud Posse, LLC](https://cloudposse.com)
[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
Expand All @@ -122,7 +132,7 @@ Here's how to get started...
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,
Expand All @@ -131,28 +141,41 @@ Here's how to get started...
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.

## About

GitHub Authorized Keys is maintained and funded by [Cloud Posse, LLC][website]. Like it? Please let us know at <[email protected]>
This project 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/)!
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.
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/

### Contributors

|[![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] |[![Igor Rodionov][igor_img]][igor_web]<br/>[Igor Rodionov][igor_img] |
|---|---|

[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/

| [![Erik Osterman][erik_img]][erik_web]<br/>[Erik Osterman][erik_web] | [![Igor Rodionov][igor_img]][igor_web]<br/>[Igor Rodionov][igor_web] |
|-------------------------------------------------------|------------------------------------------------------------------|
[konstantin_img]: https://avatars1.githubusercontent.com/u/11299538?v=4&u=ed9ce1c9151d552d985bdf5546772e14ef7ab617&s=144
[konstantin_web]: https://github.com/comeanother/

[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/
[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/
4 changes: 0 additions & 4 deletions modules/docs/Makefile.docs

This file was deleted.

2 changes: 0 additions & 2 deletions modules/make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ make\:lint:
find . -type f -name 'Makefile*' -type f '!' -name '*.example' -exec \
/bin/sh -c 'echo "==> {}">/dev/stderr; make --include-dir=modules/ --just-print --dry-run --recon --no-print-directory --quiet --silent -f {}' \; > /dev/null
@make bash:lint


19 changes: 19 additions & 0 deletions modules/make/Makefile.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


define make-docs-provide
--datasource make=file:///$(TEMPLATES)/make.yml
endef

define make_data-docs-provide
--datasource make_data=file:///tmp/make_data.yml
endef

define make-docs-prepare-data
$(shell echo "---" > /tmp/make_data.$(TIMESTAMP).yml)
$(shell echo " help: |" >> /tmp/make_data.yml)
$(shell make -s help | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | sed -e 's/^/ /' >> /tmp/make_data.yml)
endef

define make-docs-cleanup-data
$(shell rm -rf /tmp/make_data.yml)
endef
67 changes: 67 additions & 0 deletions modules/readme/Makefile.docs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
GOMPLATE_VERSION ?= v2.2.0
GOMPLATE_REPO ?= hairyhenderson/gomplate
GOMPLATE ?= gomplate

TEMPLATES ?= $(BUILD_HARNESS_PATH)/templates/readme

INCLUDED_MODULES ?= "repo"

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

## Install dependencies
readme\: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 : readme\:init
## Create basic minimalistic .README.md template file
readme\:init:
@if [ -s ./.README.md ]; then \
echo ".README.md already exists!"; \
else \
cp $(BUILD_HARNESS_PATH)/templates/README.md ./.README.md ; \
echo ".README.md created!"; \
fi;

.PHONY : readme\:build
## Create README.md by building it from .README.md file
readme\:build:
$(eval IN=./.README.md)
$(eval OUT=./README.md)

## We support only 10 levels on inheritance templates
$(foreach module, 1 2 3 4 5 6 7 8 9 10, \
$(eval MODULES=) \
$(call modules,MODULES) \
$(call modules-merge,INCLUDED_MODULES,$(INCLUDED_MODULES),$(MODULES)) \
$(foreach module, $(MODULES), $(call $(module)-docs-prepare-data)) \
$(shell $(GOMPLATE) --file $(IN) --out $(OUT) $(foreach module, $(INCLUDED_MODULES), $(call $(module)-docs-provide))) \
$(eval IN=./README.md) \
)

$(foreach module, \
$(INCLUDED_MODULES), \
$(call $(module)-docs-cleanup-data) \
)
@echo "README.md generated"


# Get template docs modules from $(IN) file ( .README.md / README.md )
define modules
$(eval MODULES=$$(shell grep -oP "(?<=datasource)\s+\".*?\"" $(IN) | sed 's/[ |\"]//g' | sort | uniq | paste -sd " " - ))
endef

# Merge 2 lists (in format words separated be space in string)
define modules-merge
$(eval $(1)=$$(shell echo "$(2) $(3)" | tr ' ' '\n' | sort | uniq | paste -sd " " - ))
endef



4 changes: 4 additions & 0 deletions modules/readme/Makefile.docs.contributor
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

define contributor-docs-provide
--datasource contributor=file:///$(TEMPLATES)/contributor.yml
endef
4 changes: 4 additions & 0 deletions modules/readme/Makefile.docs.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

define license-docs-provide
--datasource license=file:///$(TEMPLATES)/license.yml
endef
19 changes: 19 additions & 0 deletions modules/readme/Makefile.docs.repo
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

define repo-docs-provide
--datasource repo=file:///$(TEMPLATES)/repo.yml
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.

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

$(shell echo "---" > /tmp/repo_data.yml)
$(shell git ls-remote --get-url | xargs -I{} echo "url: {}" >> /tmp/repo_data.yml)
$(shell git ls-remote --get-url | grep -oP "(?<=\/).*(?=.git)" | xargs -I{} echo "name: {}" >> /tmp/repo_data.yml)
endef

define repo-docs-cleanup-data
$(shell rm -rf /tmp/repo_data.yml)
endef

4 changes: 4 additions & 0 deletions modules/readme/Makefile.docs.section
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

define section-docs-provide
--datasource section=file:///$(TEMPLATES)/section.yml
endef
2 changes: 2 additions & 0 deletions modules/terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ 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



## Install terraform
terraform\:install:
@[ -x $(TERRAFORM) ] || ( \
Expand Down
Loading