Gitlabci::Bundle::Update::Mr

Create MergeRequest of bundle update in GitLab CI

This is inspired by circleci-bundle-update-pr

Requirements

  • GitLab v9.0.0+

  • GitLab API v4

  • git

Installation

gem install gitlabci-bundle-update-mr

Prerequisites

The application on which you want to run continuous bundle update must be configured to be built on GitLab CI.

Setup

Get GitHub personal access token

  1. Go to your account’s settings page

  2. Generate a personal access token with repo scope

Get GitLab personal access token

  1. Go to https://YOUR-GITLAB/profile/personal_access_tokens

  2. Generate a personal access token with api scope

Save CI environment variables

  1. Go to https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/settings/ci_cd

  2. Save environment variables

    • GITLAB_API_ENDPOINT : GitLab API endpoint (e.g. https://gitlab.com/api/v4)

    • GITLAB_API_PRIVATE_TOKEN : GitLab personal access token

    • OCTOKIT_ACCESS_TOKEN : GitHub personal access token

Usage

Step 1-A. Plain

Configure your .gitlab-ci.yml to run gitlabci-bundle-update-mr, for example:

stages:
  - build

continuous_bundle_update:
  stage: build

  image: ruby

  cache:
    key: "$CI_BUILD_NAME"
    paths:
      - vendor/bundle/

  before_script:
    # Set timezone to Asia/Tokyo
    - cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

  script:
    - bundle install --path vendor/bundle
    - bundle clean
    - gem install --no-doc gitlabci-bundle-update-mr
    - gitlabci-bundle-update-mr --user="GitLab CI" --email="gitlabci@example.com" --labels="bundle update"

  only:
    - schedules

Step 1-B. Using include

include is available in one of the following versions.

  • GitLab Core 11.4+

  • GitLab Premium 10.5+

  • Starter, Premium and Ultimate 10.6+

c.f. docs.gitlab.com/ce/ci/yaml/README.html#include

example

include:
  - remote: "https://gitlab.com/sue445/gitlabci-bundle-update-mr/raw/master/gitlabci-templates/continuous_bundle_update.yml"

continuous_bundle_update:
  stage: build

  variables:
    # override variables (followings are defaults)
    CACHE_VERSION: "v1"
    GIT_EMAIL:     "gitlabci@example.com"
    GIT_USER:      "GitLab CI"
    LABELS:        "bundle update"
    OPTIONS:       ""

  before_script:
    # Set timezone to Asia/Tokyo
    - cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime

Step 2. Register scheduler

And register scheduler to https://YOUR-GITLAB/YOUR-NAME/REPO-NAME/pipeline_schedules

CLI command references

$ gitlabci-bundle-update-mr --help
Usage: gitlabci-bundle-update-mr [options]
        --email EMAIL                git email address (default. `git config user.email`)
        --user USER                  git username (default. `git config user.name`)
    -d, --duplicate                  Make MR even if it has already existed (default. false)
    -l, --labels 'In Review, Update' Add labels to the MR
        --update-bundled-with        Whether to update `BUNDLED WITH` section in Gemfie.lock (default. false)
        --merge-when-pipeline-succeeds
                                     Whether to set 'Merge when pipeline succeeds' (default. false)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitLab at gitlab.com/sue445/gitlabci-bundle-update-mr.

License

The gem is available as open source under the terms of the MIT License.