From 9ddef8cbe751585cb31d7e5995a96285e13fcdee Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Tue, 16 Feb 2016 21:11:39 -0800 Subject: [PATCH] Add automatic bootstrapping script makenew.sh --- .kitchen.yml | 2 +- README.md | 232 +++++++++++++----- _README.md.erb | 3 +- attributes/default.rb | 4 +- doc/badges.md | 11 +- doc/contributing.md | 2 +- doc/license.md | 6 +- doc/makenew.md | 110 +++++++++ doc/source.md | 6 +- doc/usage.md | 4 +- makenew.sh | 73 ++++++ metadata.rb | 14 +- recipes/default.rb | 4 +- spec/default_spec.rb | 4 +- .../default/serverspec/default_spec.rb | 2 +- 15 files changed, 390 insertions(+), 87 deletions(-) create mode 100644 doc/makenew.md create mode 100755 makenew.sh diff --git a/.kitchen.yml b/.kitchen.yml index 66a424c..5549e42 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -14,4 +14,4 @@ platforms: suites: - name: default run_list: - - recipe[replace_cookbook::default] + - recipe[makenew-chef_cookbook::default] diff --git a/README.md b/README.md index 945ac48..d51e186 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,89 @@ -# Chef Skeleton Cookbook +# Chef Cookbook Skeleton -[![Apache 2.0 License](https://img.shields.io/github/license/makenew/chef-cookbook.svg)](./LICENSE.txt) -[![Dependency Status](https://img.shields.io/gemnasium/makenew/chef-cookbook.svg)](https://gemnasium.com/makenew/chef-cookbook) -[![Build Status](https://img.shields.io/travis/makenew/chef-cookbook.svg)](https://travis-ci.org/makenew/chef-cookbook) -[![Coverage Status](https://img.shields.io/codecov/c/github/makenew/chef-cookbook.svg)](https://codecov.io/github/makenew/chef-cookbook) +[Make New](https://makenew.github.io/) +[![Chef cookbook](https://img.shields.io/cookbook/v/makenew-chef_cookbook.svg)](https://supermarket.chef.io/cookbooks/makenew-chef_cookbook) +[![GitHub license](https://img.shields.io/github/license/makenew/chef-cookbook.svg)](./LICENSE.txt) +[![Gemnasium](https://img.shields.io/gemnasium/makenew/chef-cookbook.svg)](https://gemnasium.com/makenew/chef-cookbook) +[![Travis](https://img.shields.io/travis/makenew/chef-cookbook.svg)](https://travis-ci.org/makenew/chef-cookbook) +[![Codecov](https://img.shields.io/codecov/c/github/makenew/chef-cookbook.svg)](https://codecov.io/github/makenew/chef-cookbook) -Use this project freely as a base for your testable [Chef] cookbooks. +## Description -[Chef]: https://www.chef.io/ +Bootstrap a new [Chef] cookbook in less than a minute. -## Description +[Chef]: https://www.chef.io/ ### Features -* Dependency management with [Berkshelf]. -* [Rake], [Thor], and [Guard] tasks for included tools. -* Documentation generation with [YARD] and [knife-cookbook-doc]. -* Linting with [RuboCop] and [Foodcritic]. -* Unit testing with [ChefSpec]. -* Integration testing with [Test Kitchen]. -* [Travis CI] ready. -* [EditorConfig]. -* Badges from [Shields.io]! - -[Berkshelf]: http://berkshelf.com/index.html +- Dependency management with [Bundler] and [Berkshelf]. +- [Rake], [Thor], and [Guard] tasks for included tools. +- Documentation generation with [YARD] and [knife-cookbook-doc]. +- Linting with [RuboCop] and [Foodcritic]. +- Unit testing with [ChefSpec]. +- Integration testing with [Test Kitchen]. +- Code coverage with [SimpleCov]. +- [Travis CI] ready. +- [Keep a CHANGELOG]. +- Consistent coding with [EditorConfig]. +- Badges from [Shields.io]. + +[Berkshelf]: http://berkshelf.com/ +[Bundler]: http://bundler.io/ [ChefSpec]: https://sethvargo.github.io/chefspec/ [EditorConfig]: http://editorconfig.org/ -[Foodcritic]: https://acrmp.github.io/foodcritic/ +[Foodcritic]: http://www.foodcritic.io/ [Guard]: http://guardgem.org/ -[knife-cookbook-doc]: https://github.com/realityforge/knife-cookbook-doc +[Keep a CHANGELOG]: http://keepachangelog.com/ +[knife-cookbook-doc]: http://realityforge.org/knife-cookbook-doc/ [Rake]: https://github.com/jimweirich/rake [RuboCop]: http://batsov.com/rubocop/ [Shields.io]: http://shields.io/ +[SimpleCov]: https://github.com/colszowka/simplecov [Test Kitchen]: http://kitchen.ci/ [Thor]: http://whatisthor.com/ [Travis CI]: https://travis-ci.org/ -[YARD]: http://yardoc.org/index.html +[YARD]: http://yardoc.org/ -### Usage +### Bootstrapping a New Project -This software can be used freely, see [The Unlicense]. -The Apache License text appearing in this software is for -demonstration purposes only and does not apply to this software. - -1. Clone this repository or download a [release][Releases]. - - The `master` branch can be used for making cookbooks under the Apache 2.0 License. - - The `copyright` branch can be used for making proprietary cookbooks. - -2. Customize `doc/*.md`. - - Do not edit `README.md` directly, - it will be generated from `_README.md.erb` - using data from `metadata.rb`, - and the `.md` files in `/doc`. - - Replace things marked with `replace_`. - - Customize your badges in `doc/badges.md`. - - Run `rake readme`. - -3. Everything else that should be filled in before using this skeleton - has been marked with the prefix `replace_`. - You can replace the placeholder cookbook name - and the copyright text with your own using +1. Clone the master branch of this repository with ``` - $ git ls-files -z | xargs -0 sed -i 's/replace_cookbook/your_cookbook/g' - $ git ls-files -z | xargs -0 sed -i 's/replace_yyyy/yyyy/g' - $ git ls-files -z | xargs -0 sed -i 's/replace_name_of_copyright_owner/name_of_copyright_owner/g' - $ git ls-files -z | xargs -0 sed -i 's/replace_username/your_username/g' - $ git ls-files -z | xargs -0 sed -i 's/replace_repo/your_repo/g' + $ git clone --single-branch https://github.com/makenew/chef-cookbook.git new-chef-cookbook + $ cd new-chef-cookbook ``` - To see a list of what else still needs to be replaced, run + Optionally, reset to the latest [release][Releases] with ``` - $ grep -R replace_ + $ git reset --hard chef-cookbook-v0.0.0 ``` -Note that `CHANGELOG.md` is just a template for this skeleton. -The actual changes for this project are documented in the commit history -and summarized under [Releases]. +2. Run + ``` + $ ./makenew.sh + ``` + + and follow the prompts. + This will replace the boilerplate, delete itself, + and stage changes for commit. + This script assumes the project repository will be hosted on GitHub. + For an alternative location, you must update the URLs manually. + +3. Fill in the README Description section. + +4. If [choosing a license][Choose a license] other than the one provided: + update `LICENSE.txt`, the README License section, + `metadata.rb`, `attributes/default.rb`, + and `recipes/default.rb` with your chosen license. + +5. Regenerate `README.md` with `$ rake readme`. + Do not edit `README.md` directly: it will be generated + from `_README.md.erb` using data from + `metadata.rb`, and the `.md` files in `/doc`. + +[Choose a license]: http://choosealicense.com/ [Releases]: https://github.com/makenew/chef-cookbook/releases [The Unlicense]: http://unlicense.org/UNLICENSE @@ -109,16 +114,109 @@ $ git fetch upstream $ git merge upstream/master ``` -## Source Code +#### Changelog -The [chef-cookbook source](https://github.com/makenew/chef-cookbook) -is hosted on GitHub. -To clone the project run +Note that `CHANGELOG.md` is just a template for this skeleton. +The actual changes for this project are documented in the commit history +and summarized under [Releases]. + +Chef cookbook skeleton. + +### Requirements + +- Chef 12. + +### Installation + +Add this as a dependency in your cookbook's `metadata.rb` with + +```ruby +depends 'makenew-chef_cookbook' +``` + +Alternatively, add this to your [Berksfile][Berkshelf] with + +```ruby +cookbook 'makenew-chef_cookbook' +``` + +and update your cookbooks with + +``` +$ berks +``` + +[Berkshelf]: http://berkshelf.com/ + +## Platform Support + +* ubuntu (~> 14.04) + +## Recipes + +* makenew-chef_cookbook::default - Default recipe. + +## Development and Testing + +### Requirements + +You will need [Ruby] with [Bundler]. + +[VirtualBox] and [Vagrant] are required +for integration testing with [Test Kitchen]. + +Install the development dependencies with + +``` +$ bundle +``` + +[Bundler]: http://bundler.io/ +[Ruby]: https://www.ruby-lang.org/ +[Test Kitchen]: http://kitchen.ci/ +[VirtualBox]: https://www.virtualbox.org/ + +### Source Code + +The [makenew-chef_cookbook source] is hosted on GitHub. +Clone the project with ``` $ git clone https://github.com/makenew/chef-cookbook.git ``` +[makenew-chef_cookbook source]: https://github.com/makenew/chef-cookbook + +### Rake + +Run `rake -T` to see all Rake tasks. + +``` +rake all # Run all tasks +rake doc # Build documentation +rake foodcritic # Lint Chef cookbooks +rake kitchen:all # Run all test instances +rake kitchen:default-ubuntu-1404 # Run default-ubuntu-1404 test instance +rake readme # Generate README.md from _README.md.erb +rake rubocop # Run RuboCop +rake rubocop:auto_correct # Auto-correct RuboCop offenses +rake spec # Run RSpec code examples +rake test # Run kitchen integration tests +rake yard # Generate YARD Documentation +``` + +### Thor + +Run `thor -T` to see all Thor tasks. + +### Guard + +Guard tasks have been separated into the following groups: +`doc`, `lint`, `unit`, and `integration`. + +By default, Guard will generate documentation, lint, and run unit tests. +The integration group must be selected manually with `guard -g integration`. + ## Contributing Please submit and comment on bug reports and feature requests. @@ -132,9 +230,25 @@ To submit a patch: 5. Push to the branch (`git push origin my-new-feature`). 6. Create a new Pull Request. +This software can be used freely, see [The Unlicense]. +The copyright text appearing below and elsewhere in this repository +is for demonstration purposes only and does not apply to this software. + ## License -This is free and unencumbered software released into the public domain. +Copyright 2016 Evan Sosenko + +Licensed 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 + +https://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. ## Warranty diff --git a/_README.md.erb b/_README.md.erb index 28f058e..72f1bca 100644 --- a/_README.md.erb +++ b/_README.md.erb @@ -1,8 +1,9 @@ -# replace_cookbook +# Chef Cookbook Skeleton <%= fragments['badges'] %> ## Description +<%= fragments['makenew'] %> <%= description %> <%= fragments['usage'] %> diff --git a/attributes/default.rb b/attributes/default.rb index 28763c3..f976d94 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -1,8 +1,8 @@ # -# Cookbook Name:: replace_cookbook +# Cookbook Name:: makenew-chef_cookbook # Attributes:: default # -# Copyright replace_yyyy replace_name_of_copyright_owner +# Copyright 2016 Evan Sosenko # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/doc/badges.md b/doc/badges.md index 1dc2715..618dd5d 100644 --- a/doc/badges.md +++ b/doc/badges.md @@ -1,5 +1,6 @@ -[![Chef cookbook](https://img.shields.io/cookbook/v/replace_cookbook.svg)](https://supermarket.chef.io/cookbooks/replace_cookbook) -[![GitHub license](https://img.shields.io/github/license/replace_username/replace_repo.svg)](./LICENSE.txt) -[![Gemnasium](https://img.shields.io/gemnasium/replace_username/replace_repo.svg)](https://gemnasium.com/replace_username/replace_repo) -[![Travis](https://img.shields.io/travis/replace_username/replace_repo.svg)](https://travis-ci.org/replace_username/replace_repo) -[![Codecov](https://img.shields.io/codecov/c/github/replace_username/replace_repo.svg)](https://codecov.io/github/replace_username/replace_repo) +[Make New](https://makenew.github.io/) +[![Chef cookbook](https://img.shields.io/cookbook/v/makenew-chef_cookbook.svg)](https://supermarket.chef.io/cookbooks/makenew-chef_cookbook) +[![GitHub license](https://img.shields.io/github/license/makenew/chef-cookbook.svg)](./LICENSE.txt) +[![Gemnasium](https://img.shields.io/gemnasium/makenew/chef-cookbook.svg)](https://gemnasium.com/makenew/chef-cookbook) +[![Travis](https://img.shields.io/travis/makenew/chef-cookbook.svg)](https://travis-ci.org/makenew/chef-cookbook) +[![Codecov](https://img.shields.io/codecov/c/github/makenew/chef-cookbook.svg)](https://codecov.io/github/makenew/chef-cookbook) diff --git a/doc/contributing.md b/doc/contributing.md index b34fb4b..ce3aaf3 100644 --- a/doc/contributing.md +++ b/doc/contributing.md @@ -4,7 +4,7 @@ Please submit and comment on bug reports and feature requests. To submit a patch: -1. Fork it (https://github.com/replace_username/replace_repo/fork). +1. Fork it (https://github.com/makenew/chef-cookbook/fork). 2. Create your feature branch (`git checkout -b my-new-feature`). 3. Make changes. Write and run tests. 4. Commit your changes (`git commit -am 'Add some feature'`). diff --git a/doc/license.md b/doc/license.md index be03261..291b917 100644 --- a/doc/license.md +++ b/doc/license.md @@ -1,6 +1,10 @@ +This software can be used freely, see [The Unlicense]. +The copyright text appearing below and elsewhere in this repository +is for demonstration purposes only and does not apply to this software. + ## License -Copyright replace_yyyy replace_name_of_copyright_owner +Copyright 2016 Evan Sosenko Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/doc/makenew.md b/doc/makenew.md new file mode 100644 index 0000000..b89f941 --- /dev/null +++ b/doc/makenew.md @@ -0,0 +1,110 @@ +Bootstrap a new [Chef] cookbook in less than a minute. + +[Chef]: https://www.chef.io/ + +### Features + +- Dependency management with [Bundler] and [Berkshelf]. +- [Rake], [Thor], and [Guard] tasks for included tools. +- Documentation generation with [YARD] and [knife-cookbook-doc]. +- Linting with [RuboCop] and [Foodcritic]. +- Unit testing with [ChefSpec]. +- Integration testing with [Test Kitchen]. +- Code coverage with [SimpleCov]. +- [Travis CI] ready. +- [Keep a CHANGELOG]. +- Consistent coding with [EditorConfig]. +- Badges from [Shields.io]. + +[Berkshelf]: http://berkshelf.com/ +[Bundler]: http://bundler.io/ +[ChefSpec]: https://sethvargo.github.io/chefspec/ +[EditorConfig]: http://editorconfig.org/ +[Foodcritic]: http://www.foodcritic.io/ +[Guard]: http://guardgem.org/ +[Keep a CHANGELOG]: http://keepachangelog.com/ +[knife-cookbook-doc]: http://realityforge.org/knife-cookbook-doc/ +[Rake]: https://github.com/jimweirich/rake +[RuboCop]: http://batsov.com/rubocop/ +[Shields.io]: http://shields.io/ +[SimpleCov]: https://github.com/colszowka/simplecov +[Test Kitchen]: http://kitchen.ci/ +[Thor]: http://whatisthor.com/ +[Travis CI]: https://travis-ci.org/ +[YARD]: http://yardoc.org/ + +### Bootstrapping a New Project + +1. Clone the master branch of this repository with + + ``` + $ git clone --single-branch https://github.com/makenew/chef-cookbook.git new-chef-cookbook + $ cd new-chef-cookbook + ``` + + Optionally, reset to the latest [release][Releases] with + + ``` + $ git reset --hard chef-cookbook-v0.0.0 + ``` + +2. Run + + ``` + $ ./makenew.sh + ``` + + and follow the prompts. + This will replace the boilerplate, delete itself, + and stage changes for commit. + This script assumes the project repository will be hosted on GitHub. + For an alternative location, you must update the URLs manually. + +3. Fill in the README Description section. + +4. If [choosing a license][Choose a license] other than the one provided: + update `LICENSE.txt`, the README License section, + `metadata.rb`, `attributes/default.rb`, + and `recipes/default.rb` with your chosen license. + +5. Regenerate `README.md` with `$ rake readme`. + Do not edit `README.md` directly: it will be generated + from `_README.md.erb` using data from + `metadata.rb`, and the `.md` files in `/doc`. + +[Choose a license]: http://choosealicense.com/ +[Releases]: https://github.com/makenew/chef-cookbook/releases +[The Unlicense]: http://unlicense.org/UNLICENSE + +### Updating + +If you want to pull in future updates from this skeleton, +you can fetch and merge in changes from this repository. + +If this repository is already set as `origin`, +rename it to `upstream` with + +``` +$ git remote rename origin upstream +``` + +and then configure your `origin` branch as normal. + +Otherwise, add this as a new remote with + +``` +$ git remote add upstream https://github.com/makenew/chef-cookbook.git +``` + +You can then fetch and merge changes with + +``` +$ git fetch upstream +$ git merge upstream/master +``` + +#### Changelog + +Note that `CHANGELOG.md` is just a template for this skeleton. +The actual changes for this project are documented in the commit history +and summarized under [Releases]. diff --git a/doc/source.md b/doc/source.md index 2044b45..97e55f8 100644 --- a/doc/source.md +++ b/doc/source.md @@ -1,10 +1,10 @@ ### Source Code -The [replace_cookbook source] is hosted on GitHub. +The [makenew-chef_cookbook source] is hosted on GitHub. Clone the project with ``` -$ git clone https://github.com/replace_username/replace_repo.git +$ git clone https://github.com/makenew/chef-cookbook.git ``` -[replace_cookbook source]: https://github.com/replace_username/replace_repo +[makenew-chef_cookbook source]: https://github.com/makenew/chef-cookbook diff --git a/doc/usage.md b/doc/usage.md index a6dd005..7ac66cd 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -7,13 +7,13 @@ Add this as a dependency in your cookbook's `metadata.rb` with ```ruby -depends 'makenew-chef_cookboook' +depends 'makenew-chef_cookbook' ``` Alternatively, add this to your [Berksfile][Berkshelf] with ```ruby -cookbook 'makenew-chef_cookboook' +cookbook 'makenew-chef_cookbook' ``` and update your cookbooks with diff --git a/makenew.sh b/makenew.sh new file mode 100755 index 0000000..6f68061 --- /dev/null +++ b/makenew.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env sh + +set -e +set -u + +find_replace () { + git ls-files -z | xargs -0 sed -i "$1" +} + +check_env () { + test -d .git || (echo 'This is not a Git repository. Exiting.' && exit 1) + for cmd in ${1}; do + command -v ${cmd} >/dev/null 2>&1 || \ + (echo "Could not find '$cmd' which is required to continue." && exit 2) + done + echo + echo 'Ready to bootstrap your new project!' + echo +} + +stage_env () { + echo + git rm -f makenew.sh + echo + echo 'Staging changes.' + git add --all + echo + echo 'Done!' + echo +} + +makenew () { + read -p '> Cookbook title: ' mk_title + read -p '> Cookbook name (slug): ' mk_slug + read -p '> Short cookbook description: ' mk_description + read -p '> Version number: ' mk_version + read -p '> Maintainer name: ' mk_author + read -p '> Maintainer email: ' mk_email + read -p '> Copyright owner: ' mk_owner + read -p '> Copyright year: ' mk_year + read -p '> GitHub user or organization name: ' mk_user + read -p '> GitHub repository name: ' mk_repo + + sed -i -e '6d' _README.md.erb + sed -i -e '1d' doc/badges.md + sed -i -e '8d' metadata.rb + + find_replace "s/0\.0\.0\.\.\./${mk_version}.../g" + find_replace "s/Chef Cookbook Skeleton/${mk_title}/g" + find_replace "s/Chef cookbook skeleton./${mk_description}/g" + find_replace "s/2016 Evan Sosenko/${mk_year} ${mk_owner}/g" + find_replace "s/Evan Sosenko/${mk_author}/g" + find_replace "s/razorx@evansosenko\.com/${mk_email}/g" + find_replace "s/makenew\/chef-cookbook/${mk_user}\/${mk_repo}/g" + find_replace "s/makenew-chef_cookbook/${mk_slug}/g" + find_replace "s/cd chef-cookbook/cd ${mk_repo}/g" + + sed -i -e "8i version '${mk_version}'" metadata.rb + + mk_attribution='> Make New Built from [makenew/chef-cookbook](https://github.com/makenew/chef-cookbook).' + echo "" >> doc/badges.md + echo "${mk_attribution}" >> doc/badges.md + + rm doc/makenew.md + + echo + echo 'Replacing boilerplate.' +} + +check_env 'git read sed xargs' +makenew +stage_env +exit diff --git a/metadata.rb b/metadata.rb index 01fcac6..357735a 100644 --- a/metadata.rb +++ b/metadata.rb @@ -1,12 +1,12 @@ -name 'replace_cookbook' -maintainer 'replace_your_name' -maintainer_email 'replace_email@example.com' +name 'makenew-chef_cookbook' +maintainer 'Evan Sosenko' +maintainer_email 'razorx@evansosenko.com' license 'Apache 2.0' -description 'replace_description.' -source_url 'https://github.com/replace_username/replace_repo' -issues_url 'https://github.com/replace_username/replace_repo/issues' +description 'Chef cookbook skeleton.' +source_url 'https://github.com/makenew/chef-cookbook' +issues_url 'https://github.com/makenew/chef-cookbook/issues' version '0.0.0' supports 'ubuntu', '~> 14.04' -recipe 'replace_cookbook::default', 'replace_description.' +recipe 'makenew-chef_cookbook::default', 'Default recipe.' diff --git a/recipes/default.rb b/recipes/default.rb index e294483..903cff1 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -1,8 +1,8 @@ # -# Cookbook Name:: replace_cookbook +# Cookbook Name:: makenew-chef_cookbook # Recipe:: default # -# Copyright replace_yyyy replace_name_of_copyright_owner +# Copyright 2016 Evan Sosenko # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 181ce7f..12d9a10 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -1,8 +1,8 @@ require 'spec_helper' -describe 'replace_cookbook::default' do +describe 'makenew-chef_cookbook::default' do let(:chef_run) { ChefSpec::ServerRunner.new.converge(described_recipe) } - it 'replace_does_something' do + it 'does nothing' do end end diff --git a/test/integration/default/serverspec/default_spec.rb b/test/integration/default/serverspec/default_spec.rb index 0758460..a1e5bce 100644 --- a/test/integration/default/serverspec/default_spec.rb +++ b/test/integration/default/serverspec/default_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe 'replace_cookbook::default' do +describe 'makenew-chef_cookbook::default' do describe command('ls -al /') do its(:stdout) { should match(/bin/) } end