LoginSignup
2
4

More than 5 years have passed since last update.

travisをローカルで動かす

Posted at

概要

travisの設定を変更して、毎回pushして確認するのではなく、ローカルで確認する手順をメモ

環境

mac上のdockerで動かすことができないようなので、vagrantで起動したcentos上のdockerで試す。

❯  cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

準備

docker起動。今回はpythonのimageを使用。

❯ sudo docker run -it -u travis quay.io/travisci/travis-python /bin/bash
travis@6492bd86030a:/$

ruby 2.3.0をインストール

$ ruby -v
ruby 1.9.3p551 (2014-11-13 revision 48407) [x86_64-linux]
$ rvm install 2.3.0
...
$ rvm use 2.3.0
Using /home/travis/.rvm/gems/ruby-2.3.0
$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]

travis-buildの準備

$ cd ~/builds
$ git clone https://github.com/travis-ci/travis-build.git
$ cd travis-build/
$ gem install travis
$ travis
$ ln -s `pwd` ~/.travis/travis-build
$ gem install bundler
$ bundle install

gem installでsslのエラーが出る場合はhttpを使用するように設定

gem source -r https://rubygems.org/
gem source -a http://rubygems.org/
Gemfile
source 'http://rubygems.org'

ssh key作成し、githubに登録

$ ssh-keygen -t rsa -b 4096 -C your@email.com
$ cat ~/.ssh/id_rsa.pub

ビルド対象のレポジトリをclone

$ mkdir ~/builds/bassaer
$ cd ~/builds/bassaer
$ git clone git@github.com:bassaer/travis-local.git
$ cd travis-local

travisのスクリプトをコンパイルして生成

$ travis compile > ci.sh

travis関連のファイルがないと怒られる場合は

cannot load such file -- travis/support

以下のようにbuildしてinstall

$ git clone https://github.com/travis-ci/travis-support.git
$ gem build travis-support.gemspec
$ gem install travis-support-0.0.1.gem

自分の環境では同様の作業を以下でも必要だった

  • travis-rollout
  • travis-github_apps

加えてaddressableコンフリクトするエラーがあったので対象のバージョンをuninstall

$ gem uninstall addressable -v 2.5.2

これでスクリプト生成

$ travis compile > ci.sh
detected repository as bassaer/travis-local

ブランチ名がdevの場合は以下のように修正

ci.sh

-    travis_cmd git\ clone\ --depth\=50\ --branch\=\'\'\ https://github.com/bassaer/travis-local.git\ bassaer/travis-local --echo --retry --timing
+    travis_cmd git\ clone\ --depth\=50\ --branch\=\dev\ https://github.com/bassaer/travis-local.git\ bassaer/travis-local --echo --retry --timing

準備完了。

実行

$ bash ci.sh
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4