├── .gitignore ├── src ├── @orb.yml ├── commands │ ├── install-circleci-bundle-update-pr.yml │ ├── run-circleci-bundle-update-pr.yml │ └── bundle-install.yml ├── examples │ ├── bundle-install-with-gemfile-lock.yml │ ├── bundle-install-without-gemfile-lock.yml │ └── bundle-update-pr.yml └── jobs │ └── bundle-update-pr.yml ├── test ├── bundler-v1 │ ├── bundle-update-pr_test.yml │ ├── bundle-install_test.yml │ └── bundle-install-gemspec_test.yml └── bundler-v2 │ ├── bundle-update-pr_test.yml │ ├── bundle-install_test.yml │ └── bundle-install-gemspec_test.yml ├── .circleci ├── push_latest_version_tag.rb ├── setup_smoke_test.sh └── config.yml ├── scripts └── generate_markdown.rb ├── LICENSE ├── CHANGELOG.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | packed/ 2 | -------------------------------------------------------------------------------- /src/@orb.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | description: | 4 | CircleCI orb for ruby. 5 | https://github.com/sue445/circleci-ruby-orbs 6 | -------------------------------------------------------------------------------- /test/bundler-v1/bundle-update-pr_test.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: ruby:2.5-alpine 7 | 8 | jobs: 9 | build: 10 | executor: 11 | name: default 12 | 13 | steps: 14 | - ruby-orbs/install-circleci-bundle-update-pr: 15 | version: "1.14.0" 16 | -------------------------------------------------------------------------------- /test/bundler-v2/bundle-update-pr_test.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: ruby:2.7-alpine 7 | 8 | jobs: 9 | build: 10 | executor: 11 | name: default 12 | 13 | steps: 14 | - ruby-orbs/install-circleci-bundle-update-pr: 15 | version: "1.14.0" 16 | -------------------------------------------------------------------------------- /.circleci/push_latest_version_tag.rb: -------------------------------------------------------------------------------- 1 | orb_ref = ARGV[0] 2 | 3 | raise "Usage: push_latest_version_tag.rb /" unless orb_ref 4 | 5 | result = `circleci orb info #{orb_ref} --token #{ENV["CIRCLECI_API_TOKEN"]}` 6 | 7 | result =~ /^Latest:\s*#{orb_ref}@(.+)$/ 8 | 9 | version = $1 10 | 11 | raise "Not found version in '#{result}'" unless version 12 | 13 | system "git tag -a #{version} -m 'Release #{version}'" 14 | system "git push origin --tags" 15 | -------------------------------------------------------------------------------- /scripts/generate_markdown.rb: -------------------------------------------------------------------------------- 1 | # Usage: scripts/generate_markdown.rb src/commands/bundle-install.yml 2 | 3 | require "yaml" 4 | 5 | raise "yaml is required" unless ARGV[0] 6 | 7 | config = YAML.load_file(ARGV[0]) 8 | 9 | result = config["parameters"].map do |name, values| 10 | line = "* `#{name}` : #{values["description"]}" 11 | 12 | if values.key?("default") 13 | default = values["default"] 14 | line << " (default: `#{default}`)" unless default.to_s.empty? 15 | end 16 | 17 | line 18 | end.join("\n") 19 | 20 | puts result 21 | -------------------------------------------------------------------------------- /src/commands/install-circleci-bundle-update-pr.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Install circleci-bundle-update-pr. 3 | 4 | parameters: 5 | version: 6 | type: string 7 | default: "" 8 | description: "circleci-bundle-update-pr vesion. default is latest" 9 | 10 | steps: 11 | - run: 12 | name: "Install `circleci-bundle-update-pr`" 13 | command: | 14 | set -xe 15 | args="--no-doc" 16 | 17 | if [ -n "<< parameters.version >>" ]; then 18 | args="$args --version << parameters.version >>" 19 | fi 20 | 21 | gem install circleci-bundle-update-pr $args 22 | -------------------------------------------------------------------------------- /.circleci/setup_smoke_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -xe 2 | 3 | mkdir -m 700 -p ~/.ssh/ 4 | cat >> ~/.ssh/config << EOF 5 | StrictHostKeyChecking no 6 | EOF 7 | chmod 600 ~/.ssh/config 8 | 9 | readonly SOURCE_BRANCH=$1 10 | export SMOKE_BRANCH="smoke_test/${CIRCLE_SHA1}_${SOURCE_BRANCH}" 11 | 12 | git clone --branch $SOURCE_BRANCH git@github.com:sue445/circleci-ruby-orbs-test.git /tmp/circleci-ruby-orbs-test 13 | 14 | cd /tmp/circleci-ruby-orbs-test 15 | 16 | git config push.default current 17 | git config user.name "CircleCI" 18 | git config user.email ${EMAIL} 19 | 20 | git checkout -b ${SMOKE_BRANCH} 21 | 22 | sed -i -e "s/@volatile/@dev:${CIRCLE_SHA1}/g" .circleci/config.yml 23 | git add .circleci/config.yml 24 | git commit -m "Update from ${CIRCLE_BUILD_URL}" 25 | 26 | git push -f origin 27 | -------------------------------------------------------------------------------- /src/examples/bundle-install-with-gemfile-lock.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Run `bundle install` using cache for app repo. (`Gemfile.lock` is committed) 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | ruby-orbs: sue445/ruby-orbs@volatile 9 | 10 | jobs: 11 | rspec: 12 | docker: 13 | - image: circleci/ruby 14 | 15 | steps: 16 | - checkout 17 | 18 | - ruby-orbs/bundle-install: 19 | cache_key_prefix: "v1-bundle" 20 | bundle_jobs: 4 21 | bundle_retry: 3 22 | bundle_path: "vendor/bundle" 23 | bundle_gemfile: "Gemfile" 24 | bundle_clean: true 25 | bundle_without: development test 26 | bundle_extra_args: "" 27 | restore_bundled_with: true 28 | 29 | - run: bundle exec rspec 30 | -------------------------------------------------------------------------------- /src/examples/bundle-install-without-gemfile-lock.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Run `bundle install` using cache for gem repo. (`Gemfile.lock` is not committed) 3 | 4 | usage: 5 | version: 2.1 6 | 7 | orbs: 8 | ruby-orbs: sue445/ruby-orbs@volatile 9 | 10 | jobs: 11 | rspec: 12 | docker: 13 | - image: circleci/ruby 14 | 15 | steps: 16 | - checkout 17 | 18 | - ruby-orbs/bundle-install: 19 | with_gemfile_lock: false 20 | gemspec_name: "yourgem" 21 | cache_key_prefix: "v1-bundle" 22 | bundle_jobs: 4 23 | bundle_retry: 3 24 | bundle_path: "vendor/bundle" 25 | bundle_clean: true 26 | bundle_without: development test 27 | bundle_extra_args: "" 28 | 29 | - run: bundle exec rspec 30 | -------------------------------------------------------------------------------- /src/examples/bundle-update-pr.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Run `bundle update` and send PullRequest. 3 | Uses https://github.com/masutaka/circleci-bundle-update-pr 4 | 5 | usage: 6 | version: 2.1 7 | 8 | orbs: 9 | ruby-orbs: sue445/ruby-orbs@volatile 10 | 11 | workflows: 12 | version: 2 13 | nightly: 14 | triggers: 15 | - schedule: 16 | cron: "00 10 * * 5" 17 | filters: 18 | branches: 19 | only: master 20 | jobs: 21 | - ruby-orbs/bundle-update-pr: 22 | image: "circleci/ruby:2.5.3" 23 | pre-bundle-update-pr: 24 | - run: 25 | name: "Set timezone to Asia/Tokyo" 26 | command: "sudo cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime" 27 | - ruby-orbs/bundle-install 28 | git_user_name: "CircleCI" 29 | git_user_email: "you@example.com" 30 | github_access_token: GITHUB_ACCESS_TOKEN 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 GO Sueyoshi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /test/bundler-v1/bundle-install_test.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: ruby:2.5-alpine 7 | 8 | jobs: 9 | build: 10 | executor: 11 | name: default 12 | 13 | steps: 14 | - run: 15 | name: Put test.gemfile 16 | # FIXME: '<<' is special character for CircleCI 2.1+. So `cat test.gemfile << EOS` does't work in config.yml... 17 | command: | 18 | echo 'source "https://rubygems.org"' > test.gemfile 19 | echo 'gem "sengiri_yaml"' >> test.gemfile 20 | 21 | - run: 22 | name: Put test.gemfile.lock 23 | command: | 24 | echo 'GEM' > test.gemfile.lock 25 | echo ' remote: https://rubygems.org/' >> test.gemfile.lock 26 | echo ' specs:' >> test.gemfile.lock 27 | echo ' sengiri_yaml (0.0.3)' >> test.gemfile.lock 28 | echo '' >> test.gemfile.lock 29 | echo 'PLATFORMS' >> test.gemfile.lock 30 | echo ' ruby' >> test.gemfile.lock 31 | echo '' >> test.gemfile.lock 32 | echo 'DEPENDENCIES' >> test.gemfile.lock 33 | echo ' sengiri_yaml' >> test.gemfile.lock 34 | 35 | - ruby-orbs/bundle-install: 36 | bundle_gemfile: "test.gemfile" 37 | 38 | # Assert whether `vendor/bundle` are created 39 | - run: ls -l vendor/bundle 40 | -------------------------------------------------------------------------------- /test/bundler-v2/bundle-install_test.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: ruby:2.7-alpine 7 | 8 | jobs: 9 | build: 10 | executor: 11 | name: default 12 | 13 | steps: 14 | - run: 15 | name: Put test.gemfile 16 | # FIXME: '<<' is special character for CircleCI 2.1+. So `cat test.gemfile << EOS` does't work in config.yml... 17 | command: | 18 | echo 'source "https://rubygems.org"' > test.gemfile 19 | echo 'gem "sengiri_yaml"' >> test.gemfile 20 | 21 | - run: 22 | name: Put test.gemfile.lock 23 | command: | 24 | echo 'GEM' > test.gemfile.lock 25 | echo ' remote: https://rubygems.org/' >> test.gemfile.lock 26 | echo ' specs:' >> test.gemfile.lock 27 | echo ' sengiri_yaml (0.0.3)' >> test.gemfile.lock 28 | echo '' >> test.gemfile.lock 29 | echo 'PLATFORMS' >> test.gemfile.lock 30 | echo ' ruby' >> test.gemfile.lock 31 | echo '' >> test.gemfile.lock 32 | echo 'DEPENDENCIES' >> test.gemfile.lock 33 | echo ' sengiri_yaml' >> test.gemfile.lock 34 | 35 | - ruby-orbs/bundle-install: 36 | bundle_gemfile: "test.gemfile" 37 | 38 | # Assert whether `vendor/bundle` are created 39 | - run: ls -l vendor/bundle 40 | -------------------------------------------------------------------------------- /test/bundler-v1/bundle-install-gemspec_test.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: ruby:2.5-alpine 7 | 8 | jobs: 9 | build: 10 | executor: 11 | name: default 12 | 13 | steps: 14 | - run: 15 | name: Put Gemfile 16 | # FIXME: '<<' is special character for CircleCI 2.1+. So `cat test.gemfile << EOS` does't work in config.yml... 17 | command: | 18 | echo 'source "https://rubygems.org"' > Gemfile 19 | echo 'gemspec' >> Gemfile 20 | 21 | - run: 22 | name: Put test.gemspec 23 | command: | 24 | echo 'Gem::Specification.new do |spec|' > test.gemspec 25 | echo ' spec.name = "test"' >> test.gemspec 26 | echo ' spec.version = "0.0.1"' >> test.gemspec 27 | echo ' spec.authors = ["sue445"]' >> test.gemspec 28 | echo ' spec.email = ["sue445@example.com"]' >> test.gemspec 29 | echo ' spec.summary = "test"' >> test.gemspec 30 | echo ' spec.description = "test"' >> test.gemspec 31 | echo ' spec.homepage = "http://example.com"' >> test.gemspec 32 | echo ' spec.license = "MIT"' >> test.gemspec 33 | echo ' spec.add_development_dependency "rspec"' >> test.gemspec 34 | echo 'end' >> test.gemspec 35 | 36 | - ruby-orbs/bundle-install: 37 | with_gemfile_lock: false 38 | gemspec_name: "test" 39 | update_always: false 40 | 41 | - ruby-orbs/bundle-install: 42 | with_gemfile_lock: false 43 | gemspec_name: "test" 44 | update_always: true 45 | 46 | # Assert whether `vendor/bundle` are created 47 | - run: ls -l vendor/bundle 48 | -------------------------------------------------------------------------------- /test/bundler-v2/bundle-install-gemspec_test.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | executors: 4 | default: 5 | docker: 6 | - image: ruby:2.7-alpine 7 | 8 | jobs: 9 | build: 10 | executor: 11 | name: default 12 | 13 | steps: 14 | - run: 15 | name: Put Gemfile 16 | # FIXME: '<<' is special character for CircleCI 2.1+. So `cat test.gemfile << EOS` does't work in config.yml... 17 | command: | 18 | echo 'source "https://rubygems.org"' > Gemfile 19 | echo 'gemspec' >> Gemfile 20 | 21 | - run: 22 | name: Put test.gemspec 23 | command: | 24 | echo 'Gem::Specification.new do |spec|' > test.gemspec 25 | echo ' spec.name = "test"' >> test.gemspec 26 | echo ' spec.version = "0.0.1"' >> test.gemspec 27 | echo ' spec.authors = ["sue445"]' >> test.gemspec 28 | echo ' spec.email = ["sue445@example.com"]' >> test.gemspec 29 | echo ' spec.summary = "test"' >> test.gemspec 30 | echo ' spec.description = "test"' >> test.gemspec 31 | echo ' spec.homepage = "http://example.com"' >> test.gemspec 32 | echo ' spec.license = "MIT"' >> test.gemspec 33 | echo ' spec.add_development_dependency "rspec"' >> test.gemspec 34 | echo 'end' >> test.gemspec 35 | 36 | - ruby-orbs/bundle-install: 37 | with_gemfile_lock: false 38 | gemspec_name: "test" 39 | update_always: false 40 | 41 | - ruby-orbs/bundle-install: 42 | with_gemfile_lock: false 43 | gemspec_name: "test" 44 | update_always: true 45 | 46 | # Assert whether `vendor/bundle` are created 47 | - run: ls -l vendor/bundle 48 | -------------------------------------------------------------------------------- /src/jobs/bundle-update-pr.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Run `bundle update` and send PullRequest. 3 | Uses https://github.com/masutaka/circleci-bundle-update-pr 4 | 5 | parameters: 6 | image: 7 | type: string 8 | default: "circleci/ruby" 9 | description: "Image for `bundle update`" 10 | pre-bundle-update-pr: 11 | type: steps 12 | default: [] 13 | description: "Run steps before `circleci-bundle-update-pr`" 14 | post-bundle-update-pr: 15 | type: steps 16 | default: [] 17 | description: "Run steps after `circleci-bundle-update-pr`" 18 | 19 | # install-circleci-bundle-update-pr parameters 20 | version: 21 | type: string 22 | default: "" 23 | description: "circleci-bundle-update-pr vesion. default is latest" 24 | 25 | # run-circleci-bundle-update-pr parameters 26 | assignees: 27 | type: string 28 | default: "" 29 | description: "Assign the PR to them. (e.g. alice,bob,carol)" 30 | reviewers: 31 | type: string 32 | default: "" 33 | description: "Request PR review to them. (e.g. alice,bob,carol)" 34 | labels: 35 | type: string 36 | default: "" 37 | description: "Add labels to the PR (e.g. In Review, Update)" 38 | duplicate: 39 | type: boolean 40 | default: false 41 | description: "Make PR even if it has already existed" 42 | git_user_name: 43 | type: string 44 | default: "$GIT_USER_NAME" 45 | description: "Username for commit" 46 | git_user_email: 47 | type: string 48 | default: "$GIT_USER_EMAIL" 49 | description: "E-mail for commit" 50 | branch: 51 | type: string 52 | default: "$CIRCLE_BRANCH" 53 | description: "Space separated branches. (e.g. `master develop topic`)" 54 | github_access_token: 55 | type: env_var_name 56 | default: GITHUB_ACCESS_TOKEN 57 | description: | 58 | Your GitHub personal access token as an env var on CircleCI. 59 | Go to your account's settings page (https://github.com/settings/tokens/new?description=circleci-bundle-update-pr%20token) and generate a personal access token with "repo" scope 60 | enterprise_octokit_access_token: 61 | type: env_var_name 62 | default: ENTERPRISE_OCTOKIT_ACCESS_TOKEN 63 | description: "Your GitHub Enterprise personal access token as an env var on CircleCI" 64 | enterprise_octokit_api_endpoint: 65 | type: string 66 | default: "$ENTERPRISE_OCTOKIT_API_ENDPOINT" 67 | description: "Your GitHub Enterprise api endpoint (e.g. https://www.example.com/api/v3)" 68 | no_output_timeout: 69 | type: string 70 | default: "10m" 71 | description: "Elapsed time the command can run without output. (e.g. 20m, 1.25h, 5s)" 72 | 73 | docker: 74 | - image: "<< parameters.image >>" 75 | 76 | steps: 77 | - checkout 78 | - install-circleci-bundle-update-pr: 79 | version: "<< parameters.version >>" 80 | - steps: << parameters.pre-bundle-update-pr >> 81 | - run-circleci-bundle-update-pr: 82 | assignees: "<< parameters.assignees >>" 83 | reviewers: "<< parameters.reviewers >>" 84 | labels: "<< parameters.labels >>" 85 | duplicate: "<< parameters.duplicate >>" 86 | git_user_name: "<< parameters.git_user_name >>" 87 | git_user_email: "<< parameters.git_user_email >>" 88 | branch: "<< parameters.branch >>" 89 | github_access_token: "<< parameters.github_access_token >>" 90 | enterprise_octokit_access_token: "<< parameters.enterprise_octokit_access_token >>" 91 | enterprise_octokit_api_endpoint: "<< parameters.enterprise_octokit_api_endpoint >>" 92 | no_output_timeout: "<< parameters.no_output_timeout >>" 93 | - steps: << parameters.post-bundle-update-pr >> 94 | -------------------------------------------------------------------------------- /src/commands/run-circleci-bundle-update-pr.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Run `circleci-bundle-update-pr`. 3 | 4 | parameters: 5 | assignees: 6 | type: string 7 | default: "" 8 | description: "Assign the PR to them. (e.g. alice,bob,carol)" 9 | reviewers: 10 | type: string 11 | default: "" 12 | description: "Request PR review to them. (e.g. alice,bob,carol)" 13 | labels: 14 | type: string 15 | default: "" 16 | description: "Add labels to the PR (e.g. In Review, Update)" 17 | duplicate: 18 | type: boolean 19 | default: false 20 | description: "Make PR even if it has already existed" 21 | git_user_name: 22 | type: string 23 | default: "$GIT_USER_NAME" 24 | description: "Username for commit" 25 | git_user_email: 26 | type: string 27 | default: "$GIT_USER_EMAIL" 28 | description: "E-mail for commit" 29 | branch: 30 | type: string 31 | default: "$CIRCLE_BRANCH" 32 | description: "Space separated branches. (e.g. 'master develop topic')" 33 | github_access_token: 34 | type: env_var_name 35 | default: GITHUB_ACCESS_TOKEN 36 | description: | 37 | Your GitHub personal access token as an env var on CircleCI. 38 | Go to your account's settings page (https://github.com/settings/tokens/new?description=circleci-bundle-update-pr%20token) and generate a personal access token with "repo" scope 39 | enterprise_octokit_access_token: 40 | type: env_var_name 41 | default: ENTERPRISE_OCTOKIT_ACCESS_TOKEN 42 | description: "Your GitHub Enterprise personal access token as an env var on CircleCI" 43 | enterprise_octokit_api_endpoint: 44 | type: string 45 | default: "$ENTERPRISE_OCTOKIT_API_ENDPOINT" 46 | description: "Your GitHub Enterprise api endpoint (e.g. https://www.example.com/api/v3)" 47 | no_output_timeout: 48 | type: string 49 | default: "10m" 50 | description: "Elapsed time the command can run without output. (e.g. 20m, 1.25h, 5s)" 51 | 52 | steps: 53 | - run: 54 | name: "Check params" 55 | command: | 56 | set -xe 57 | if [ -z "<< parameters.git_user_name >>" ]; then 58 | echo 'Either git_user_name or $GIT_USER_NAME is required' 59 | exit 1 60 | fi 61 | if [ -z "<< parameters.git_user_email >>" ]; then 62 | echo 'Either git_user_email or $GIT_USER_EMAIL is required' 63 | exit 1 64 | fi 65 | 66 | - run: 67 | name: "Export environment variables" 68 | command: | 69 | if [ -n "<< parameters.github_access_token >>" ]; then 70 | export GITHUB_ACCESS_TOKEN="<< parameters.github_access_token >>" 71 | fi 72 | if [ -n "<< parameters.enterprise_octokit_access_token >>" ]; then 73 | export ENTERPRISE_OCTOKIT_ACCESS_TOKEN="<< parameters.enterprise_octokit_access_token >>" 74 | fi 75 | if [ -n "<< parameters.enterprise_octokit_api_endpoint >>" ]; then 76 | export ENTERPRISE_OCTOKIT_API_ENDPOINT="<< parameters.enterprise_octokit_api_endpoint >>" 77 | fi 78 | 79 | - run: 80 | name: "Run `bundle update` and send PullRequest" 81 | no_output_timeout: "<< parameters.no_output_timeout >>" 82 | command: | 83 | set -xe 84 | 85 | args="" 86 | 87 | if [ -n "<< parameters.branch >>" ]; then 88 | args="$args << parameters.branch >>" 89 | fi 90 | 91 | if [ -n "<< parameters.assignees >>" ]; then 92 | args="$args --assignees << parameters.assignees >>" 93 | fi 94 | 95 | if [ -n "<< parameters.reviewers >>" ]; then 96 | args="$args --reviewers << parameters.reviewers >>" 97 | fi 98 | 99 | if [ -n "<< parameters.labels >>" ]; then 100 | args="$args --labels << parameters.labels >>" 101 | fi 102 | 103 | <<# parameters.duplicate >> 104 | args="$args --duplicate" 105 | <> 106 | 107 | circleci-bundle-update-pr "<< parameters.git_user_name >>" << parameters.git_user_email >> $args 108 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Unreleased 2 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.6.1...master) 3 | 4 | ## v1.6.1 5 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.6.0...1.6.1) 6 | 7 | * [Resolved] `open': can't modify frozen Hash: {} (FrozenError) 8 | * https://github.com/sue445/circleci-ruby-orbs/pull/61 9 | 10 | ## v1.6.0 11 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.5.2...1.6.0) 12 | 13 | ### `bundle-install` 14 | * Resolved deprecation warning on bundler 2.1+ 15 | * https://github.com/sue445/circleci-ruby-orbs/pull/54 16 | * Add params 17 | * https://github.com/sue445/circleci-ruby-orbs/pull/60 18 | * Add followings 19 | * `bundle_deployment` 20 | * `bundle_frozen` 21 | * `bundle_no_cache` 22 | * `bundle_no_prune` 23 | * `bundle_shebang` 24 | * `bundle_system` 25 | * `bundle_without` 26 | * `bundle_with` 27 | 28 | ## v1.5.2 29 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.5.0...1.5.2) 30 | 31 | ### `bundle-install` 32 | * Revert "Support bundler v2.1" 33 | * https://github.com/sue445/circleci-ruby-orbs/pull/52 34 | * :warning: v1.5.0 changes were reverted :pensive: 35 | 36 | ## v1.5.0 37 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.4.4...1.5.0) 38 | 39 | ### `bundle-install` 40 | * Support bundler v2.1 41 | * https://github.com/sue445/circleci-ruby-orbs/pull/49 42 | * Add followings params 43 | * `bundle_deployment` 44 | * `bundle_frozen` 45 | * `bundle_no_cache` 46 | * `bundle_no_prune` 47 | * `bundle_shebang` 48 | * `bundle_system` 49 | * `bundle_without` 50 | * `bundle_with` 51 | 52 | ## v1.4.4 53 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.4.3...1.4.4) 54 | 55 | ### `bundle-update-pr` 56 | * fix: use env_var_name instead of string to secure sensitive data 57 | * https://github.com/sue445/circleci-ruby-orbs/pull/45 58 | 59 | ## v1.4.3 60 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.4.2...1.4.3) 61 | 62 | ### `bundle-install` 63 | * Bugfix. fix typo in `bundle install` 64 | * https://github.com/sue445/circleci-ruby-orbs/pull/41 65 | 66 | ## v1.4.2 67 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.4.0...1.4.2) 68 | 69 | ### `bundle-install` 70 | * Add `update_always` param to `bundle-install` 71 | * https://github.com/sue445/circleci-ruby-orbs/pull/40 72 | 73 | ## v1.4.0 74 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.3.10...1.4.0) 75 | 76 | ### `bundle-install` 77 | * Supports repo without `Gemfile.lock` 78 | * https://github.com/sue445/circleci-ruby-orbs/pull/39 79 | 80 | ## v1.3.10 81 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.3.9...1.3.10) 82 | 83 | ### `bundle-update-pr` 84 | * Fixed. can't expand environment variable 85 | * https://github.com/sue445/circleci-ruby-orbs/pull/38 86 | 87 | ## v1.3.9 88 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.3.8...1.3.9) 89 | 90 | ### `bundle-update-pr` 91 | * Fixup PR #34 (Allow white space in git username) 92 | * https://github.com/sue445/circleci-ruby-orbs/pull/37 93 | 94 | ## v1.3.8 95 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.3.7...1.3.8) 96 | 97 | ### `bundle-update-pr` 98 | * Change default value for `branch` parameter to CI current branch 99 | * https://github.com/sue445/circleci-ruby-orbs/pull/36 100 | * https://github.com/sue445/circleci-ruby-orbs/issues/35 101 | 102 | ## v1.3.7 103 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.3.6...1.3.7) 104 | 105 | ### `bundle-update-pr` 106 | * Allow white space in git username 107 | * https://github.com/sue445/circleci-ruby-orbs/pull/34 108 | 109 | ## v1.3.0 110 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.2.0...1.3.0) 111 | 112 | ### `bundle-update-pr` 113 | * Add `bundle-update-pr` 114 | * https://github.com/sue445/circleci-ruby-orbs/pull/26 115 | * https://github.com/sue445/circleci-ruby-orbs/pull/27 116 | * https://github.com/sue445/circleci-ruby-orbs/pull/28 117 | 118 | ## v1.2.0 119 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.1.2...1.2.0) 120 | 121 | ### `bundle-install` 122 | * Add `bundle_gemfile` 123 | * https://github.com/sue445/circleci-ruby-orbs/pull/21 124 | 125 | ## v1.1.1 126 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.1.0...1.1.1) 127 | 128 | ### `bundle-install` 129 | * Tweak cache key format 130 | * https://github.com/sue445/circleci-ruby-orbs/pull/19 131 | 132 | ## v1.1.0 133 | [full changelog](http://github.com/sue445/circleci-ruby-orbs/compare/1.0.0...1.1.0) 134 | 135 | ### `bundle-install` 136 | * Add branch name to cache key 137 | * https://github.com/sue445/circleci-ruby-orbs/pull/16 138 | 139 | ## v1.0.0 140 | * first release 141 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # circleci-ruby-orbs 2 | CircleCI orb for ruby 3 | 4 | https://circleci.com/orbs/registry/orb/sue445/ruby-orbs 5 | 6 | [![CircleCI Orb Version](https://img.shields.io/badge/endpoint.svg?url=https://badges.circleci.io/orb/sue445/ruby-orbs)](https://circleci.com/orbs/registry/orb/sue445/ruby-orbs) 7 | [![CircleCI](https://circleci.com/gh/sue445/circleci-ruby-orbs/tree/master.svg?style=svg)](https://circleci.com/gh/sue445/circleci-ruby-orbs/tree/master) 8 | 9 | 10 | ## Requirements 11 | * Ruby and bundler 12 | * recommend [cimg/ruby](https://hub.docker.com/r/cimg/ruby/) 13 | 14 | ## Usage 15 | ### Common setting 16 | ```yml 17 | # .circleci/config.yml 18 | version: 2.1 19 | 20 | orbs: 21 | # Use specific version 22 | # see. https://github.com/sue445/circleci-ruby-orbs/releases 23 | ruby-orbs: sue445/ruby-orbs@1.4.4 24 | 25 | # or 26 | # Use latest version 27 | # ruby-orbs: sue445/ruby-orbs@volatile 28 | ``` 29 | 30 | ### bundle-install 31 | Run `bundle install` using cache. 32 | 33 | #### for app repo (`Gemfile.lock` is committed) 34 | ```yml 35 | # .circleci/config.yml 36 | jobs: 37 | rspec: 38 | docker: 39 | - image: circleci/ruby 40 | 41 | steps: 42 | - checkout 43 | 44 | - ruby-orbs/bundle-install 45 | # or 46 | - ruby-orbs/bundle-install: 47 | cache_key_prefix: "v1-bundle" 48 | bundle_jobs: 4 49 | bundle_retry: 3 50 | bundle_path: "vendor/bundle" 51 | bundle_gemfile: "Gemfile" 52 | bundle_clean: true 53 | bundle_extra_args: "" 54 | restore_bundled_with: true 55 | 56 | # Add your job (e.g. rspec, rubocop) 57 | - run: bundle exec rspec 58 | ``` 59 | 60 | #### for gem repo (`Gemfile.lock` is not committed) 61 | ```yml 62 | # .circleci/config.yml 63 | jobs: 64 | rspec: 65 | docker: 66 | - image: circleci/ruby 67 | 68 | steps: 69 | - checkout 70 | 71 | - ruby-orbs/bundle-install: 72 | with_gemfile_lock: false 73 | gemspec_name: "yourgem" 74 | # or 75 | - ruby-orbs/bundle-install: 76 | with_gemfile_lock: false 77 | gemspec_name: "yourgem" 78 | cache_key_prefix: "v1-bundle" 79 | bundle_jobs: 4 80 | bundle_retry: 3 81 | bundle_path: "vendor/bundle" 82 | bundle_clean: true 83 | bundle_extra_args: "" 84 | update_always: false 85 | 86 | # Add your job (e.g. rspec, rubocop) 87 | - run: bundle exec rspec 88 | ``` 89 | 90 | #### Parameters 91 | * `cache_key_prefix` : Key prefix of cache (default: `v1-bundle`) 92 | * `bundle_jobs` : Passed to `bundle install --jobs` (default: `4`) 93 | * `bundle_retry` : Passed to `bundle install --retry` (default: `3`) 94 | * `bundle_path` : Passed to `bundle install --path` or use `bundle config set path` (default: `vendor/bundle`) 95 | * `bundle_gemfile` : Passed to `bundle install --gemfile` (default: `Gemfile`) 96 | * `bundle_clean` : Whether pass `--clean` to `bundle install` or use `bundle config set --local clean 'true'` (default: `true`) 97 | * `bundle_deployment` : Whether path to `--deployment` or run `bundle config set deployment 'true'` (default: `false`) 98 | * `bundle_frozen` : Whether path to `--frozen` or run `bundle config set frozen 'true'` (default: `false`) 99 | * `bundle_no_cache` : Whether path to `--no-cache` or run `bundle config set no-cache 'true'` (default: `false`) 100 | * `bundle_no_prune` : Whether path to `--no-prune` or run `bundle config set no-prune 'true'` (default: `false`) 101 | * `bundle_shebang` : Whether path to `--shebang` or run `bundle config set shebang 'true'` (default: `false`) 102 | * `bundle_system` : Whether path to `--system` or run `bundle config set system 'true'` (default: `false`) 103 | * `bundle_without` : Passed to `bundle install --without` or `bundle config set without` 104 | * `bundle_with` : Passed to `bundle install --with` or `bundle config set with` 105 | * `bundle_extra_args` : Arguments to pass to `bundle install` 106 | * `restore_bundled_with` : Whether resolve bundler version difference between `Gemfile.lock` and pre-installed in CI (default: `true`) 107 | * `with_gemfile_lock` : Whether using `Gemfile.lock` for cache key (default: `true`) 108 | * `gemspec_name` : gemspec name (required if `with_gemfile_lock` is false) 109 | * `update_always` : Whether run always `bundle update` when `with_gemfile_lock` is disabled (default: `false`) 110 | 111 | ### bundle-update-pr 112 | Run `bundle update` and send PullRequest. 113 | 114 | Uses https://github.com/masutaka/circleci-bundle-update-pr 115 | 116 | ```yml 117 | workflows: 118 | version: 2 119 | nightly: 120 | triggers: 121 | - schedule: 122 | cron: "00 10 * * 5" 123 | filters: 124 | branches: 125 | only: master 126 | jobs: 127 | - ruby-orbs/bundle-update-pr 128 | # or 129 | - ruby-orbs/bundle-update-pr: 130 | image: "circleci/ruby:2.5.3" 131 | pre-bundle-update-pr: 132 | - run: 133 | name: "Set timezone to Asia/Tokyo" 134 | command: "sudo cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime" 135 | - ruby-orbs/bundle-install 136 | git_user_name: "yourname" 137 | git_user_email: "you@example.com" 138 | github_access_token: GITHUB_ACCESS_TOKEN 139 | ``` 140 | 141 | #### Parameters 142 | * `image` : Image for `bundle update` (default: `circleci/ruby`) 143 | * `pre-bundle-update-pr` : Run steps before `circleci-bundle-update-pr` (default: `[]`) 144 | * `post-bundle-update-pr` : Run steps after `circleci-bundle-update-pr` (default: `[]`) 145 | * `version` : circleci-bundle-update-pr vesion. default is latest 146 | * `assignees` : Assign the PR to them. (e.g. alice,bob,carol) 147 | * `reviewers` : Request PR review to them. (e.g. alice,bob,carol) 148 | * `labels` : Add labels to the PR (e.g. In Review, Update) 149 | * `duplicate` : Make PR even if it has already existed (default: `false`) 150 | * `git_user_name` : Username for commit (default: `$GIT_USER_NAME`) 151 | * `git_user_email` : E-mail for commit (default: `$GIT_USER_EMAIL`) 152 | * `branch` : Space separated branches. (e.g. `master develop topic`) (default: `$CIRCLE_BRANCH`) 153 | * `github_access_token` : Your GitHub personal access token as an env var on CircleCI (default: `GITHUB_ACCESS_TOKEN`) 154 | * Go to [your account's settings page](https://github.com/settings/tokens/new?description=circleci-bundle-update-pr%20token) and generate a personal access token with "repo" scope 155 | * Use the CircleCI UI to set the GITHUB_ACCESS_TOKEN environment variable. 156 | * `enterprise_octokit_access_token` : Your GitHub Enterprise personal access token as an env var on CircleCI (default. `ENTERPRISE_OCTOKIT_ACCESS_TOKEN`) 157 | * Use the CircleCI UI to set the ENTERPRISE_OCTOKIT_ACCESS_TOKEN environment variable. 158 | * `enterprise_octokit_api_endpoint` : Your GitHub Enterprise api endpoint (e.g. https://www.example.com/api/v3) (default: `$ENTERPRISE_OCTOKIT_API_ENDPOINT`) 159 | * `no_output_timeout` : Elapsed time the command can run without output. (e.g. 20m, 1.25h, 5s) (default: `10m`) 160 | 161 | ## External 162 | * Smoke test repository for circleci-ruby-orbs 163 | * https://github.com/sue445/circleci-ruby-orbs-test 164 | -------------------------------------------------------------------------------- /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | orbs: 4 | orb-tools: circleci/orb-tools@2.0.2 5 | 6 | jobs: 7 | push_latest_version_tag: 8 | docker: 9 | - image: circleci/ruby:2.7 10 | working_directory: ~/app 11 | steps: 12 | - checkout 13 | - add_ssh_keys: 14 | fingerprints: 15 | - "43:39:3a:d1:90:49:a4:85:db:17:41:ce:88:55:44:92" 16 | - run: curl -fLSs https://circle.ci/cli | sudo bash 17 | - run: 18 | name: Setup git 19 | command: | 20 | git config push.default current 21 | git config user.email "$EMAIL" 22 | git config user.name "CircleCI" 23 | - run: ruby .circleci/push_latest_version_tag.rb sue445/ruby-orbs 24 | 25 | smoke_test: 26 | # c.f. https://github.com/CircleCI-Public/artifactory-orb/blob/39e72bee4c884eae0adde4c3204f0e18d727bc4b/.circleci/config.yml 27 | docker: 28 | - image: circleci/node:10 29 | parameters: 30 | branch: 31 | type: string 32 | description: branch of circleci-ruby-orbs-test 33 | working_directory: ~/app 34 | steps: 35 | - checkout 36 | - add_ssh_keys: 37 | fingerprints: 38 | - "43:39:3a:d1:90:49:a4:85:db:17:41:ce:88:55:44:92" 39 | - run: ./.circleci/setup_smoke_test.sh << parameters.branch >> 40 | 41 | - run: 42 | name: Poll for result 43 | no_output_timeout: 5m 44 | command: | 45 | export SMOKE_BRANCH="smoke_test/${CIRCLE_SHA1}_<< parameters.branch >>" 46 | echo "Smoke test branch: https://github.com/sue445/circleci-ruby-orbs-test/commits/${SMOKE_BRANCH}" 47 | 48 | curl https://circleci.com/api/v1.1/project/github/sue445/circleci-ruby-orbs-test/tree/${SMOKE_BRANCH}?limit=1 > build-result.json 49 | BUILD_URL=$(cat build-result.json | jq -r '.[0].build_url') 50 | echo "Monitoring Build: $BUILD_URL for status" 51 | while true; do 52 | curl https://circleci.com/api/v1.1/project/github/sue445/circleci-ruby-orbs-test/tree/${SMOKE_BRANCH}?limit=1 > build-result.json 53 | LIFECYCLE=$(cat build-result.json | jq -r '.[0].lifecycle') 54 | if [ "$LIFECYCLE" == "finished" ];then 55 | STATUS=$(cat build-result.json | jq -r '.[0].status') 56 | if [ "$STATUS" == "success" ];then 57 | echo "Test project build successful." 58 | exit 0 59 | else 60 | exit 1 61 | fi 62 | else 63 | sleep 10 64 | fi 65 | done 66 | 67 | workflows: 68 | version: 2 69 | 70 | # c.f. https://github.com/CircleCI-Public/hello-orb/blob/c43a73505b996c29688510b5d60d17130ae937b7/.circleci/config.yml 71 | btd: 72 | jobs: 73 | - orb-tools/pack: 74 | source-dir: src/ 75 | destination-orb-path: packed/orb.yml 76 | workspace-path: packed/orb.yml 77 | artifact-path: packed/orb.yml 78 | 79 | - orb-tools/test-in-builds: 80 | name: Test test/bundler-v1/bundle-install_test.yml 81 | orb-location: packed/orb.yml 82 | orb-name: ruby-orbs 83 | test-steps: 84 | - orb-tools/local-test-build: 85 | test-config-location: test/bundler-v1/bundle-install_test.yml 86 | attach-workspace: true 87 | checkout: true 88 | requires: 89 | - orb-tools/pack 90 | 91 | - orb-tools/test-in-builds: 92 | name: Test test/bundler-v1/bundle-install-gemspec_test.yml 93 | orb-location: packed/orb.yml 94 | orb-name: ruby-orbs 95 | test-steps: 96 | - orb-tools/local-test-build: 97 | test-config-location: test/bundler-v1/bundle-install-gemspec_test.yml 98 | attach-workspace: true 99 | checkout: true 100 | requires: 101 | - orb-tools/pack 102 | 103 | - orb-tools/test-in-builds: 104 | name: Test test/bundler-v1/bundle-update-pr_test.yml 105 | orb-location: packed/orb.yml 106 | orb-name: ruby-orbs 107 | test-steps: 108 | - orb-tools/local-test-build: 109 | test-config-location: test/bundler-v1/bundle-update-pr_test.yml 110 | attach-workspace: true 111 | checkout: true 112 | requires: 113 | - orb-tools/pack 114 | 115 | - orb-tools/test-in-builds: 116 | name: Test test/bundler-v2/bundle-install_test.yml 117 | orb-location: packed/orb.yml 118 | orb-name: ruby-orbs 119 | test-steps: 120 | - orb-tools/local-test-build: 121 | test-config-location: test/bundler-v2/bundle-install_test.yml 122 | attach-workspace: true 123 | checkout: true 124 | requires: 125 | - orb-tools/pack 126 | 127 | - orb-tools/test-in-builds: 128 | name: Test test/bundler-v2/bundle-install-gemspec_test.yml 129 | orb-location: packed/orb.yml 130 | orb-name: ruby-orbs 131 | test-steps: 132 | - orb-tools/local-test-build: 133 | test-config-location: test/bundler-v2/bundle-install-gemspec_test.yml 134 | attach-workspace: true 135 | checkout: true 136 | requires: 137 | - orb-tools/pack 138 | 139 | - orb-tools/test-in-builds: 140 | name: Test test/bundler-v2/bundle-update-pr_test.yml 141 | orb-location: packed/orb.yml 142 | orb-name: ruby-orbs 143 | test-steps: 144 | - orb-tools/local-test-build: 145 | test-config-location: test/bundler-v2/bundle-update-pr_test.yml 146 | attach-workspace: true 147 | checkout: true 148 | requires: 149 | - orb-tools/pack 150 | 151 | - orb-tools/publish: 152 | orb-path: packed/orb.yml 153 | orb-ref: "sue445/ruby-orbs@dev:${CIRCLE_SHA1}" 154 | publish-token-variable: "$CIRCLECI_API_TOKEN" 155 | attach-workspace: true 156 | checkout: false 157 | requires: [orb-tools/pack] 158 | context: CircleCI 159 | 160 | - smoke_test: 161 | name: smoke_test (bundler v2.1) 162 | branch: master 163 | requires: 164 | - orb-tools/publish 165 | - Test test/bundler-v2/bundle-install_test.yml 166 | - Test test/bundler-v2/bundle-install-gemspec_test.yml 167 | - Test test/bundler-v2/bundle-update-pr_test.yml 168 | 169 | - smoke_test: 170 | name: smoke_test (bundler v1.17) 171 | branch: bundler_1.17 172 | requires: 173 | - orb-tools/publish 174 | - Test test/bundler-v1/bundle-install_test.yml 175 | - Test test/bundler-v1/bundle-install-gemspec_test.yml 176 | - Test test/bundler-v1/bundle-update-pr_test.yml 177 | 178 | - orb-tools/increment: 179 | orb-path: packed/orb.yml 180 | orb-ref: "sue445/ruby-orbs" 181 | segment: "patch" 182 | publish-token-variable: "$CIRCLECI_API_TOKEN" 183 | attach-workspace: true 184 | checkout: false 185 | requires: 186 | - Test test/bundler-v1/bundle-install_test.yml 187 | - Test test/bundler-v1/bundle-install-gemspec_test.yml 188 | - Test test/bundler-v1/bundle-update-pr_test.yml 189 | - Test test/bundler-v2/bundle-install_test.yml 190 | - Test test/bundler-v2/bundle-install-gemspec_test.yml 191 | - Test test/bundler-v2/bundle-update-pr_test.yml 192 | filters: 193 | branches: 194 | only: master 195 | context: CircleCI 196 | 197 | - push_latest_version_tag: 198 | requires: [orb-tools/increment] 199 | filters: 200 | branches: 201 | only: master 202 | tags: 203 | ignore: /.*/ 204 | context: CircleCI 205 | 206 | release: 207 | jobs: 208 | - orb-tools/pack: 209 | source-dir: src/ 210 | destination-orb-path: packed/orb.yml 211 | workspace-path: packed/orb.yml 212 | artifact-path: packed/orb.yml 213 | filters: 214 | tags: 215 | only: /^[0-9.]+\.0$/ 216 | branches: 217 | ignore: /.*/ 218 | 219 | - orb-tools/publish: 220 | orb-path: packed/orb.yml 221 | orb-ref: "sue445/ruby-orbs@${CIRCLE_TAG}" 222 | publish-token-variable: "$CIRCLECI_API_TOKEN" 223 | attach-workspace: true 224 | checkout: false 225 | requires: [orb-tools/pack] 226 | filters: 227 | tags: 228 | only: /^[0-9.]+\.0$/ 229 | branches: 230 | ignore: /.*/ 231 | context: CircleCI 232 | -------------------------------------------------------------------------------- /src/commands/bundle-install.yml: -------------------------------------------------------------------------------- 1 | description: | 2 | Run `bundle install` using cache. 3 | 4 | parameters: 5 | cache_key_prefix: 6 | type: string 7 | default: "v1-bundle" 8 | description: "Key prefix of cache" 9 | bundle_jobs: 10 | type: integer 11 | default: 4 12 | description: "Passed to `bundle install --jobs`" 13 | bundle_retry: 14 | type: integer 15 | default: 3 16 | description: "Passed to `bundle install --retry`" 17 | bundle_path: 18 | type: string 19 | default: "vendor/bundle" 20 | description: "Passed to `bundle install --path` or use `bundle config set path`" 21 | bundle_gemfile: 22 | type: string 23 | default: "Gemfile" 24 | description: "Passed to `bundle install --gemfile`" 25 | bundle_clean: 26 | type: boolean 27 | default: true 28 | description: "Whether pass `--clean` to `bundle install` or use `bundle config set --local clean 'true'`" 29 | bundle_deployment: 30 | type: boolean 31 | default: false 32 | description: "Whether path to `--deployment` or run `bundle config set deployment 'true'`" 33 | bundle_frozen: 34 | type: boolean 35 | default: false 36 | description: "Whether path to `--frozen` or run `bundle config set frozen 'true'`" 37 | bundle_no_cache: 38 | type: boolean 39 | default: false 40 | description: "Whether path to `--no-cache` or run `bundle config set no-cache 'true'`" 41 | bundle_no_prune: 42 | type: boolean 43 | default: false 44 | description: "Whether path to `--no-prune` or run `bundle config set no-prune 'true'`" 45 | bundle_shebang: 46 | type: boolean 47 | default: false 48 | description: "Whether path to `--shebang` or run `bundle config set shebang 'true'`" 49 | bundle_system: 50 | type: boolean 51 | default: false 52 | description: "Whether path to `--system` or run `bundle config set system 'true'`" 53 | bundle_without: 54 | type: string 55 | default: "" 56 | description: "Passed to `bundle install --without` or `bundle config set without`" 57 | bundle_with: 58 | type: string 59 | default: "" 60 | description: "Passed to `bundle install --with` or `bundle config set with`" 61 | bundle_extra_args: 62 | type: string 63 | default: "" 64 | description: "Arguments to pass to `bundle install`" 65 | restore_bundled_with: 66 | type: boolean 67 | default: true 68 | description: "Whether resolve bundler version difference between `Gemfile.lock` and pre-installed in CI" 69 | with_gemfile_lock: 70 | type: boolean 71 | default: true 72 | description: "Whether using `Gemfile.lock` for cache key" 73 | gemspec_name: 74 | type: string 75 | default: "" 76 | description: "gemspec name (required if `with_gemfile_lock` is false)" 77 | update_always: 78 | type: boolean 79 | default: false 80 | description: "Whether run always `bundle update` when `with_gemfile_lock` is disabled" 81 | 82 | steps: 83 | - when: 84 | condition: << parameters.with_gemfile_lock >> 85 | steps: 86 | - restore_cache: 87 | keys: 88 | - << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }}-{{ checksum "<< parameters.bundle_gemfile >>.lock" }}-{{ .Branch }} 89 | - << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }}-{{ checksum "<< parameters.bundle_gemfile >>.lock" }} 90 | - << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }} 91 | - << parameters.cache_key_prefix >> 92 | 93 | - unless: 94 | condition: << parameters.with_gemfile_lock >> 95 | steps: 96 | - restore_cache: 97 | keys: 98 | - << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }}-{{ checksum "<< parameters.bundle_gemfile >>" }}-{{ checksum "<< parameters.gemspec_name >>.gemspec" }}-{{ .Branch }} 99 | - << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }}-{{ checksum "<< parameters.bundle_gemfile >>" }}-{{ checksum "<< parameters.gemspec_name >>.gemspec" }} 100 | - << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }}-{{ checksum "<< parameters.bundle_gemfile >>" }} 101 | - << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }} 102 | - << parameters.cache_key_prefix >> 103 | 104 | - run: 105 | name: bundle install 106 | command: | 107 | set -xe 108 | if [ $(bundle -v | grep "Bundler version 1." | wc -l) = "1" ]; then 109 | # bundler v1.x 110 | use_bundle_config_set="0" 111 | elif [ $(bundle -v | grep "Bundler version 2.0." | wc -l) = "1" ]; then 112 | # bundler v2.0.x 113 | use_bundle_config_set="0" 114 | else 115 | # bundler v2.1+ 116 | use_bundle_config_set="1" 117 | fi 118 | 119 | bundle_install_args="--jobs=<< parameters.bundle_jobs >> --retry=<< parameters.bundle_retry >> --gemfile=<< parameters.bundle_gemfile >>" 120 | 121 | if [ $use_bundle_config_set = "0" ]; then 122 | bundle_install_args="$bundle_install_args --path=<< parameters.bundle_path >>" 123 | 124 | <<# parameters.bundle_clean >> 125 | bundle_install_args="$bundle_install_args --clean" 126 | <> 127 | 128 | <<# parameters.bundle_deployment >> 129 | bundle_install_args="$bundle_install_args --deployment" 130 | <> 131 | 132 | <<# parameters.bundle_frozen >> 133 | bundle_install_args="$bundle_install_args --frozen" 134 | <> 135 | 136 | <<# parameters.bundle_no_cache >> 137 | bundle_install_args="$bundle_install_args --no-cache" 138 | <> 139 | 140 | <<# parameters.bundle_no_prune >> 141 | bundle_install_args="$bundle_install_args --no-prune" 142 | <> 143 | 144 | <<# parameters.bundle_shebang >> 145 | bundle_install_args="$bundle_install_args --shebang" 146 | <> 147 | 148 | <<# parameters.bundle_system >> 149 | bundle_install_args="$bundle_install_args --system" 150 | <> 151 | 152 | bundle_without_param="<< parameters.bundle_without >>" 153 | if [ -n "$bundle_without_param" ]; then 154 | bundle_install_args="$bundle_install_args --without $bundle_without_param" 155 | fi 156 | 157 | bundle_with_param="<< parameters.bundle_with >>" 158 | if [ -n "$bundle_with_param" ]; then 159 | bundle_install_args="$bundle_install_args --with $bundle_with_param" 160 | fi 161 | else 162 | bundle config set path "<< parameters.bundle_path >>" 163 | 164 | <<# parameters.bundle_clean >> 165 | # NOTE: `--local` is required because `Cleaning all the gems on your system is dangerous!` error when `bundle install` 166 | # c.f. https://app.circleci.com/jobs/github/sue445/circleci-ruby-orbs/1011 167 | bundle config set --local clean 'true' 168 | <> 169 | 170 | <<# parameters.bundle_deployment >> 171 | bundle config set bundle_deployment 'true' 172 | <> 173 | 174 | <<# parameters.bundle_frozen >> 175 | bundle config set frozen 'true' 176 | <> 177 | 178 | <<# parameters.bundle_no_cache >> 179 | bundle config set no-cache 'true' 180 | <> 181 | 182 | <<# parameters.bundle_no_prune >> 183 | bundle config set no-prune 'true' 184 | <> 185 | 186 | <<# parameters.bundle_shebang >> 187 | bundle config set shebang 'true' 188 | <> 189 | 190 | <<# parameters.bundle_system >> 191 | bundle config set system 'true' 192 | <> 193 | 194 | bundle_without_param="<< parameters.bundle_without >>" 195 | if [ -n "$bundle_without_param" ]; then 196 | bundle config set without "$bundle_without_param" 197 | fi 198 | 199 | bundle_with_param="<< parameters.bundle_with >>" 200 | if [ -n "$bundle_with_param" ]; then 201 | bundle config set with "$bundle_with_param" 202 | fi 203 | fi 204 | 205 | bundle_extra_args="<< parameters.bundle_extra_args >>" 206 | if [ -n "$bundle_extra_args" ]; then 207 | bundle_install_args="$bundle_install_args $bundle_extra_args" 208 | fi 209 | 210 | with_gemfile_lock="false" 211 | <<# parameters.with_gemfile_lock >> 212 | with_gemfile_lock="true" 213 | <> 214 | 215 | if [ $with_gemfile_lock == "true" ]; then 216 | bundle install $bundle_install_args 217 | else 218 | run_bundle_install="true" 219 | <<# parameters.update_always >> 220 | run_bundle_install="false" 221 | <> 222 | 223 | if [ $run_bundle_install == "true" ]; then 224 | set +e 225 | bundle install $bundle_install_args 226 | ret=$? 227 | set -e 228 | else 229 | ret=1 230 | fi 231 | 232 | # Retry with `bundle update` if `bundle install` is failed 233 | if [ $ret -ne 0 ]; then 234 | if [ $use_bundle_config_set = "0" ]; then 235 | # NOTE: `.bundle/config` is not created after `bundle install` is failed 236 | mkdir -p .bundle/ 237 | echo '---' > .bundle/config 238 | echo 'BUNDLE_PATH: "<< parameters.bundle_path >>"' >> .bundle/config 239 | fi 240 | 241 | bundle update --jobs=<< parameters.bundle_jobs >> 242 | fi 243 | fi 244 | 245 | - when: 246 | condition: << parameters.restore_bundled_with >> 247 | steps: 248 | - when: 249 | condition: << parameters.with_gemfile_lock >> 250 | steps: 251 | - run: 252 | name: "restore-bundled-with" 253 | command: | 254 | set -xe 255 | 256 | if [ "<< parameters.bundle_gemfile >>" == "Gemfile" ]; then 257 | gem install git --version 1.7.0 --no-document 258 | gem install restore_bundled_with --no-document 259 | restore-bundled-with 260 | fi 261 | 262 | - when: 263 | condition: << parameters.with_gemfile_lock >> 264 | steps: 265 | - save_cache: 266 | key: << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }}-{{ checksum "<< parameters.bundle_gemfile >>.lock" }}-{{ .Branch }} 267 | paths: 268 | - << parameters.bundle_path >> 269 | 270 | - unless: 271 | condition: << parameters.with_gemfile_lock >> 272 | steps: 273 | - save_cache: 274 | key: << parameters.cache_key_prefix >>-{{ .Environment.CIRCLE_JOB }}-{{ checksum "<< parameters.bundle_gemfile >>" }}-{{ checksum "<< parameters.gemspec_name >>.gemspec" }}-{{ .Branch }} 275 | paths: 276 | - << parameters.bundle_path >> 277 | - Gemfile.lock 278 | --------------------------------------------------------------------------------