From c829c2521cc5114c8de6070a520fe4123dfb8166 Mon Sep 17 00:00:00 2001 From: Jonathan Hartman Date: Wed, 27 Apr 2016 09:43:17 -0700 Subject: [PATCH] Prepare a v0.1.0 --- .gitignore | 24 +++++ .kitchen.travis.yml | 6 ++ .kitchen.yml | 22 +++++ .travis.yml | 15 +++ Berksfile | 10 ++ CHANGELOG.md | 6 ++ CODE_OF_CONDUCT.md | 29 ++++++ Gemfile | 39 ++++++++ Guardfile | 28 ++++++ README.md | 90 +++++++++++++++++- Rakefile | 23 +++++ chefignore | 95 +++++++++++++++++++ libraries/matchers.rb | 27 ++++++ libraries/resource_airmail.rb | 45 +++++++++ metadata.rb | 16 ++++ recipes/default.rb | 21 ++++ spec/recipes/default_spec.rb | 17 ++++ spec/resources/airmail/mac_os_x/10_10_spec.rb | 30 ++++++ spec/spec_helper.rb | 25 +++++ .../resource_airmail_test/metadata.rb | 13 +++ .../resource_airmail_test/recipes/default.rb | 3 + .../default/serverspec/localhost/app_spec.rb | 17 ++++ .../default/serverspec/spec_helper.rb | 10 ++ 23 files changed, 609 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .kitchen.travis.yml create mode 100644 .kitchen.yml create mode 100644 .travis.yml create mode 100644 Berksfile create mode 100644 CHANGELOG.md create mode 100644 CODE_OF_CONDUCT.md create mode 100644 Gemfile create mode 100644 Guardfile create mode 100644 Rakefile create mode 100644 chefignore create mode 100644 libraries/matchers.rb create mode 100644 libraries/resource_airmail.rb create mode 100644 metadata.rb create mode 100644 recipes/default.rb create mode 100644 spec/recipes/default_spec.rb create mode 100644 spec/resources/airmail/mac_os_x/10_10_spec.rb create mode 100644 spec/spec_helper.rb create mode 100644 spec/support/cookbooks/resource_airmail_test/metadata.rb create mode 100644 spec/support/cookbooks/resource_airmail_test/recipes/default.rb create mode 100644 test/integration/default/serverspec/localhost/app_spec.rb create mode 100644 test/integration/default/serverspec/spec_helper.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f9fb076 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +.vagrant +Berksfile.lock +berks-cookbooks +*~ +*# +.#* +\#*# +.*.sw[a-z] +*.un~ + +# Sublime Text +*.sublime-project +*.sublime-workspace + +# Bundler +Gemfile.lock +bin/* +.bundle/* + +.kitchen/ +.kitchen.local.yml + +.env.sh +coverage diff --git a/.kitchen.travis.yml b/.kitchen.travis.yml new file mode 100644 index 0000000..12aabb8 --- /dev/null +++ b/.kitchen.travis.yml @@ -0,0 +1,6 @@ +--- +driver: + name: localhost + +platforms: + - name: macosx diff --git a/.kitchen.yml b/.kitchen.yml new file mode 100644 index 0000000..9f6ecf9 --- /dev/null +++ b/.kitchen.yml @@ -0,0 +1,22 @@ +--- +driver: + name: vagrant + +provisioner: + name: chef_zero + +platforms: + - name: macosx-10.10 + driver: + box: roboticcheese/macosx-10.10 + ssh: + insert_key: false + +suites: + - name: default + run_list: + - recipe[airmail] + attributes: + mac_app_store: + username: <%= ENV['APPLE_ID_USERNAME'] %> + password: <%= ENV['APPLE_ID_PASSWORD'] %> diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..67b7d34 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,15 @@ +language: objective-c + +branches: + only: + - master + +install: + - curl -L https://www.chef.io/chef/install.sh | sudo bash -s -- -P chefdk + - chef exec bundle install --without=development integration + +before_script: + - cp .kitchen.travis.yml .kitchen.local.yml + +script: + - chef exec rake diff --git a/Berksfile b/Berksfile new file mode 100644 index 0000000..561263e --- /dev/null +++ b/Berksfile @@ -0,0 +1,10 @@ +# Encoding: UTF-8 + +source 'https://supermarket.chef.io' + +metadata + +group :unit do + cookbook 'resource_airmail_test', + path: 'spec/support/cookbooks/resource_airmail_test' +end diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..7876805 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +Airmail Cookbook CHANGELOG +========================== + +v0.0.1 (2016-04-27) +------------------- +- Development started diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..84d571d --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,29 @@ +Airmail Contributor Code of Conduct +=================================== + +As contributors and maintainers of this project, we pledge to respect all +people who contribute through reporting issues, posting feature requests, +updating documentation, submitting pull requests or patches, and other +activities. + +We are committed to making participation in this project a harassment-free +experience for everyone, regardless of level of experience, gender, gender +identity and expression, sexual orientation, disability, personal appearance, +body size, race, age, or religion. + +Examples of unacceptable behavior by participants include the use of sexual +language or imagery, derogatory comments or personal attacks, trolling, public +or private harassment, insults, or other unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct. Project maintainers who do not +follow the Code of Conduct may be removed from the project team. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by opening an issue or contacting one or more of the project +maintainers. + +This Code of Conduct is adapted from the +[Contributor Covenant](http://contributor-covenant.org), version 1.0.0, +available [here](http://contributor-covenant.org/version/1/0/0/). diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..f557bd5 --- /dev/null +++ b/Gemfile @@ -0,0 +1,39 @@ +# Encoding: UTF-8 + +source 'https://rubygems.org' + +group :development do + gem 'yard-chef' + gem 'guard' + gem 'guard-foodcritic' + gem 'guard-rspec' + gem 'guard-kitchen' +end + +group :test do + gem 'rake' + gem 'rubocop' + gem 'foodcritic' + gem 'rspec' + gem 'chefspec' + gem 'simplecov' + gem 'simplecov-console' + gem 'coveralls' + gem 'fauxhai' + gem 'test-kitchen' + gem 'kitchen-localhost' + gem 'kitchen-vagrant' +end + +group :integration do + gem 'serverspec' +end + +group :deploy do + gem 'stove' +end + +group :production do + gem 'chef', '>= 12.5' + gem 'berkshelf' +end diff --git a/Guardfile b/Guardfile new file mode 100644 index 0000000..75bca0f --- /dev/null +++ b/Guardfile @@ -0,0 +1,28 @@ +# Encoding: UTF-8 + +guard :rspec, all_on_start: true, notification: false do + watch(%r{^spec/.+_spec\.rb$}) + watch('spec/spec_helper.rb') { 'spec' } + + watch(%r{^recipes/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch(%r{^attributes/(.+)\.rb$}) + watch(%r{^files/(.+)}) + watch(%r{^templates/(.+)}) + watch(%r{^providers/(.+)\.rb}) + watch(%r{^resources/(.+)\.rb}) + watch(%r{^libraries/(.+)\.rb}) +end + +# guard :foodcritic, cookbook_paths: '.', cli: '-t ~FC023 -f any' do +# watch(/^.*\.rb$/) +# end + +# guard :kitchen do +# watch(/test\/.+/) +# watch(/^recipes\/(.+)\.rb$/) +# watch(/^attributes\/(.+)\.rb$/) +# watch(/^files\/(.+)/) +# watch(/^templates\/(.+)/) +# watch(/^providers\/(.+)\.rb/) +# watch(/^resources\/(.+)\.rb/) +# end diff --git a/README.md b/README.md index 9da1389..3259d58 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,88 @@ -# airmail-chef -A Chef cookbook for the Airmail app +Airmail Cookbook +================ +[![Cookbook Version](https://img.shields.io/cookbook/v/airmail.svg)][cookbook] +[![Build Status](https://img.shields.io/travis/roboticcheese/airmail-chef.svg)][travis] +[![Code Climate](https://img.shields.io/codeclimate/github/roboticcheese/airmail-chef.svg)][codeclimate] +[![Coverage Status](https://img.shields.io/coveralls/roboticcheese/airmail-chef.svg)][coveralls] + +[cookbook]: https://supermarket.chef.io/cookbooks/airmail +[travis]: https://travis-ci.org/roboticcheese/airmail-chef +[codeclimate]: https://codeclimate.com/github/roboticcheese/airmail-chef +[coveralls]: https://coveralls.io/r/roboticcheese/airmail-chef + +A Chef cookbook to install the Airmail app. + +Requirements +============ + +This cookbook offers a recipe-based and a resource-based install. Use of the +resource requires that you open a `mac_app_store` resource prior in your Chef +run. + +This cookbook requires Chef 12.5 or newer. + +Usage +===== + +Either add the default recipe to your run_list, or implement the resource in +a recipe of your own. + +Recipes +======= + +***default*** + +Opens the Mac App Store and performs a simple install of the app. + +Resources +========= + +***airmail*** + +Used to perform installation of the app. + +Syntax: + + airmail 'default' do + action :install + end + +Actions: + +| Action | Description | +|------------|-----------------| +| `:install` | Install the app | + +Attributes: + +| Attribute | Default | Description | +|------------|----------------|----------------------| +| action | `:install` | Action(s) to perform | + +Contributing +============ + +1. Fork it +2. Create your feature branch (`git checkout -b my-new-feature`) +3. Add tests for the new feature; ensure they pass (`rake`) +4. Commit your changes (`git commit -am 'Add some feature'`) +5. Push to the branch (`git push origin my-new-feature`) +6. Create a new Pull Request + +License & Authors +================= +- Author: Jonathan Hartman + +Copyright 2016, Jonathan Hartman + +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 + + 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. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..1d99b95 --- /dev/null +++ b/Rakefile @@ -0,0 +1,23 @@ +# Encoding: UTF-8 + +require 'rubygems' +require 'bundler/setup' +require 'rubocop/rake_task' +require 'rspec/core/rake_task' +require 'foodcritic' +require 'kitchen/rake_tasks' +require 'stove/rake_task' + +RuboCop::RakeTask.new + +FoodCritic::Rake::LintTask.new do |f| + f.options = { fail_tags: %w(any) } +end + +RSpec::Core::RakeTask.new(:spec) + +Kitchen::RakeTasks.new + +Stove::RakeTask.new + +task default: %w(rubocop foodcritic spec) diff --git a/chefignore b/chefignore new file mode 100644 index 0000000..80dc2d2 --- /dev/null +++ b/chefignore @@ -0,0 +1,95 @@ +# Put files/directories that should be ignored in this file when uploading +# or sharing to the community site. +# Lines that start with '# ' are comments. + +# OS generated files # +###################### +.DS_Store +Icon? +nohup.out +ehthumbs.db +Thumbs.db + +# SASS # +######## +.sass-cache + +# EDITORS # +########### +\#* +.#* +*~ +*.sw[a-z] +*.bak +REVISION +TAGS* +tmtags +*_flymake.* +*_flymake +*.tmproj +.project +.settings +mkmf.log + +## COMPILED ## +############## +a.out +*.o +*.pyc +*.so +*.com +*.class +*.dll +*.exe +*/rdoc/ + +# Testing # +########### +.watchr +.rspec +spec/* +spec/fixtures/* +test/* +features/* +Guardfile +Procfile + +# SCM # +####### +.git +*/.git +.gitignore +.gitmodules +.gitconfig +.gitattributes +.svn +*/.bzr/* +*/.hg/* +*/.svn/* + +# Berkshelf # +############# +Berksfile +Berksfile.lock +cookbooks/* +tmp + +# Cookbooks # +############# +CONTRIBUTING + +# Strainer # +############ +Colanderfile +Strainerfile +.colander +.strainer + +# Vagrant # +########### +.vagrant +Vagrantfile + +# Travis # +########## +.travis.yml diff --git a/libraries/matchers.rb b/libraries/matchers.rb new file mode 100644 index 0000000..3fd8627 --- /dev/null +++ b/libraries/matchers.rb @@ -0,0 +1,27 @@ +# Encoding: UTF-8 +# +# Cookbook Name:: airmail +# Library:: matchers +# +# Copyright 2015 Jonathan Hartman +# +# 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 +# +# 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. +# + +if defined?(ChefSpec) + ChefSpec.define_matcher(:airmail) + + def install_airmail(name) + ChefSpec::Matchers::ResourceMatcher.new(:airmail, :install, name) + end +end diff --git a/libraries/resource_airmail.rb b/libraries/resource_airmail.rb new file mode 100644 index 0000000..c1f034a --- /dev/null +++ b/libraries/resource_airmail.rb @@ -0,0 +1,45 @@ +# Encoding: UTF-8 +# +# Cookbook Name:: airmail +# Library:: resource_airmail +# +# Copyright 2016, Jonathan Hartman +# +# 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 +# +# 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. +# + +require 'chef/resource' + +class Chef + class Resource + # A Chef custom resource for the Airmail app. + # + # @author Jonathan Hartman + class Airmail < Resource + provides :airmail, platform_family: 'mac_os_x' + + default_action :install + + Chef::Resource::MacAppStoreApp.allowed_actions.each do |a| + action a do + include_recipe 'mac-app-store' unless a == :nothing + + mac_app_store_app 'Airmail 2.6' do + bundle_id 'it.bloop.airmail2' + action a + end + end + end + end + end +end diff --git a/metadata.rb b/metadata.rb new file mode 100644 index 0000000..d6e75cf --- /dev/null +++ b/metadata.rb @@ -0,0 +1,16 @@ +# Encoding: UTF-8 + +name 'airmail' +maintainer 'Jonathan Hartman' +maintainer_email 'j@p4nt5.com' +license 'apache2' +description 'Installs Airmail' +long_description 'Installs Airmail' +version '0.0.1' + +source_url 'https://github.com/roboticcheese/airmail-chef' +issues_url 'https://github.com/roboticcheese/airmail-chef/issues' + +depends 'mac-app-store', '~> 1.0' + +supports 'mac_os_x' diff --git a/recipes/default.rb b/recipes/default.rb new file mode 100644 index 0000000..d8a96db --- /dev/null +++ b/recipes/default.rb @@ -0,0 +1,21 @@ +# Encoding: UTF-8 +# +# Cookbook Name:: airmail +# Recipe:: default +# +# Copyright 2016, Jonathan Hartman +# +# 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 +# +# 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. +# + +airmail 'default' diff --git a/spec/recipes/default_spec.rb b/spec/recipes/default_spec.rb new file mode 100644 index 0000000..7237aae --- /dev/null +++ b/spec/recipes/default_spec.rb @@ -0,0 +1,17 @@ +# Encoding: UTF-8 + +require 'spec_helper' + +describe 'airmail::default' do + let(:platform) { nil } + let(:runner) { ChefSpec::SoloRunner.new(platform) } + let(:chef_run) { runner.converge(described_recipe) } + + context 'Mac OS X platform' do + let(:platform) { { platform: 'mac_os_x', version: '10.10' } } + + it 'installs the Airmail app' do + expect(chef_run).to install_airmail('default') + end + end +end diff --git a/spec/resources/airmail/mac_os_x/10_10_spec.rb b/spec/resources/airmail/mac_os_x/10_10_spec.rb new file mode 100644 index 0000000..33c7852 --- /dev/null +++ b/spec/resources/airmail/mac_os_x/10_10_spec.rb @@ -0,0 +1,30 @@ +require_relative '../../../spec_helper' + +describe 'resource_airmail::mac_os_x::10_10' do + let(:action) { nil } + let(:runner) do + ChefSpec::SoloRunner.new(step_into: 'airmail', + platform: 'mac_os_x', + version: '10.10') + end + let(:chef_run) do + runner.converge("resource_airmail_test::#{action}") + end + + context 'the default action (:install)' do + let(:action) { :default } + + it 'configures the Mac App Store' do + expect(chef_run).to include_recipe('mac-app-store') + end + + it 'installs the Airmail app' do + expect(chef_run).to install_airmail('default') + end + + it 'installs via the App Store' do + expect(chef_run).to install_mac_app_store_app('Airmail 2.6') + .with(bundle_id: 'it.bloop.airmail2') + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..fd56c47 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,25 @@ +# Encoding: UTF-8 + +require 'chef' +require 'chefspec' +require 'chefspec/berkshelf' +require 'simplecov' +require 'simplecov-console' +require 'coveralls' +require_relative '../libraries/matchers' + +RSpec.configure do |c| + c.color = true +end + +SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( + [ + Coveralls::SimpleCov::Formatter, + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::Console + ] +) +SimpleCov.minimum_coverage(100) +SimpleCov.start + +at_exit { ChefSpec::Coverage.report! } diff --git a/spec/support/cookbooks/resource_airmail_test/metadata.rb b/spec/support/cookbooks/resource_airmail_test/metadata.rb new file mode 100644 index 0000000..a1ebafd --- /dev/null +++ b/spec/support/cookbooks/resource_airmail_test/metadata.rb @@ -0,0 +1,13 @@ +# Encoding: UTF-8 + +name 'resource_airmail_test' +maintainer 'Jonathan Hartman' +maintainer_email 'j@p4nt5.com' +license 'apache2' +description 'Resource test wrapper' +long_description 'Resource test wrapper' +version '0.0.1' + +depends 'airmail' + +supports 'mac_os_x' diff --git a/spec/support/cookbooks/resource_airmail_test/recipes/default.rb b/spec/support/cookbooks/resource_airmail_test/recipes/default.rb new file mode 100644 index 0000000..982ec3f --- /dev/null +++ b/spec/support/cookbooks/resource_airmail_test/recipes/default.rb @@ -0,0 +1,3 @@ +# Encoding: UTF-8 + +airmail 'default' diff --git a/test/integration/default/serverspec/localhost/app_spec.rb b/test/integration/default/serverspec/localhost/app_spec.rb new file mode 100644 index 0000000..4338601 --- /dev/null +++ b/test/integration/default/serverspec/localhost/app_spec.rb @@ -0,0 +1,17 @@ +# Encoding: UTF-8 + +require_relative '../spec_helper' + +describe 'airmail::default::app' do + describe package('it.bloop.airmail2') do + it 'is installed' do + expect(subject).to be_installed.by(:pkgutil) + end + end + + describe file('/Applications/Airmail 2.app') do + it 'is present on the filesystem' do + expect(subject).to be_directory + end + end +end diff --git a/test/integration/default/serverspec/spec_helper.rb b/test/integration/default/serverspec/spec_helper.rb new file mode 100644 index 0000000..04da6e6 --- /dev/null +++ b/test/integration/default/serverspec/spec_helper.rb @@ -0,0 +1,10 @@ +# Encoding: UTF-8 + +require 'serverspec' + +if RUBY_PLATFORM =~ /mswin|mingw32|windows/ + set :os, family: 'windows' + set :backend, :cmd +else + set :backend, :exec +end