dependabot/dependabot-coreというdocker imageを使って、GitlabCIでruby gemsのアップデートをし、バージョンアップがあったものを自動的にMR作成できるようになりました。
事前準備
- gitlab access token作成
![image.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F293473%2Fee7d9bc9-a7c5-f1af-906e-ab5ce2d6a2b2.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=e0e657587b28a9bacb172d42d336da99)
.gitlab-ci.ymlを調整
ruby gems更新用のJobを追加
dependabot/dependabot-core
コンテナに望ましいバージョンのrubyがない可能性があるので、rbenv
を用いてインストールしておく。
※プロジェクトの配下にruby
のバージョンを記載してある.ruby-version
があるとします。
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](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F293473%2F553b74d5-110d-1c25-ec29-306cb0b3bd1e.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=df33d03dc644f088fbdbedc7d59d13a8)
動けるかを試してみる
![image.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F293473%2Ff8364056-d7e4-5f7e-be76-119158caf000.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=a00ab53616bc9e3ff578dd70c85bf8e7)
2つのGemバージョナップがあったようで
![image.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F293473%2F282d1f96-6947-4014-262f-ecc289c3d6c7.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=25bfeb743fd5af45a10614aa34248d98)
MRリストを確認
あとは、緑のmerge
ボタンをクリックだけ。