Skip to content

Commit

Permalink
Replace make with rake (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuravel authored Mar 6, 2017
1 parent 44e54cc commit 0f79eee
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 82 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ Gemfile.lock
source/_static/test
.pivotalrc
.idea
*.log
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
language: python
script: make test
script: rake test
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
source 'https://rubygems.org'

gem 'foreman'
gem 'guard-livereload'
gem 'guard-shell'
gem 'foreman'
gem 'rake'
74 changes: 0 additions & 74 deletions Makefile

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ More information in case of trouble: https://github.com/Homebrew/homebrew/wiki/H

Install dependencies:

gem install bundler
bundle install
pip install -r requirements.txt

If that fails, install pip first.

If you get the error "unknown locale: UTF-8" when generating the documentation
the solution is to define the following environment variables:

Expand All @@ -87,17 +87,17 @@ the solution is to define the following environment variables:

### Building

Run `make preview` from "master" branch.
Run `rake preview` from "master" branch.

#### Setting up LiveReload

Install Ruby and [Bundler](http://bundler.io/), and run `bundle install` to install dependencies.

Run `make server` from "master" branch and open `http://localhost:5000` in browser.
Run `rake server` from "master" branch and open `http://localhost:5000` in browser.

### Deploying

If you did everything right, deploying is as easy as `make deploy` from "master" branch.
If you did everything right, deploying is as easy as `rake deploy` from "master" branch.

---

Expand Down
102 changes: 102 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# frozen_string_literal: true
require 'mkmf'
require 'open-uri'

SPHINX_BUILD = ENV['SPHINX_BUILD'] || 'sphinx-build'
SOURCE_DIR = 'source'
BUILD_DIR = 'build'
SPHINX_OPTS = "-b html -d #{BUILD_DIR}/doctrees #{SOURCE_DIR} #{BUILD_DIR}/html"

task :default => :help
task :help do
system 'rake --tasks'
end

desc 'Set up deploys'
task :setup do
sh 'git remote add staging [email protected]:talkable/void-talkable-docs.git'
end

task :environment do
ENV['LANG'] = ENV['LC_ALL'] = 'en_US.UTF-8'
find_executable(SPHINX_BUILD) || abort("The '#{SPHINX_BUILD}' command was not found. Make sure you have Sphinx installed, then set the SPHINX_BUILD environment variable to point to the full path of the '#{SPHINX_BUILD}' executable. Alternatively you can add the directory with the executable to your PATH. If you do not have Sphinx installed, grab it from http://sphinx-doc.org/")
end

desc 'Run build in test mode'
task :test => :environment do
sh "#{SPHINX_BUILD} -nW #{SPHINX_OPTS}"
end

task :build => :environment do
sh "#{SPHINX_BUILD} #{SPHINX_OPTS}"
integration_version = open('http://d2jjzw81hqbuqv.cloudfront.net/integration/docs.version', &:read).chomp
integration_url = "//d2jjzw81hqbuqv.cloudfront.net/integration/talkable-#{integration_version}.min.js"
Rake::FileList["#{BUILD_DIR}/html/**/*.html"].each do |filename|
File.open(filename, 'r+') do |file|
old_content = file.read
new_content = old_content.
gsub('|integration_url|', integration_url).
gsub('|integration_version|', integration_version)
file.tap(&:rewind).write(new_content) if old_content != new_content
end
end

puts "\nBuild finished. The HTML pages are in #{File.expand_path("#{BUILD_DIR}/html")}."
end

task :clean do
sh "rm -rf #{BUILD_DIR}/*"
end

desc 'Make standalone HTML files'
task :preview => [:clean, :build]

desc 'Run the server on localhost:5000 and open a browser'
task :server => :preview do
sh '(sleep 2 && open "http://localhost:5000")&'
sh 'bundle exec foreman start'
end

desc 'Commit and deploy changes to http://docs.talkable.com'
task :deploy => :'deploy:production'

namespace :deploy do
def deploy(domain:, html_branch:, source_branch:, disallow_robots:, push_command:)
sh "git checkout #{html_branch}"
sh 'git pull'
sh "rm -rf #{BUILD_DIR} #{SOURCE_DIR}"
sh "git checkout #{source_branch} #{SOURCE_DIR} .gitignore"
sh 'git reset HEAD'
Rake::Task[:build].invoke
sh "(cd #{BUILD_DIR}/html && tar c ./) | (cd ./ && tar xf -)"
sh "rm -rf #{BUILD_DIR} #{SOURCE_DIR} .buildinfo"
File.write('.nojekyll', '')
File.write('CNAME', domain)
File.write('robots.txt', "User-agent: *\nDisallow: /") if disallow_robots
sh 'git add -A'
sh "git commit -m \"Generated gh-pages for `git log #{source_branch} -1 --pretty=short --abbrev-commit`\" && #{push_command} ; git checkout #{source_branch}"

puts "\nDeployment finished. Check updated docs at http://#{domain}"
end

task :production do
deploy(
domain: 'docs.talkable.com',
html_branch: 'gh-pages',
source_branch: 'master',
disallow_robots: false,
push_command: 'git push origin gh-pages'
)
end

desc 'Commit and deploy changes to http://void-docs.talkable.com'
task :staging do
deploy(
domain: 'void-docs.talkable.com',
html_branch: 'void-gh-pages',
source_branch: 'void',
disallow_robots: true,
push_command: 'git push -f origin void-gh-pages && git push -f staging void-gh-pages:gh-pages'
)
end
end
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Sphinx==1.5.2
Sphinx==1.5.3

0 comments on commit 0f79eee

Please sign in to comment.