From a3c7c48a728c3385010468db1348f0fb37750565 Mon Sep 17 00:00:00 2001 From: Nielsen Ramon Date: Tue, 24 Nov 2015 09:14:08 +0100 Subject: [PATCH] Move to circle CI --- .travis.yml | 10 ---- README.md | 41 +++++---------- circle.yml | 16 ++++++ lib/kickster/install.rb | 5 ++ lib/kickster/version.rb | 2 +- snippets/automated | 41 --------------- snippets/circle/automated | 43 ++++++++++++++++ snippets/circle/circle.yml | 21 ++++++++ snippets/{ => travis}/.travis.yml | 0 snippets/travis/README.md | 47 ++++++++++++++++++ snippets/travis/automated | 45 +++++++++++++++++ template/.travis.yml | 11 ---- template/Gemfile | 4 +- template/_assets/images/.keep | 0 .../{ => _assets/images}/apple-touch-icon.png | Bin template/_config.yml.tt | 1 + template/_layouts/default.html | 2 +- template/bin/deploy | 26 +++++----- template/bin/setup | 4 +- template/circle.yml | 12 +++++ 20 files changed, 221 insertions(+), 110 deletions(-) delete mode 100644 .travis.yml create mode 100644 circle.yml delete mode 100755 snippets/automated create mode 100755 snippets/circle/automated create mode 100644 snippets/circle/circle.yml rename snippets/{ => travis}/.travis.yml (100%) create mode 100644 snippets/travis/README.md create mode 100755 snippets/travis/automated delete mode 100644 template/.travis.yml delete mode 100644 template/_assets/images/.keep rename template/{ => _assets/images}/apple-touch-icon.png (100%) create mode 100644 template/circle.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 6ae7c99..0000000 --- a/.travis.yml +++ /dev/null @@ -1,10 +0,0 @@ -language: ruby -rvm: -- 2.2.3 -branches: - except: - - gh-pages - - website -notifications: - email: false -script: 'bundle install' diff --git a/README.md b/README.md index 74beb03..470b383 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ Setup your environment: bin/setup +Don't forget to enable your repository on [Circle CI](https://circleci.com/docs/getting-started)! + *If you do not want the Kickster files but just the deploy then copy the `bin/deploy` script to your repo and your ready to go.* ## Development @@ -30,10 +32,10 @@ Run Jekyll: Used tools: - [Autoprefixer](https://github.com/postcss/autoprefixer) - [Bower](http://bower.io/) + - [Circle CI](https://circleci.com/) - [Jekyll](http://jekyllrb.com/) - [Jekyll assets](https://github.com/jekyll/jekyll-assets) - [HTML5 Boilerplate](https://html5boilerplate.com/) (Influenced by) - - [Travis CI](http://travis-ci.org) ## Manual deploy to GitHub Pages @@ -43,7 +45,7 @@ Run this in the root project folder in your console: That's it, enjoy your nicely build project on GitHub pages! -## Automated deployment with TravisCI +## Automated deployment with Circle CI Automated deployment is by default not included in your Kickster generated Jekyll project. Please follow the steps below to include automated deployment. @@ -51,39 +53,22 @@ Automated deployment is by default not included in your Kickster generated Jekyl #### 1. Copy the required automated deploy script -Copy the [automated](https://github.com/nielsenramon/kickster/blob/master/snippets/automated) script inside the `/bin` folder of your project. - -#### 2. Update `.travis.yml` - -Replace your `.travis.yml` file with [this](https://github.com/nielsenramon/kickster/blob/master/snippets/.travis.yml) one. -And adjust the following 2 lines with your information: - - - USERNAME: - - EMAIL: - -#### 3. Create a personal access token - -This is required to push to the GitHub repo from a script. - -In GitHub go to `settings > Personal access tokens` and create a new one. -First give it a proper name so it is easy to recognize later. Then check `repo` (check `public_repo` if it is a public repository) and click on create. - -Screenshot of token generation in GitHub +Copy the [automated](https://github.com/nielsenramon/kickster/blob/master/snippets/circle/automated) script inside the `/bin` folder of your project (check if the file has execute permissions!). -Copy the generated token. +#### 2. Update `circle.yml` -*Don't forget to enable your repository in [Travis CI](https://travis-ci.org/)* +Replace your `circle.yml` file with [this](https://github.com/nielsenramon/kickster/blob/master/snippets/circle/circle.yml) one. And adjust the following 2 lines with your information: -Go back to your project in terminal and input the following: + - USER_NAME: + - USER_EMAIL: - gem install travis - travis encrypt GITHUB_TOKEN=secret-token-from-github --add +#### 3. Enable Circle CI. -This added a line inside your `.travis.yml' file like this: +Make sure you enable your repository in Circle CI. In Circle CI go to `Project settings > Checkout SSH Keys` and create a new User key. This is required to push to the GitHub repo from a script (permissions). - secure: +Screenshot of user key creating in Circle CI -That's it, enjoy your automated deployments from now on! +That's it, start pushing changes and enjoy your automated deployments from now on! ## License diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..1107200 --- /dev/null +++ b/circle.yml @@ -0,0 +1,16 @@ +machine: + ruby: + version: 2.2.3 + +dependencies: + pre: + - gem build kickster.gemspec + - gem install kickster + +test: + override: + - kickster new test + - ls -al + - cd test && bin/setup + - cd test && bundle exec jekyll build + - cd test && bundle exec htmlproof ./_site --only-4xx --href-ignore "#" diff --git a/lib/kickster/install.rb b/lib/kickster/install.rb index e019058..b0e4d63 100644 --- a/lib/kickster/install.rb +++ b/lib/kickster/install.rb @@ -34,6 +34,11 @@ def copy_templates directory("./", "./#{snake_name}") end + def grant_permissions + chmod "./#{snake_name}/bin/deploy", 0755 + chmod "./#{snake_name}/bin/setup", 0755 + end + def report_success say "Kickster template folder successfully created!", :green end diff --git a/lib/kickster/version.rb b/lib/kickster/version.rb index fbbd0df..dc6aad3 100644 --- a/lib/kickster/version.rb +++ b/lib/kickster/version.rb @@ -1,3 +1,3 @@ module Kickster - VERSION = "1.0.4" + VERSION = "1.1.0" end diff --git a/snippets/automated b/snippets/automated deleted file mode 100755 index 51accac..0000000 --- a/snippets/automated +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -ORIGIN_URL=`git config --get remote.origin.url` -ORIGIN_CREDENTIALS=${ORIGIN_URL/\/\/github.com/\/\/$GITHUB_TOKEN@github.com} -COMMIT_MESSAGE=$(git log -1 --pretty=%B) - -echo "Started deploying to the gh-pages branch." - -echo "Creating clean gh-pages branch." -if [ `git branch | grep gh-pages` ] -then - git branch -D gh-pages -fi -git checkout -b gh-pages - -echo "Building site." -bower install -bundle exec jekyll build --destination temp || exit 1 - -echo "Removing old files" -find . -maxdepth 1 ! -name 'temp' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \; - -mv temp/* . || exit 1 -rm -R temp/ || exit 1 - -echo "Pushing content" -git config user.name "$USERNAME" -git config user.email "$EMAIL" - -git add -fA || exit 1 -git commit --allow-empty -m "$COMMIT_MESSAGE" || exit 1 - -git push -f -q "$ORIGIN_CREDENTIALS" gh-pages > /dev/null 2>&1 - -echo "Deployed Successfully" - -echo "Checking out previous branch" -git checkout - -bower install - -exit 0 diff --git a/snippets/circle/automated b/snippets/circle/automated new file mode 100755 index 0000000..13f60a7 --- /dev/null +++ b/snippets/circle/automated @@ -0,0 +1,43 @@ +#!/bin/bash + +# Automated deploy script with Circle CI. + +# Exit if any subcommand fails. +set -e + +# Variables +ORIGIN_URL=`git config --get remote.origin.url` + +echo "Started deploying" + +# Checkout gh-pages branch. +if [ `git branch | grep gh-pages` ] +then + git branch -D gh-pages +fi +git checkout -b gh-pages + +# Build site. +bower install +bundle exec jekyll build + +# Delete and move files. +find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \; +mv _site/* . +rm -R _site/ + +# Push to gh-pages. +git config user.name "$USER_NAME" +git config user.email "$USER_EMAIL" + +git add -fA +git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]" +git push -f $ORIGIN_URL gh-pages + +# Move back to previous branch. +git checkout - +bower install + +echo "Deployed Successfully!" + +exit 0 diff --git a/snippets/circle/circle.yml b/snippets/circle/circle.yml new file mode 100644 index 0000000..2d28e0f --- /dev/null +++ b/snippets/circle/circle.yml @@ -0,0 +1,21 @@ +machine: + environment: + USER_NAME: + USER_EMAIL: + ruby: + version: 2.2.3 + +dependencies: + pre: + - ./bin/setup + +test: + post: + - bundle exec jekyll build + - bundle exec htmlproof ./_site --only-4xx --href-ignore "#" + +deployment: + production: + branch: master + commands: + - ./bin/automated diff --git a/snippets/.travis.yml b/snippets/travis/.travis.yml similarity index 100% rename from snippets/.travis.yml rename to snippets/travis/.travis.yml diff --git a/snippets/travis/README.md b/snippets/travis/README.md new file mode 100644 index 0000000..5aad959 --- /dev/null +++ b/snippets/travis/README.md @@ -0,0 +1,47 @@ +Automated deploy with Travis CI +=============================== + +Kickster can also work with [Travis CI](https://travis-ci.org/), follow the steps below to set it up. + +## Automated deployment with TravisCI + +Automated deployment is by default not included in your Kickster generated Jekyll project. Please follow the steps below to include automated deployment with travis. + +*Note that changes will only deploy when your code is merged into master.* + +#### 1. Copy the required automated deploy script + +Copy the [automated](https://github.com/nielsenramon/kickster/blob/master/snippets/travis/automated) script inside the `/bin` folder of your project (check if the file has execute permissions!). + +#### 2. Add `.travis.yml` + +Copy the `.travis.yml` from the [snippets](https://github.com/nielsenramon/kickster/blob/master/snippets/travis/.travis.yml) folder inside the `/bin` folder of your project(check if the file has execute permissions!). + +And adjust the following 2 lines with your information: + + - USERNAME: + - EMAIL: + +#### 3. Create a personal access token + +This is required to push to the GitHub repo from a script. + +In GitHub go to `settings > Personal access tokens` and create a new one. +First give it a proper name so it is easy to recognize later. Then check `repo` (check `public_repo` if it is a public repository) and click on create. + +Screenshot of token generation in GitHub + +Copy the generated token. + +*Don't forget to enable your repository in [Travis CI](https://travis-ci.org/)* + +Go back to your project in terminal and input the following: + + gem install travis + travis encrypt GITHUB_TOKEN=secret-token-from-github --add + +This added a line inside your `.travis.yml' file like this: + + secure: + +That's it, enjoy your automated deployments from now on! diff --git a/snippets/travis/automated b/snippets/travis/automated new file mode 100755 index 0000000..ed5e27c --- /dev/null +++ b/snippets/travis/automated @@ -0,0 +1,45 @@ +#!/bin/bash + +# Automated deploy script with Travis CI. + +# Exit if any subcommand fails. +set -e + +# Variables +ORIGIN_URL=`git config --get remote.origin.url` +ORIGIN_CREDENTIALS=${ORIGIN_URL/\/\/github.com/\/\/$GITHUB_TOKEN@github.com} +COMMIT_MESSAGE=$(git log -1 --pretty=%B) + +echo "Started deploying" + +# Checkout gh-pages branch. +if [ `git branch | grep gh-pages` ] +then + git branch -D gh-pages +fi +git checkout -b gh-pages + +# Build site. +bower install +bundle exec jekyll build + +# Delete and move files. +find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \; +mv _site/* . +rm -R _site/ + +# Push to gh-pages. +git config user.name "$USERNAME" +git config user.email "$EMAIL" + +git add -fA +git commit --allow-empty -m "$COMMIT_MESSAGE [ci skip]" +git push -f -q $ORIGIN_CREDENTIALS gh-pages + +# Move back to previous branch. +git checkout - +bower install + +echo "Deployed Successfully!" + +exit 0 diff --git a/template/.travis.yml b/template/.travis.yml deleted file mode 100644 index 71079b6..0000000 --- a/template/.travis.yml +++ /dev/null @@ -1,11 +0,0 @@ -language: ruby -rvm: -- 2.2.3 -install: -- ./bin/setup -script: -- bundle exec jekyll build --trace -- bundle exec htmlproof ./_site --only-4xx -env: - global: - - NOKOGIRI_USE_SYSTEM_LIBRARIES=true diff --git a/template/Gemfile b/template/Gemfile index cf98cdb..88fd825 100644 --- a/template/Gemfile +++ b/template/Gemfile @@ -1,9 +1,9 @@ source "https://rubygems.org" -gem "autoprefixer-rails", "~> 6.1.0.1" +gem "autoprefixer-rails", "~> 6.1.1" gem "html-proofer", "~> 2.5.2" gem "jekyll", "~> 3.0.1" -gem "jekyll-assets", "~> 2.0.2" +gem "jekyll-assets", "~> 2.0.3" gem "jekyll-sitemap", "~> 0.9.0" gem "sass", "~> 3.4.19" gem "uglifier", "~> 2.7.2" diff --git a/template/_assets/images/.keep b/template/_assets/images/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/template/apple-touch-icon.png b/template/_assets/images/apple-touch-icon.png similarity index 100% rename from template/apple-touch-icon.png rename to template/_assets/images/apple-touch-icon.png diff --git a/template/_config.yml.tt b/template/_config.yml.tt index e8986e9..4a5006e 100644 --- a/template/_config.yml.tt +++ b/template/_config.yml.tt @@ -13,6 +13,7 @@ exclude: - .travis.yml - bin/* - bower.json + - circle.yml - Gemfile - Gemfile.lock - README.md diff --git a/template/_layouts/default.html b/template/_layouts/default.html index ff45eff..fe000c4 100644 --- a/template/_layouts/default.html +++ b/template/_layouts/default.html @@ -19,7 +19,7 @@ - + {% stylesheet application %} diff --git a/template/bin/deploy b/template/bin/deploy index d5a56cf..fc3c85f 100755 --- a/template/bin/deploy +++ b/template/bin/deploy @@ -2,7 +2,7 @@ # Run this script to deploy the app to Github Pages. -# Exit if any subcommand fails +# Exit if any subcommand fails. set -e echo "Started deploying" @@ -12,28 +12,26 @@ if [ `git branch | grep gh-pages` ] then git branch -D gh-pages fi - git checkout -b gh-pages -# Generate site. +# Build site. bower install -bundle exec jekyll build --destination temp - -# Port everyting needed inside temp folder. -mkdir tmp -find . -maxdepth 1 ! -name 'temp' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \; +bundle exec jekyll build -# Move site to root and cleanup files. -mv temp/* . -rm -R temp/ +# Delete and move files. +find . -maxdepth 1 ! -name '_site' ! -name '.git' ! -name '.gitignore' -exec rm -rf {} \; +mv _site/* . +rm -R _site/ -# Push to gh-pages +# Push to gh-pages. git add -fA -git commit --allow-empty -m "$(git log -1 --pretty=%B)" +git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]" git push -f -q origin gh-pages -# Move back to previous branch +# Move back to previous branch. git checkout - bower install echo "Deployed Successfully!" + +exit 0 diff --git a/template/bin/setup b/template/bin/setup index 80e4508..c6c9e28 100755 --- a/template/bin/setup +++ b/template/bin/setup @@ -6,10 +6,10 @@ # Exit if any subcommand fails set -e -# Set up Ruby dependencies via Bundler +# Set up Ruby dependencies via Bundler. gem install bundler --conservative bundle check || bundle install -# Set up JS dependencies via Bower +# Set up JS dependencies via Bower. bower --version > /dev/null || npm install -g bower bower install diff --git a/template/circle.yml b/template/circle.yml new file mode 100644 index 0000000..187a4d7 --- /dev/null +++ b/template/circle.yml @@ -0,0 +1,12 @@ +machine: + ruby: + version: 2.2.3 + +dependencies: + pre: + - ./bin/setup + +test: + post: + - bundle exec jekyll build + - bundle exec htmlproof ./_site --only-4xx --href-ignore "#"