Browse Source

Update travis to auto deploy the docs

zhixin 7 years ago
parent
commit
bb51653a55
9 changed files with 94 additions and 182 deletions
  1. 0 3
      .gitignore
  2. 18 3
      .travis.yml
  3. 6 0
      Gemfile
  4. 4 0
      _config.yml
  5. 64 0
      deploy.sh
  6. BIN
      deploy_key.enc
  7. 0 22
      docs/_plugins/markdown-tag.rb
  8. 0 153
      docs/_plugins/multiple-languages.rb
  9. 2 1
      docs/index.md

+ 0 - 3
.gitignore

@@ -7,9 +7,6 @@ _gh_pages
 # build the extensions
 # build the extensions
 extensions.js
 extensions.js
 
 
-# deploy the docs
-deploy.sh
-
 # old docs
 # old docs
 docs_
 docs_
 
 

+ 18 - 3
.travis.yml

@@ -1,4 +1,19 @@
-language: node_js
+language: ruby
+rvm:
+  - 2.4.1
 
 
-node_js:
-    - "0.10"
+script: bash ./deploy.sh
+
+branches:
+  only:
+  - master
+  - hotfix/docs
+
+env:
+  global:
+  - ENCRYPTION_LABEL: "5453d0fdf68a"
+  - COMMIT_AUTHOR_EMAIL: "wenzhixin2010@gmail.com"
+
+sudo: false
+
+cache: bundler

+ 6 - 0
Gemfile

@@ -0,0 +1,6 @@
+source "https://rubygems.org"
+
+gem "jekyll"
+gem "rouge"
+gem "redcarpet"
+gem "jekyll-multiple-languages-plugin"

+ 4 - 0
_config.yml

@@ -7,6 +7,10 @@ redcarpet:
   - autolink
   - autolink
 highlighter: rouge
 highlighter: rouge
 
 
+plugins:
+  - jekyll-multiple-languages-plugin
+baseurl: ""
+
 # Permalinks
 # Permalinks
 permalink: pretty
 permalink: pretty
 
 

+ 64 - 0
deploy.sh

@@ -0,0 +1,64 @@
+#!/bin/bash
+set -e # Exit with nonzero exit code if anything fails
+
+SOURCE_BRANCH="hotfix/docs"
+TARGET_BRANCH="gh-pages"
+
+function doCompile {
+  bundle exec jekyll build
+}
+
+# Pull requests and commits to other branches shouldn't try to deploy, just build to verify
+if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_BRANCH" != "$SOURCE_BRANCH" ]; then
+    echo "Skipping deploy; just doing a build."
+    doCompile
+    exit 0
+fi
+
+# Save some useful information
+REPO=`git config remote.origin.url`
+SSH_REPO=${REPO/https:\/\/github.com\//git@github.com:}
+SHA=`git rev-parse --verify HEAD`
+OUT=_gh_pages
+
+# Clone the existing gh-pages for this repo into dist/
+# Create a new empty branch if gh-pages doesn't exist yet (should only happen on first deply)
+git clone $REPO $OUT
+cd $OUT
+git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
+cd ..
+
+# Clean out existing contents
+rm -rf $OUT/**/* || exit 0
+
+# Run our compile script
+doCompile
+
+# Now let's go have some fun with the cloned repo
+cd $OUT
+git config user.name "Travis CI"
+git config user.email "$COMMIT_AUTHOR_EMAIL"
+
+# If there are no changes to the compiled dist (e.g. this is a README update) then just bail.
+if git diff --quiet; then
+    echo "No changes to the output on this push; exiting."
+    exit 0
+fi
+
+# Commit the "changes", i.e. the new version.
+# The delta will show diffs between new and old versions.
+git add -A .
+git commit -m "Deploy to GitHub Pages: ${SHA}"
+
+# Get the deploy key by using Travis's stored variables to decrypt deploy_key.enc
+ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
+ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
+ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
+ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}
+openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in ../deploy_key.enc -out ../deploy_key -d
+chmod 600 ../deploy_key
+eval `ssh-agent -s`
+ssh-add ../deploy_key
+
+# Now that we're all set up, we can push.
+git push $SSH_REPO $TARGET_BRANCH

BIN
deploy_key.enc


+ 0 - 22
docs/_plugins/markdown-tag.rb

@@ -1,22 +0,0 @@
-=begin
-  Jekyll tag to include Markdown text from _includes directory preprocessing with Liquid.
-  Usage:
-    {% markdown <filename> %}
-=end
-module Jekyll
-  class MarkdownTag < Liquid::Tag
-    def initialize(tag_name, text, tokens)
-      super
-      @text = text.strip
-    end
- 
-    def render(context)
-      tmpl = File.read File.join context.registers[:site].source, "_includes", @text
-      site = context.registers[:site]
-      converter = site.getConverterImpl(Jekyll::Converters::Markdown)
-      tmpl = (Liquid::Template.parse tmpl).render site.site_payload
-      html = converter.convert(tmpl)
-    end
-  end
-end
-Liquid::Template.register_tag('markdown', Jekyll::MarkdownTag)

+ 0 - 153
docs/_plugins/multiple-languages.rb

