Redmine のプラグインの場合、プラグイン本体のみ Github に登録しているので、そのままでは Travis で CI することができない。
諦めていたんだけど、.travis.yml のオプションとにらめっこしたらなんとなく出来そうな気がしたので試してみた。
10数回の試行を経て、なんとか出来たのでスクリプトを紹介します。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
language: ruby | |
rvm: | |
- 1.9.3 | |
- 2.0.0 | |
before_install: sh travis/before_install.sh | |
script: sh travis/exec_test.sh | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
REDMINE_VERSION="2.4.0" | |
PLUGIN_NAME="<plugin_name>" | |
# Get & deploy Redmine | |
wget http://www.redmine.org/releases/redmine-${REDMINE_VERSION}.tar.gz | |
tar zxf redmine-${REDMINE_VERSION}.tar.gz | |
# Copy plugin files to plugin directory | |
mkdir redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME} | |
mv app redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/app | |
mv assets redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/assets | |
mv config redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/config | |
mv db redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/db | |
mv lib redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/lib | |
mv spec redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/spec | |
mv Gemfile redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/Gemfile | |
mv init.rb redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/init.rb | |
# Create necessary files | |
cat > redmine-${REDMINE_VERSION}/config/database.yml <<_EOS_ | |
test: | |
adapter: sqlite3 | |
database: db/redmine_test.db | |
_EOS_ | |
cp redmine-${REDMINE_VERSION}/plugins/${PLUGIN_NAME}/test/fixtures/* redmine-${REDMINE_VERSION}/test/fixtures/ | |
# All move to work directory | |
mv redmine-${REDMINE_VERSION}/* . | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
export REDMINE_LANG=en | |
export RAILS_ENV=test | |
# Initialize redmine | |
bundle exec rake generate_secret_token | |
bundle exec rake db:migrate | |
bundle exec rake redmine:load_default_data | |
# Copy assets & execute plugin's migration | |
bundle exec rake redmine:plugins NAME=<plugin_name> | |
# Initialize RSpec | |
bundle exec rails g rspec:install | |
# Execute test by RSpec | |
bundle exec rspec plugins/<plugin_name>/spec -c |
.travis.yml
before_install
があるので、after_install
があるかと思ったらなかった。before_install.sh
gem インストール前に実行させるスクリプト。
Travis ではbundle install
前に直下のGemfile
がBUNDLE_GEMFILE
環境変数に登録されてしまう。
しかし、指定したいのはプラグインのGemfile
ではなく、Redmine のものなのである。
なので、mv
しまくりでなんとかディレクトリ構成を整えた。苦労した。
Redmine のダウンロード URL がバージョンだけに依存してくれないのが少し残念。exec_test.sh
テスト実行用スクリプト。
前述のとおりafter_install
がなかったので、bundle install
後の処理(Redmineの初期化など)とテストの実行を同時にすることにした。
こちらはそんなに苦労しなかった。
これで、プラグインを複数バージョンの Ruby でテストすることができるようになった。
でも、複数バージョンの Redmine でテストすることは当然できない。
複数バージョンの Redmine を対象にテストするなら Jenkins 使うのがいいんだろうな。
0 件のコメント :
コメントを投稿