Jekyll网站的Travis-CI测试
原文链接 https://gaoxiaosong.github.io/2016/03/25/jekyll-travis-ci.html
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。
编译运行配置
编写Gemfile:
source 'https://rubygems.org'
gem 'jekyll'
gem 'jekyll-sitemap'
gem 'jekyll-paginate'
gem 'html-proofer'
gem "codeclimate-test-reporter", group: :test, require: nil
编写Makefile:
.PHONY: build
install:
@bundle install --deployment
build: install
@bundle exec jekyll build
# 开发环境
start: build
@bundle exec jekyll serve
# 测试环境
test:
@bundle exec jekyll build
@bundle exec htmlproofer ./_site
主要是使用htmlproofer对静态网页进行测试。
.travis.yml配置
编写Travis-CI使用的.travis.yml:
language: ruby
rvm:
- 2.0.0
addons:
code_climate:
repo_token: 5867e3f205455671c9f4e1ce0ab9dff6f0062671d29d7329cd0006cdcce213cd
after_script:
- bundle exec ruby ./spec_helper.rb
script:
- make test
env:
global:
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true # speeds up installation of html-proofer
sudo: false
其中spec_helper.rb是发送Coverage用的:
require "codeclimate-test-reporter"
CodeClimate::TestReporter.start
.config.yml配置
在.config.yml中添加:
exclude: [vendor]
否则会出现错误:
ERROR: YOUR SITE COULD NOT BE BUILT:
------------------------------------
Invalid date '<%= Time.now.strftime('%Y-%m-%d %H:%M:%S %z') %>': Document 'vendor/bundle/ruby/2.0.0/gems/jekyll-3.1.2/lib/site_template/_posts/0000-00-00-welcome-to-jekyll.markdown.erb' does not have a valid date in the YAML front matter.
Mac OS X中的libc.dylib错误
在Mac OS X El Capitan中,make test的时候,会遇到如下错误:
/usr/local/Cellar/gems/2.0.0/gems/ffi-1.9.6/lib/ffi/library.rb:133:in `block in ffi_lib': Could not open library 'c': dlopen(c, 5): image not found. (LoadError)
Could not open library 'libc.dylib': dlopen(libc.dylib, 5): image not found
在GitHub中的ffi项目的issue-461处找到了解决方法:
可以在这个library.rb中,添加如下代码:
module FFI
...
def self.map_library_name(lib)
...
lib = Library::LIBC if lib == 'c'
lib = Library::LIBCURL if lib == 'libcurl'
module Library
CURRENT_PROCESS = FFI::CURRENT_PROCESS
LIBC = '/usr/lib/libc.dylib'
LIBCURL = '/usr/lib/libcurl.dylib'
用绝对路径对于找不到的.dylib进行定位。