@@ -1,153 +0,0 @@
-module Jekyll
-  @parsedlangs = {}
-  def self.langs
-    @parsedlangs
-  end
-  def self.setlangs(l)
-    @parsedlangs = l
-  end
-  class Site
-    alias :process_org :process
-    def process
-      if !self.config['baseurl']
-        self.config['baseurl'] = ""
-      end
-      #Variables
-      config['baseurl_root'] = self.config['baseurl']
-      baseurl_org = self.config['baseurl']
-      languages = self.config['languages']
-      exclude_org = self.exclude
-      dest_org = self.dest
-
-      #Loop
-      self.config['lang'] = self.config['default_lang'] = languages.first
-      puts
-      puts "Building site for default language: \"#{self.config['lang']}\" to: #{self.dest}"
-      process_org
-      languages.drop(1).each do |lang|
-
-        # Build site for language lang
-        @dest = @dest + "/" + lang
-        self.config['baseurl'] = self.config['baseurl'] + "/" + lang
-        self.config['lang'] = lang
-        
-        # exclude folders or files from beeing copied to all the language folders
-        exclude_from_localizations = self.config['exclude_from_localizations'] || []
-        @exclude = @exclude + exclude_from_localizations
-
-        puts "Building site for language: \"#{self.config['lang']}\" to: #{self.dest}"
-        process_org
-
-        #Reset variables for next language
-        @dest = dest_org
-        @exclude = exclude_org
-
-        self.config['baseurl'] = baseurl_org
-      end
-      Jekyll.setlangs({})
-      puts 'Build complete'
-    end
-
-    alias :read_posts_org :read_posts
-    def read_posts(dir)
-      if dir == ''
-        read_posts("_i18n/#{self.config['lang']}/")
-      else
-        read_posts_org(dir)
-      end
-    end
-  end
-
-  class LocalizeTag < Liquid::Tag
-
-    def initialize(tag_name, key, tokens)
-      super
-      @key = key.strip
-    end
-
-    def render(context)
-      if "#{context[@key]}" != "" #Check for page variable
-        key = "#{context[@key]}"
-      else
-        key = @key
-      end
-      lang = context.registers[:site].config['lang']
-      unless Jekyll.langs.has_key?(lang)
-        puts "Loading translation from file #{context.registers[:site].source}/_i18n/#{lang}.yml"
-        Jekyll.langs[lang] = YAML.load_file("#{context.registers[:site].source}/_i18n/#{lang}.yml")
-      end
-      translation = Jekyll.langs[lang].access(key) if key.is_a?(String)
-      if translation.nil? or translation.empty?
-        translation = Jekyll.langs[context.registers[:site].config['default_lang']].access(key)
-        puts "Missing i18n key: #{lang}:#{key}"
-        puts "Using translation '%s' from default language: %s" %[translation, context.registers[:site].config['default_lang']]
-      end
-      translation
-    end
-  end
-
-  module Tags
-    class LocalizeInclude < IncludeTag
-      def render(context)
-        if "#{context[@file]}" != "" #Check for page variable
-          file = "#{context[@file]}"
-        else
-          file = @file
-        end
-
-        includes_dir = File.join(context.registers[:site].source, '_i18n/' + context.registers[:site].config['lang'])
-
-        if File.symlink?(includes_dir)
-          return "Includes directory '#{includes_dir}' cannot be a symlink"
-        end
-        if file !~ /^[a-zA-Z0-9_\/\.-]+$/ || file =~ /\.\// || file =~ /\/\./
-          return "Include file '#{file}' contains invalid characters or sequences"
-        end
-
-        Dir.chdir(includes_dir) do
-          choices = Dir['**/*'].reject { |x| File.symlink?(x) }
-          if choices.include?(file)
-            source = File.read(file)
-            partial = Liquid::Template.parse(source)
-
-            context.stack do
-              context['include'] = parse_params(context) if @params
-              contents = partial.render(context)
-              site = context.registers[:site]
-              ext = File.extname(file)
-
-              converter = site.converters.find { |c| c.matches(ext) }
-              contents = converter.convert(contents) unless converter.nil?
-
-              contents
-            end
-          else
-            "Included file '#{file}' not found in #{includes_dir} directory"
-          end
-        end
-      end
-    end
-  end
-end
-
-unless Hash.method_defined? :access
-  class Hash
-    def access(path)
-      ret = self
-      path.split('.').each do |p|
-        if p.to_i.to_s == p
-          ret = ret[p.to_i]
-        else
-          ret = ret[p.to_s] || ret[p.to_sym]
-        end
-        break unless ret
-      end
-      ret
-    end
-  end
-end
-
-Liquid::Template.register_tag('t', Jekyll::LocalizeTag)
-Liquid::Template.register_tag('translate', Jekyll::LocalizeTag)
-Liquid::Template.register_tag('tf', Jekyll::Tags::LocalizeInclude)
-Liquid::Template.register_tag('translate_file', Jekyll::Tags::LocalizeInclude)

+ 2 - 1
docs/index.md

@@ -31,7 +31,8 @@ title: pages.home.title
         {% tf home/feature.md %}
         {% tf home/feature.md %}
       </div>
       </div>
       <div class="col-md-7">
       <div class="col-md-7">
-        {% markdown latest-release.md %}
+        {% capture my_include %}{% include latest-release.md %}{% endcapture %}
+        {{ my_include | markdownify }}
       </div>
       </div>
     </div>
     </div>
   </div>
   </div>