LoginSignup
3
4

More than 3 years have passed since last update.

Gitlab CIでruby gemsのアップデートとMRの自動作成ができるようになりました

Last updated at Posted at 2019-09-18

dependabot/dependabot-coreというdocker imageを使って、GitlabCIでruby gemsのアップデートをし、バージョンアップがあったものを自動的にMR作成できるようになりました。

事前準備

  • gitlab access token作成 image.png

.gitlab-ci.ymlを調整

ruby gems更新用のJobを追加

dependabot/dependabot-coreコンテナに望ましいバージョンのrubyがない可能性があるので、rbenvを用いてインストールしておく。
※プロジェクトの配下にrubyのバージョンを記載してある.ruby-versionがあるとします。
image.png

Jobを追加後の.gitlab-ci.ymlファイル

.gitlab-ci.yml
dependabot:
  image: dependabot/dependabot-core
  before_script:
    - git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
    - git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
    - echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
    - echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
    - source ~/.bash_profile
    - rbenv install -v `cat ./.ruby-version` --skip-existing
    - rbenv global `cat ./.ruby-version`
    - gem install bundler
    - bundle install -j $(nproc) --path vendor
    - curl -O https://raw.githubusercontent.com/dependabot/dependabot-script/master/generic-update-script.rb
    - curl -O https://raw.githubusercontent.com/dependabot/dependabot-script/master/update-script.rb
  script:
    - bundle exec ruby ./generic-update-script.rb
  only:
    - schedules

.gitlab-ci.ymlに載っているdependabot以外のJobにexcept: schedulesを追加

ruby gemsの更新だけなので、rspec/lintとかの実行はいりません

.gitlab-ci.yml
...
brakeman:
  stage: audit
  tags:
    - docker
    - gce
  except:
    - schedules
  script:
    - bundle exec brakeman -4 -A -w 1 -z
...

ScheduleにJobを登録

image.png

動けるかを試してみる

image.png

2つのGemバージョナップがあったようで

image.png

MRリストを確認

確かに、2つのMRが上がられました。
image.png

いい感じ出来上がりました :confetti_ball:
image.png

あとは、緑のmergeボタンをクリックだけ。

3
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
3
4