8d0d2219 by Jeff Balicki

deploy

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 23cbefe0
Showing 1000 changed files with 4197 additions and 13 deletions

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

---
BUNDLE_PATH: "vendor/bundle"
File mode changed
source 'https://rubygems.org'
gem 'capistrano', '~> 3.4.0'
gem "capistrano", "~> 3.10"
gem 'capistrano-composer'
......
GEM
remote: https://rubygems.org/
specs:
capistrano (3.4.0)
airbrussh (1.4.1)
sshkit (>= 1.6.1, != 1.7.0)
capistrano (3.17.1)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (~> 1.3)
sshkit (>= 1.9.0)
capistrano-composer (0.0.6)
capistrano (>= 3.0.0.pre)
i18n (0.7.0)
concurrent-ruby (1.1.10)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (3.0.2)
rake (10.5.0)
sshkit (1.8.1)
net-ssh (7.0.1)
rake (13.0.6)
sshkit (1.21.2)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
PLATFORMS
ruby
x86_64-darwin-21
x86_64-darwin-22
DEPENDENCIES
capistrano (~> 3.4.0)
capistrano (~> 3.10)
capistrano-composer
BUNDLED WITH
2.3.21
......
set :application, 'tenzing-web-2023'
set :application, 'tenzing-web-2019-staging'
set :repo_url, 'git@git.gotenzing.com:tenzing/Tenzing-Web-2023.git'
# Branch options
......@@ -33,7 +33,7 @@ namespace :deploy do
desc 'Install composer packages'
task :install_composer_packages do
on roles(:web), in: :sequence, wait: 5 do
execute("cd '#{release_path}'; composer install --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader")
execute("cd '#{release_path}'; composer update --no-dev --prefer-dist --no-interaction --quiet --optimize-autoloader")
end
end
end
......
set :application, 'tenzing-web-2023-staging'
set :application, 'tenzing-web-2019-staging'
set :stage, :staging
set :branch, :staging
set :branch, :main
# Simple Role Syntax
# ==================
......
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
str = ARGV.first
if str
str = str.b[/\A_(.*)_\z/, 1]
if str and Gem::Version.correct?(str)
version = str
ENV['BUNDLER_VERSION'] = str
ARGV.shift
end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('bundler', 'bundle', version)
else
gem "bundler", version
load Gem.bin_path("bundler", "bundle", version)
end
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'bundler' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
version = ">= 0.a"
str = ARGV.first
if str
str = str.b[/\A_(.*)_\z/, 1]
if str and Gem::Version.correct?(str)
version = str
ENV['BUNDLER_VERSION'] = str
ARGV.shift
end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('bundler', 'bundler', version)
else
gem "bundler", version
load Gem.bin_path("bundler", "bundler", version)
end
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'capistrano' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
Gem.use_gemdeps
version = ">= 0.a"
str = ARGV.first
if str
str = str.b[/\A_(.*)_\z/, 1]
if str and Gem::Version.correct?(str)
version = str
ARGV.shift
end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('capistrano', 'cap', version)
else
gem "capistrano", version
load Gem.bin_path("capistrano", "cap", version)
end
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'capistrano' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
Gem.use_gemdeps
version = ">= 0.a"
str = ARGV.first
if str
str = str.b[/\A_(.*)_\z/, 1]
if str and Gem::Version.correct?(str)
version = str
ARGV.shift
end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('capistrano', 'capify', version)
else
gem "capistrano", version
load Gem.bin_path("capistrano", "capify", version)
end
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'rake' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'rubygems'
Gem.use_gemdeps
version = ">= 0.a"
str = ARGV.first
if str
str = str.b[/\A_(.*)_\z/, 1]
if str and Gem::Version.correct?(str)
version = str
ARGV.shift
end
end
if Gem.respond_to?(:activate_bin_path)
load Gem.activate_bin_path('rake', 'rake', version)
else
gem "rake", version
load Gem.bin_path("rake", "rake", version)
end
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
version: 2.1
executors:
ruby:
parameters:
version:
description: "Ruby version number"
default: "3.1"
type: string
docker:
- image: ruby:<< parameters.version >>
commands:
bundle_install:
description: Install Ruby dependencies with Bundler
parameters:
key:
description: "Cache key"
default: "3.1"
type: string
steps:
- restore_cache:
keys:
- bundle-v1-{{ arch }}-<< parameters.key >>
- run:
name: Install Ruby Dependencies
command: |
gem install bundler --conservative --no-document || \
gem install rubygems-update -v '<3' && update_rubygems && gem install bundler -v '<2' --no-document
bundle config --local path vendor/bundle
bundle check || (bundle install --jobs=4 --retry=3 && bundle clean)
- save_cache:
paths:
- ./vendor/bundle
key: bundle-v1-{{ arch }}-<< parameters.key >>-{{ checksum "Gemfile.lock" }}
jobs:
rubocop:
executor:
name: ruby
version: "2.7"
steps:
- checkout
- bundle_install:
key: "2.7"
- run: bundle exec rubocop
spec:
parameters:
ruby:
description: "Ruby version number"
default: "3.1"
type: string
executor:
name: ruby
version: << parameters.ruby >>
steps:
- checkout
- run: echo sshkit=master >> $BASH_ENV
- bundle_install:
key: << parameters.ruby >>
- run: bundle exec rake test
spec_legacy_ruby:
parameters:
ruby:
description: "Ruby version number"
default: "1.9"
type: string
sshkit:
description: "sshkit version number"
default: "1.6.1"
type: string
executor:
name: ruby
version: << parameters.ruby >>
steps:
- checkout
- run: |
echo "export sshkit=<< parameters.sshkit >>" >> $BASH_ENV
if [ "<< parameters.ruby >>" == "1.9" ]; then
echo "export RUBYOPT=-Ku" >> $BASH_ENV
fi
- bundle_install:
key: << parameters.ruby >>-<< parameters.sshkit >>
- run: bundle exec rake test
workflows:
version: 2
commit-workflow:
jobs:
- rubocop
- spec:
matrix: &matrix
parameters:
ruby:
- "2.4"
- "2.5"
- "2.6"
- "2.7"
- "3.0"
- "3.1"
- spec_legacy_ruby:
matrix: &legacy_ruby_matrix
parameters:
ruby:
- "1.9"
- "2.0"
- "2.1"
- "2.2"
- "2.3"
sshkit:
- "1.6.1"
- "1.7.1"
- master
exclude:
- ruby: "1.9"
sshkit: master
cron-workflow:
jobs:
- rubocop
- spec:
matrix:
<<: *matrix
- spec_legacy_ruby:
matrix:
<<: *legacy_ruby_matrix
triggers:
- schedule:
cron: "0 13 * * 6"
filters:
branches:
only:
- main
name-template: "$RESOLVED_VERSION"
tag-template: "v$RESOLVED_VERSION"
categories:
- title: "⚠️ Breaking Changes"
label: "⚠️ Breaking"
- title: " New Features"
label: " Feature"
- title: "🐛 Bug Fixes"
label: "🐛 Bug Fix"
- title: "📚 Documentation"
label: "📚 Docs"
- title: "🏠 Housekeeping"
label: "🏠 Housekeeping"
version-resolver:
minor:
labels:
- "⚠️ Breaking"
- " Feature"
default: patch
change-template: "- $TITLE (#$NUMBER) @$AUTHOR"
no-changes-template: "- No changes"
template: |
$CHANGES
**Full Changelog:** https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
name: Release Drafter
on:
push:
branches:
- main
jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/log/
/pkg/
/spec/reports/
/tmp/
*.bundle
*.so
*.o
*.a
mkmf.log
AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
TargetRubyVersion: 1.9
Exclude:
- "*.gemspec"
- "vendor/**/*"
Layout/EndOfLine:
Enabled: false
Layout/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space
Metrics/AbcSize:
Exclude:
- "test/**/*"
Metrics/MethodLength:
Exclude:
- "test/**/*"
Metrics/ClassLength:
Exclude:
- "test/**/*"
Style/BarePercentLiterals:
EnforcedStyle: percent_q
Style/ClassAndModuleChildren:
Enabled: false
Style/Documentation:
Enabled: false
Style/DoubleNegation:
Enabled: false
Style/Encoding:
Enabled: false
Style/HashSyntax:
EnforcedStyle: hash_rockets
Style/StringLiterals:
EnforcedStyle: double_quotes
Style/TrivialAccessors:
AllowPredicates: true
Release notes for this project are kept here: https://github.com/mattbrictson/airbrussh/releases
Contributor Code of Conduct
As contributors and maintainers of this project, we pledge to respect all
people who contribute through reporting issues, posting feature requests,
updating documentation, submitting pull requests or patches, and other
activities.
We are committed to making participation in this project a harassment-free
experience for everyone, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal appearance,
body size, race, ethnicity, age, or religion.
Examples of unacceptable behavior by participants include the use of sexual
language or imagery, derogatory comments or personal attacks, trolling, public
or private harassment, insults, or other unprofessional conduct.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct. Project maintainers who do not
follow the Code of Conduct may be removed from the project team.
This code of conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by opening an issue or contacting one or more of the project
maintainers.
This Code of Conduct is adapted from the Contributor Covenant
(http://contributor-covenant.org), version 1.1.0, available at
http://contributor-covenant.org/version/1/1/0/
# Contributing to airbrussh
Have a feature idea, bug fix, or refactoring suggestion? Contributions are welcome!
## Pull requests
1. Check [Issues][] to see if your contribution has already been discussed and/or implemented.
2. If not, open an issue to discuss your contribution. I won't accept all changes and do not want to waste your time.
3. Once you have the :thumbsup:, fork the repo, make your changes, and open a PR.
## Coding guidelines
* This project has a coding style enforced by [RuboCop][]. Use hash rockets and double-quoted strings, and otherwise try to follow the [Ruby style guide][style].
* Writing tests is strongly encouraged! This project uses Minitest.
## Getting started
Note that Bundler 1.10 is required for development. Run `gem update bundler` to get the latest version.
After checking out the airbrussh repo, run `bin/setup` to install dependencies. Run `rake` to execute airbrussh's tests and RuboCop checks.
Airbrussh is designed to work against multiple versions of SSHKit and Ruby. In order to test this, we use the environment variable `sshkit` in order to run the tests against a specific version. The combinations of sshkit and ruby we support are specified in [.circleci/config.yml](.circleci/config.yml).
A Guardfile is also present, so if you'd like to use Guard to do a TDD workflow, then:
1. Run `bundle install --with extras` to get the optional guard dependencies
2. Run `guard` to monitor the filesystem and automatically run tests as you work
[Issues]: https://github.com/mattbrictson/airbrussh/issues
[RuboCop]: https://github.com/bbatsov/rubocop
[style]: https://github.com/bbatsov/ruby-style-guide
source "https://rubygems.org"
# Specify your gem's dependencies in airbrussh.gemspec
gemspec
if RUBY_VERSION == "1.9.3"
# These gems need specific version for Ruby 1.9
gem "json", "~> 1.8"
gem "minitest", "~> 5.11.3"
gem "net-ssh", "~> 2.8"
gem "rake", "< 12.3"
gem "term-ansicolor", "~> 1.3.2"
gem "tins", "~> 1.6.0"
end
if RUBY_VERSION >= "2.5"
# These gems need at least Ruby 2.5
gem "coveralls_reborn", "~> 0.24.0"
end
if RUBY_VERSION >= "2.1"
# These gems need at least Ruby 2.1
gem "rubocop", "0.50.0"
# Optional development dependencies; requires bundler >= 1.10.
# Note that these gems assume a Ruby 2.2 environment. Install them using:
#
# bundle install --with extras
#
group :extras, :optional => true do
gem "guard", ">= 2.2.2"
gem "guard-minitest"
gem "rb-fsevent"
gem "terminal-notifier-guard"
end
end
if (sshkit_version = ENV["sshkit"])
requirement = begin
Gem::Dependency.new("sshkit", sshkit_version).requirement
rescue ArgumentError
user, branch =
if sshkit_version.include?("#")
sshkit_version.split("#")
else
["capistrano", sshkit_version]
end
{ :git => "https://github.com/#{user}/sshkit.git", :branch => branch }
end
gem "sshkit", requirement
end
guard :minitest do
# with Minitest::Unit
watch(%r{^test/(.*)\/?(.*)_test\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
watch(%r{^test/minitest_helper\.rb$}) { "test" }
end
The MIT License (MIT)
Copyright (c) 2020 Matt Brictson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
# Airbrussh
[![Gem Version](https://badge.fury.io/rb/airbrussh.svg)](http://badge.fury.io/rb/airbrussh)
[![Build Status](https://circleci.com/gh/mattbrictson/airbrussh/tree/main.svg?style=shield)](https://app.circleci.com/pipelines/github/mattbrictson/airbrussh?branch=main)
[![Build status](https://ci.appveyor.com/api/projects/status/h052rlq54sne3md6/branch/main?svg=true)](https://ci.appveyor.com/project/mattbrictson/airbrussh/branch/main)
[![Code Climate](https://codeclimate.com/github/mattbrictson/airbrussh/badges/gpa.svg)](https://codeclimate.com/github/mattbrictson/airbrussh)
[![Coverage Status](https://coveralls.io/repos/mattbrictson/airbrussh/badge.svg?branch=main)](https://coveralls.io/r/mattbrictson/airbrussh?branch=main)
Airbrussh is a concise log formatter for Capistrano and SSHKit. It displays well-formatted, useful log output that is easy to read. Airbrussh also saves Capistrano's verbose output to a separate log file just in case you need additional details for troubleshooting.
**As of April 2016, Airbrussh is bundled with Capistrano 3.5, and is Capistrano's default formatter! There is nothing additional to install or enable.** Continue reading to learn more about Airbrussh's features and configuration options.
If you aren't yet using Capistrano 3.5 (or wish to use Airbrussh with SSHKit directly), refer to the [advanced/legacy usage](#advancedlegacy-usage) section for installation instructions.
![Sample output](https://raw.github.com/mattbrictson/airbrussh/HEAD/demo.gif)
For more details on how exactly Airbrussh affects Capistrano's output and the reasoning behind it, check out the blog post: [Introducing Airbrussh](https://mattbrictson.com/airbrussh).
-----
* [Usage](#usage)
* [Configuration](#configuration)
* [FAQ](#faq)
* [Advanced/legacy usage](#advancedlegacy-usage)
## Usage
Airbrussh is enabled by default in Capistrano 3.5 and newer. To manually enable Airbrussh (for example, when upgrading an existing project), set the Capistrano format like this:
```ruby
# In deploy.rb
set :format, :airbrussh
```
### What's displayed
When you run a Capistrano command, Airbrussh provides the following information in its output:
![Sample output](https://raw.github.com/mattbrictson/airbrussh/HEAD/formatting.png)
* Name of Capistrano task being executed
* When each task started (minutes:seconds elapsed since the deploy began)
* The SSH command-line strings that are executed; for Capistrano tasks that involve running multiple commands, the numeric prefix indicates the command in the sequence, starting from `01`
* Stdout and stderr output from each command
* The duration of each command execution, per server
### What's *not* displayed
For brevity, Airbrussh does not show *everything* that Capistrano is doing. For example, it will omit Capistrano's `test` commands, which can be noisy and confusing. Airbrussh also hides things like environment variables, as well as `cd` and `env` invocations. To see a full audit of Capistrano's execution, including *exactly* what commands were run on each server, look at `log/capistrano.log`.
## Configuration
You can customize many aspects of Airbrussh's output. In Capistrano 3.5 and newer, this is done via the `:format_options` variable, like this:
```ruby
# Pass options to Airbrussh
set :format_options, color: false, truncate: 80
```
Here are the options you can use, and their effects (note that the defaults may be different depending on where Airbrussh is used; these are the defaults used by Capistrano 3.5):
|Option|Default|Usage|
|---|---|---|
|`banner`|`nil`|Provide a string (e.g. "Capistrano started!") that will be printed when Capistrano starts up.|
|`color`|`:auto`|Use `true` or `false` to enable or disable ansi color. If set to `:auto`, Airbrussh automatically uses color based on whether the output is a TTY, or if the SSHKIT_COLOR environment variable is set.|
|`command_output`|`true`|Set to `:stdout`, `:stderr`, or `true` to display the SSH output received via stdout, stderr, or both, respectively. Set to `false` to not show any SSH output, for a minimal look.|
|`context`|`Airbrussh::Rake::Context`|Defines the execution context. Targeted towards uses of Airbrussh outside of Rake/Capistrano. Alternate implementations should provide the definition for `current_task_name`, `register_new_command`, and `position`.|
|`log_file`|`log/capistrano.log`|Capistrano's verbose output is saved to this file to facilitate debugging. Set to `nil` to disable completely.|
|`truncate`|`:auto`|Set to a number (e.g. 80) to truncate the width of the output to that many characters, or `false` to disable truncation. If `:auto`, output is automatically truncated to the width of the terminal window, if it can be determined.|
|`task_prefix`|`nil`|A string to prefix to task output. Handy for output collapsing like [buildkite](https://buildkite.com/docs/builds/managing-log-output)'s `---` prefix|
## FAQ
**Airbrussh is not displaying the output of my commands! For example, I run `tail` in one of my capistrano tasks and airbrussh doesn't show anything. How do I fix this?**
Make sure Airbrussh is configured to show SSH output.
```ruby
set :format_options, command_output: true
```
**I haven't upgraded to Capistrano 3.5 yet. Can I still use Airbrussh?**
Yes! Capistrano 3.4.x is also supported. Refer to the [advanced/legacy usage](#advancedlegacy-usage) section for installation instructions.
**Does Airbrussh work with Capistrano 2?**
No, Capistrano 3 is required. We recommend Capistrano 3.4.0 or higher. Capistrano 3.5.0 and higher have Airbrussh enabled by default, with no installation needed.
**Does Airbrussh work with JRuby?**
JRuby is not officially supported or tested, but may work. You must disable automatic truncation to work around a known bug in the JRuby 9.0 standard library. See [#62](https://github.com/mattbrictson/airbrussh/issues/62) for more details.
```ruby
set :format_options, truncate: false
```
**I have a question that’s not answered here or elsewhere in the README.**
Please [open a GitHub issue](https://github.com/mattbrictson/airbrussh/issues/new) and we’ll be happy to help!
## Advanced/legacy usage
Although Airbrussh is built into Capistrano 3.5.0 and higher, it is also available as a plug-in for older versions. Airbrussh has been tested with MRI 1.9+, Capistrano 3.4.0+, and SSHKit 1.6.1+.
### Capistrano 3.4.x
Add this line to your application's Gemfile:
```ruby
gem "airbrussh", require: false
```
And then execute:
$ bundle
Finally, add this line to your application's Capfile:
```ruby
require "airbrussh/capistrano"
```
**Important:** explicitly setting Capistrano's `:format` option in your deploy.rb will override airbrussh. Remove this line if you have it:
```ruby
# Remove this
set :format, :pretty
```
Capistrano 3.4.x doesn't have the `:format_options` configuration system, so you will need to configure Airbrussh using this technique:
```ruby
Airbrussh.configure do |config|
config.color = false
config.command_output = true
# etc.
end
```
Refer to the [configuration](#configuration) section above for the list of supported options.
### SSHKit
If you are using SSHKit directly (i.e. without Capistrano), you can use Airbrussh like this:
```ruby
require "airbrussh"
SSHKit.config.output = Airbrussh::Formatter.new($stdout)
# You can also pass configuration options like this
SSHKit.config.output = Airbrussh::Formatter.new($stdout, color: false)
```
## History
Airbrussh started life as custom logging code within the [capistrano-mb][] collection of opinionated Capistrano recipes. In February 2015, the logging code was refactored into a standalone gem with its own configuration and documentation, and renamed `airbrussh`. In February 2016, Airbrussh was added as the default formatter in Capistrano 3.5.0.
## Roadmap
Airbrussh now has a stable feature set, excellent test coverage, is being used for production deployments, and has reached 1.0.0! If you have ideas for improvements to Airbrussh, please open a [GitHub issue](https://github.com/mattbrictson/airbrussh/issues/new).
## Contributing
Contributions are welcome! Read [CONTRIBUTING.md](CONTRIBUTING.md) to get started.
[capistrano-mb]: https://github.com/mattbrictson/capistrano-mb
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
begin
require "rubocop/rake_task"
RuboCop::RakeTask.new
task :default => [:test, :rubocop]
rescue LoadError
task :default => :test
end
Rake::Task["release"].enhance do
puts "Don't forget to publish the release on GitHub!"
system "open https://github.com/mattbrictson/airbrussh/releases"
end
# Capistrano 3.5 upgrade guide for existing Airbrussh users
If you have been using Airbrussh with Capistrano, and are upgrading to Capistrano 3.5, then this guide is for you.
## What changed?
* Airbrussh is built into Capistrano starting with Capistrano 3.5.0, and is enabled by default.
* Capistrano 3.5 initializes Airbrussh with a default configuration that is different than Airbrussh+Capistrano 3.4.0.
* In Capistrano 3.5, `set :format_options, ...` is now the preferred mechanism for configuring Airbrussh.
## How to upgrade
1. Remove `gem "airbrussh"` from your Gemfile. Airbrussh is now included automatically by Capistrano.
2. Likewise, remove `require "capistrano/airbrussh"` from your Capfile. Capistrano now does this internally.
3. Remove `Airbrussh.configure do ... end` from your deploy.rb and replace with `set :format_options, ...` (see below).
## New configuration system
In Capistrano 3.5, Airbrussh is configured by assigning a configuration Hash to the `:format_options` variable. Here is a comparison of the old and new syntaxes:
```ruby
# Old syntax
Airbrussh.configure do |config|
config.color = false
end
# New syntax
set :format_options, color: false
```
Although the syntax is different, the names of the configuration keys have not changed.
## New defaults
Capistrano 3.5.0 changes Airbrussh defaults as follows:
* `banner: false`
* `command_output: true`
Therefore, after upgrading to Capistrano 3.5.0, you may notice Airbrussh's output has changed and become more verbose. To restore the defaults to what you were used to in older versions, do this:
```ruby
set :format_options, banner: :auto, command_output: false
```
## Trouble?
If you have any Airbrussh-related trouble with the upgrade, please [open an issue](https://github.com/mattbrictson/airbrussh/issues).
# coding: utf-8
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "airbrussh/version"
Gem::Specification.new do |spec|
spec.name = "airbrussh"
spec.version = Airbrussh::VERSION
spec.license = "MIT"
spec.authors = ["Matt Brictson"]
spec.email = ["airbrussh@mattbrictson.com"]
spec.summary = "Airbrussh pretties up your SSHKit and Capistrano output"
spec.description = "A replacement log formatter for SSHKit that makes "\
"Capistrano output much easier on the eyes. Just add "\
"Airbrussh to your Capfile and enjoy concise, useful "\
"log output that is easy to read."
spec.homepage = "https://github.com/mattbrictson/airbrussh"
spec.metadata = {
"bug_tracker_uri" => "https://github.com/mattbrictson/airbrussh/issues",
"changelog_uri" => "https://github.com/mattbrictson/airbrussh/releases",
"source_code_uri" => "https://github.com/mattbrictson/airbrussh",
"homepage_uri" => "https://github.com/mattbrictson/airbrussh"
}
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/|\.(gif|png)$}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_dependency "sshkit", [">= 1.6.1", "!= 1.7.0"]
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake", "~> 12.0"
spec.add_development_dependency "minitest", "~> 5.10"
spec.add_development_dependency "minitest-reporters", "~> 1.1"
spec.add_development_dependency "mocha", "~> 1.2"
end
version: "{build}"
skip_tags: true
skip_branch_with_pr: true
install:
- set PATH=C:\Ruby26-x64\bin;%PATH%
- bundle install --retry=3
test_script:
- bundle exec rake
build: off
#!/usr/bin/env ruby
require "bundler/setup"
require "airbrussh"
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start
require "irb"
IRB.start
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
bundle install
# Do any other automated setup that you need to do here
require "airbrussh/configuration"
require "airbrussh/formatter"
require "airbrussh/version"
module Airbrussh
def self.configuration(options={})
return options if options.is_a?(::Airbrussh::Configuration)
@configuration ||= Configuration.new
@configuration.apply_options(options)
end
def self.configure
yield(configuration)
end
end
require "airbrussh/capistrano/tasks"
tasks = Airbrussh::Capistrano::Tasks.new(self)
# Hook into Capistrano's init process to set the formatter
namespace :load do
task :defaults do
tasks.load_defaults
end
end
# Capistrano failure hook
namespace :deploy do
task :failed do
tasks.deploy_failed
end
end
require "airbrussh"
require "airbrussh/colors"
require "airbrussh/console"
require "forwardable"
require "shellwords"
module Airbrussh
module Capistrano
# Encapsulates the rake behavior that integrates Airbrussh into Capistrano.
# This class allows us to easily test the behavior using a mock to stand in
# for the Capistrano DSL.
#
# See airbrussh/capistrano.rb to see how this class is used.
#
class Tasks
extend Forwardable
def_delegators :dsl, :set, :env
def_delegators :config, :log_file
include Airbrussh::Colors
def initialize(dsl, stderr=$stderr, config=Airbrussh.configuration)
@dsl = dsl
@stderr = stderr
@config = config
configure
warn_if_missing_dsl
end
# Behavior for the rake load:defaults task.
def load_defaults
require "sshkit/formatter/airbrussh"
set :format, :airbrussh
end
# Behavior for the rake deploy:failed task.
def deploy_failed
return unless airbrussh_is_being_used?
return if log_file.nil?
error_line
error_line(red("** DEPLOY FAILED"))
error_line(yellow("** Refer to #{log_file} for details. "\
"Here are the last 20 lines:"))
error_line
error_line(tail_log_file)
end
private
attr_reader :dsl, :stderr, :config
# Change airbrussh's default configuration to be more appropriate for
# capistrano.
def configure
config.log_file = "log/capistrano.log"
config.monkey_patch_rake = true
end
# Verify that capistrano and rake DSLs are present
def warn_if_missing_dsl
return if %w[set namespace task].all? { |m| dsl.respond_to?(m, true) }
error_line(
red("WARNING: airbrussh/capistrano must be loaded by Capistrano in "\
"order to work.\nRequire this gem within your application's "\
"Capfile, as described here:\n"\
"https://github.com/mattbrictson/airbrussh#installation")
)
end
def err_console
@err_console ||= begin
# Ensure we do not truncate the error output
err_config = config.dup
err_config.truncate = false
Airbrussh::Console.new(stderr, err_config)
end
end
def error_line(line="\n")
line.each_line(&err_console.method(:print_line))
end
# Returns a String containing the last 20 lines of the log file. Since
# this method uses a fixed-size buffer, fewer than 20 lines may be
# returned in cases where the lines are extremely long.
def tail_log_file
open(log_file) do |file|
file.seek(-[8192, file.size].min, IO::SEEK_END)
file.readlines.last(20).join
end
end
def airbrussh_is_being_used?
# Obtain the current formatter from the SSHKit backend
output = env.backend.config.output
output.is_a?(Airbrussh::Formatter)
end
end
end
end
module Airbrussh
# Very basic support for ANSI color, so that we don't have to rely on
# any external dependencies.
module Colors
ANSI_CODES = {
:red => 31,
:green => 32,
:yellow => 33,
:blue => 34,
:gray => 90
}.freeze
# Define red, green, blue, etc. methods that return a copy of the
# String that is wrapped in the corresponding ANSI color escape
# sequence.
ANSI_CODES.each do |name, code|
define_method(name) do |string|
"\e[0;#{code};49m#{string}\e[0m"
end
module_function(name)
end
end
end
# encoding: UTF-8
require "airbrussh/colors"
require "delegate"
# rubocop:disable Style/AsciiComments
module Airbrussh
# Decorates an SSHKit Command to add string output helpers and the
# command's position within currently executing rake task:
#
# * position - zero-based position of this command in the list of
# all commands that have been run in the current rake task; in
# some cases this could be nil
class CommandFormatter < SimpleDelegator
include Airbrussh::Colors
def initialize(command, position)
super(command)
@position = position
end
# Prefixes the line with the command number and removes the newline.
#
# format_output("hello\n") # => "01 hello"
#
def format_output(line)
"#{number} #{line.chomp}"
end
# Returns the abbreviated command (in yellow) with the number prefix.
#
# start_message # => "01 echo hello"
#
def start_message
"#{number} #{yellow(abbreviated)}"
end
# Returns a green (success) or red (failure) message depending on the
# exit status.
#
# exit_message # => "✔ 01 user@host 0.084s"
# exit_message # => "✘ 01 user@host 0.084s"
#
def exit_message
message = if failure?
red(failure_message)
else
green(success_message)
end
message << " #{runtime}"
end
private
def user_at_host
user_str = host.user || (host.ssh_options || {})[:user]
host_str = host.hostname
[user_str, host_str].compact.join("@")
end
def runtime
format("%5.3fs", super)
end
def abbreviated
to_s.sub(%r{^/usr/bin/env }, "")
end
def number
format("%02d", @position.to_i + 1)
end
def success_message
"✔ #{number} #{user_at_host}"
end
def failure_message
"✘ #{number} #{user_at_host}"
end
end
end
require "airbrussh/colors"
require "airbrussh/console_formatter"
require "airbrussh/log_file_formatter"
module Airbrussh
class Configuration
attr_accessor :log_file, :monkey_patch_rake, :color, :truncate, :banner,
:command_output, :task_prefix, :context
def initialize
self.log_file = nil
self.monkey_patch_rake = false
self.color = :auto
self.truncate = :auto
self.banner = :auto
self.command_output = false
self.task_prefix = nil
self.context = Airbrussh::Rake::Context
end
def apply_options(options)
return self if options.nil?
options.each do |key, value|
if respond_to?(writer = "#{key}=")
public_send(writer, value)
else
warn_unrecognized_key(key)
end
end
self
end
def banner_message
return nil unless banner
return banner unless banner == :auto
msg = "Using airbrussh format."
if log_file
msg << "\n"
msg << "Verbose output is being written to #{Colors.blue(log_file)}."
end
msg
end
# This returns an array of formatters appropriate for the configuration.
# Depending on whether a log file is configured, this could be just the
# Airbrussh:ConsoleFormatter, or that plus the LogFileFormatter.
def formatters(io)
fmts = [Airbrussh::ConsoleFormatter.new(io, self)]
fmts.unshift(Airbrussh::LogFileFormatter.new(log_file)) if log_file
fmts
end
def show_command_output?(sym)
command_output == true || Array(command_output).include?(sym)
end
private
def warn_unrecognized_key(key)
$stderr.puts("Ignoring unrecognized Airbrussh option: #{key}")
end
end
end
# encoding: UTF-8
require "io/console"
module Airbrussh
# Helper class that wraps an IO object and provides methods for truncating
# output, assuming the IO object represents a console window.
#
# This is useful for writing log messages that will typically show up on
# an ANSI color-capable console. When a console is not present (e.g. when
# running on a CI server) the output will gracefully degrade.
class Console
attr_reader :output, :config
def initialize(output, config=Airbrussh.configuration)
@output = output
@config = config
end
# Writes to the IO after first truncating the output to fit the console
# width. If the underlying IO is not a TTY, ANSI colors are removed from
# the output. A newline is always added. Color output can be forced by
# setting the SSHKIT_COLOR environment variable.
def print_line(obj="")
string = obj.to_s
string = truncate_to_console_width(string) if console_width
string = strip_ascii_color(string) unless color_enabled?
write(string + "\n")
output.flush
end
# Writes directly through to the IO with no truncation or color logic.
# No newline is added.
def write(string)
output.write(string || "")
end
alias << write
def truncate_to_console_width(string)
string = (string || "").rstrip
ellipsis = utf8_supported?(string) ? "…" : "..."
width = console_width
if strip_ascii_color(string).length > width
width -= ellipsis.length
string.chop! while strip_ascii_color(string).length > width
string << "#{ellipsis}\e[0m"
else
string
end
end
def strip_ascii_color(string)
string ||= ""
string = to_utf8(string) unless string.valid_encoding?
string.gsub(/\033\[[0-9;]*m/, "")
end
def console_width
width = case (truncate = config.truncate)
when :auto
IO.console.winsize.last if @output.tty?
when Integer
truncate
end
width if width.to_i > 0
end
private
def color_enabled?
case config.color
when true
true
when :auto
ENV["SSHKIT_COLOR"] || @output.tty?
else
false
end
end
def utf8_supported?(string)
string.encode("UTF-8").valid_encoding?
rescue Encoding::UndefinedConversionError
false
end
def to_utf8(string)
string.force_encoding("ASCII-8BIT")
.encode("UTF-8", :invalid => :replace, :undef => :replace)
end
end
end
require "airbrussh/colors"
require "airbrussh/command_formatter"
require "airbrussh/console"
require "airbrussh/rake/context"
require "sshkit"
module Airbrussh
class ConsoleFormatter < SSHKit::Formatter::Abstract
include Airbrussh::Colors
extend Forwardable
attr_reader :config, :context
def_delegators :context, :current_task_name, :register_new_command
def initialize(io, config=Airbrussh.configuration)
super(io)
@config = config
@context = config.context.new(config)
@console = Airbrussh::Console.new(original_output, config)
write_banner
end
def write_banner
print_line(config.banner_message) if config.banner_message
end
def log_command_start(command)
return if debug?(command)
first_execution = register_new_command(command)
command = decorate(command)
print_task_if_changed
print_indented_line(command.start_message) if first_execution
end
def log_command_data(command, stream_type, string)
return if debug?(command)
return unless config.show_command_output?(stream_type)
command = decorate(command)
string.each_line do |line|
print_indented_line(command.format_output(line))
end
end
def log_command_exit(command)
return if debug?(command)
command = decorate(command)
print_indented_line(command.exit_message, -2)
end
def write(obj)
case obj
when SSHKit::Command
log_command_start(obj)
log_and_clear_command_output(obj, :stderr)
log_and_clear_command_output(obj, :stdout)
log_command_exit(obj) if obj.finished?
when SSHKit::LogMessage
write_log_message(obj)
end
end
alias << write
private
attr_accessor :last_printed_task
def write_log_message(log_message)
return if debug?(log_message)
print_task_if_changed
print_indented_line(format_log_message(log_message))
end
def format_log_message(log_message)
case log_message.verbosity
when SSHKit::Logger::WARN
"#{yellow('WARN')} #{log_message}"
when SSHKit::Logger::ERROR
"#{red('ERROR')} #{log_message}"
when SSHKit::Logger::FATAL
"#{red('FATAL')} #{log_message}"
else
log_message.to_s
end
end
# For SSHKit versions up to and including 1.7.1, the stdout and stderr
# output was available as attributes on the Command. Print the data for
# the specified command and stream if enabled and clear the stream.
# (see Airbrussh::Configuration#command_output).
def log_and_clear_command_output(command, stream)
output = command.public_send(stream)
log_command_data(command, stream, output)
command.public_send("#{stream}=", "")
end
def print_task_if_changed
return if current_task_name.nil?
return if current_task_name == last_printed_task
self.last_printed_task = current_task_name
print_line("#{config.task_prefix}#{clock} #{blue(current_task_name)}")
end
def clock
@start_at ||= Time.now
duration = Time.now - @start_at
minutes = (duration / 60).to_i
seconds = (duration - minutes * 60).to_i
format("%02d:%02d", minutes, seconds)
end
def debug?(obj)
obj.verbosity <= SSHKit::Logger::DEBUG
end
def decorate(command)
Airbrussh::CommandFormatter.new(command, @context.position(command))
end
def print_line(string)
@console.print_line(string)
end
def print_indented_line(string, offset=0)
indent = " " * (6 + offset)
print_line([indent, string].join)
end
end
end
require "sshkit"
module Airbrussh
# This class quacks like an SSHKit::Formatter, but when any formatting
# methods are called, it simply forwards them to one more more concrete
# formatters. This allows us to split out the responsibilities of
# ConsoleFormatter and LogFileFormatter into two separate classes, with
# DelegatingFormatter forwarding the logging messages to both at once.
#
class DelegatingFormatter
FORWARD_METHODS = %w[
fatal error warn info debug log
log_command_start log_command_data log_command_exit
].freeze
DUP_AND_FORWARD_METHODS = %w[<< write].freeze
attr_reader :formatters
def initialize(formatters)
@formatters = formatters
end
FORWARD_METHODS.each do |method|
define_method(method) do |*args|
formatters.map { |f| f.public_send(method, *args) }.last
end
end
# For versions of SSHKit up to and including 1.7.1, the LogfileFormatter
# and ConsoleFormatter (and all of SSHKit's built in formatters) clear
# the stdout and stderr data in the command obj. Therefore, ensure only
# one of the formatters (the last one) gets the original command. This is
# also the formatter whose return value is passed to the caller.
#
DUP_AND_FORWARD_METHODS.each do |method|
define_method(method) do |command_or_log_message|
formatters[0...-1].each do |f|
f.public_send(method, command_or_log_message.dup)
end
formatters.last.public_send(method, command_or_log_message)
end
end
end
end
require "airbrussh"
require "airbrussh/delegating_formatter"
# This is the formatter class that conforms to the SSHKit Formatter API and
# provides the airbrussh functionality to SSHKit. Note however that this class
# doesn't do much by itself; instead, it delegates to the ConsoleFormatter
# and (optionally) the LogFileFormatter, which handle the bulk of the logic.
#
module Airbrussh
class Formatter < Airbrussh::DelegatingFormatter
def initialize(io, options_or_config_object={})
config = ::Airbrussh.configuration(options_or_config_object)
# Delegate to ConsoleFormatter and (optionally) LogFileFormatter,
# based on the configuration.
super(config.formatters(io))
end
end
end
require "delegate"
require "fileutils"
require "logger"
require "sshkit"
module Airbrussh
# A Pretty formatter that sends its output to a specified log file path.
# LogFileFormatter takes care of creating the file (and its parent
# directory) if it does not already exist, opens it for appending, and writes
# a delimiter message. The file is automatically rotated if it reaches 20 MB.
#
class LogFileFormatter < SimpleDelegator
attr_reader :path
def initialize(path, formatter_class=SSHKit::Formatter::Pretty)
@path = path
ensure_directory_exists if path.is_a?(String)
super(formatter_class.new(log_file_io))
write_delimiter
end
private
def write_delimiter
delimiter = []
delimiter << "-" * 75
delimiter << "START #{Time.now} cap #{ARGV.join(' ')}"
delimiter << "-" * 75
delimiter.each do |line|
write(SSHKit::LogMessage.new(SSHKit::Logger::INFO, line))
end
end
def ensure_directory_exists
FileUtils.mkdir_p(File.dirname(path))
end
def log_file_io
@io ||= ::Logger.new(path, 1, 20_971_520)
end
end
end
module Airbrussh
module Rake
# Maintains information about what Rake task is currently being invoked,
# in order to be able to decorate SSHKit commands with additional
# context-sensitive information. Works via a monkey patch to Rake::Task,
# which can be disabled via by setting
# Airbrussh.configuration.monkey_patch_rake = false.
#
# Note that this class is not thread-safe. Normally this is not a problem,
# but some Capistrano users are known to use `invoke` to switch the Rake
# task in the middle of an SSHKit thread, which causes Context to get very
# confused. It such scenarios Context is not reliable and may return `nil`
# for the `position` of a command.
#
class Context
def initialize(config=Airbrussh.configuration)
@history = []
@enabled = config.monkey_patch_rake
self.class.install_monkey_patch if enabled?
end
# Returns the name of the currently-executing rake task, if it can be
# determined. If monkey patching is disabled, this will be nil.
def current_task_name
return nil unless enabled?
self.class.current_task_name
end
# Update the context when a new command starts by:
# * Clearing the command history if the rake task has changed
# * Recording the command in the history
#
# Returns whether or not this command was the first execution
# of this command in the current rake task
def register_new_command(command)
reset_history_if_task_changed
first_execution = !history.include?(command.to_s)
history << command.to_s
history.uniq!
first_execution
end
# The zero-based position of the specified command in the current rake
# task. May be `nil` in certain multi-threaded scenarios, so be careful!
def position(command)
history.index(command.to_s)
end
class << self
attr_accessor :current_task_name
def install_monkey_patch
require "rake"
return if ::Rake::Task.instance_methods.include?(:_airbrussh_execute)
::Rake::Task.class_exec do
alias_method :_airbrussh_execute, :execute
def execute(args=nil)
::Airbrussh::Rake::Context.current_task_name = name.to_s
_airbrussh_execute(args)
end
end
end
end
private
attr_reader :history
attr_accessor :last_task_name
def reset_history_if_task_changed
history.clear if last_task_name != current_task_name
self.last_task_name = current_task_name
end
def enabled?
@enabled
end
end
end
end
# frozen_string_literal: true
module Airbrussh
VERSION = "1.4.1".freeze
end
require "airbrussh/formatter"
# Capistrano's formatter configuration requires that the formatter class
# be in the SSHKit::Formatter namespace. So we declare
# SSHKit::Formatter::Airbrussh that simply functions as an alias for
# Airbrussh::Formatter.
module SSHKit
module Formatter
class Airbrussh < Airbrussh::Formatter
end
end
end
This diff could not be displayed because it is too large.
The MIT License
Portions copyright (c) 2010-2019 André Arko
Portions copyright (c) 2009 Engine Yard
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
[![Version ](https://img.shields.io/gem/v/bundler.svg?style=flat)](https://rubygems.org/gems/bundler)
[![Slack ](https://bundler-slackin.herokuapp.com/badge.svg)](https://bundler-slackin.herokuapp.com)
# Bundler: a gem to bundle gems
Bundler makes sure Ruby applications run the same code on every machine.
It does this by managing the gems that the application depends on. Given a list of gems, it can automatically download and install those gems, as well as any other gems needed by the gems that are listed. Before installing gems, it checks the versions of every gem to make sure that they are compatible, and can all be loaded at the same time. After the gems have been installed, Bundler can help you update some or all of them when new versions become available. Finally, it records the exact versions that have been installed, so that others can install the exact same gems.
### Installation and usage
To install (or update to the latest version):
```
gem install bundler
```
To install a prerelease version (if one is available), run `gem install bundler --pre`. To uninstall Bundler, run `gem uninstall bundler`.
Bundler is most commonly used to manage your application's dependencies. For example, these commands will allow you to use Bundler to manage the `rspec` gem for your application:
```
bundle init
bundle add rspec
bundle install
bundle exec rspec
```
See [bundler.io](https://bundler.io) for the full documentation.
### Troubleshooting
For help with common problems, see [TROUBLESHOOTING](doc/TROUBLESHOOTING.md).
Still stuck? Try [filing an issue](https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md).
### Other questions
To see what has changed in recent versions of Bundler, see the [CHANGELOG](CHANGELOG.md).
To get in touch with the Bundler core team and other Bundler users, please see [getting help](doc/contributing/GETTING_HELP.md).
### Contributing
If you'd like to contribute to Bundler, that's awesome, and we <3 you. We've put together [the Bundler contributor guide](https://github.com/rubygems/rubygems/blob/master/bundler/doc/contributing/README.md) with all of the information you need to get started.
If you'd like to request a substantial change to Bundler or its documentation, refer to the [Bundler RFC process](https://github.com/bundler/rfcs) for more information.
While some Bundler contributors are compensated by Ruby Together, the project maintainers make decisions independent of Ruby Together. As a project, we welcome contributions regardless of the author's affiliation with Ruby Together.
### Supporting
<a href="https://rubytogether.org/"><img src="https://rubytogether.org/images/rubies.svg" width="150"></a><br>
<a href="https://rubytogether.org/">Ruby Together</a> pays some Bundler maintainers for their ongoing work. As a grassroots initiative committed to supporting the critical Ruby infrastructure you rely on, Ruby Together is funded entirely by the Ruby community. Contribute today <a href="https://rubytogether.org/developers">as an individual</a> or (better yet) <a href="https://rubytogether.org/companies">as a company</a> to ensure that Bundler, RubyGems, and other shared tooling is around for years to come.
### Code of Conduct
Everyone interacting in the Bundler project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [Bundler code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
### License
Bundler is available under an [MIT License](https://github.com/rubygems/rubygems/blob/master/bundler/LICENSE.md).
# frozen_string_literal: true
begin
require_relative "lib/bundler/version"
rescue LoadError
# for Ruby core repository
require_relative "version"
end
Gem::Specification.new do |s|
s.name = "bundler"
s.version = Bundler::VERSION
s.license = "MIT"
s.authors = [
"André Arko", "Samuel Giddins", "Colby Swandale", "Hiroshi Shibata",
"David Rodríguez", "Grey Baker", "Stephanie Morillo", "Chris Morris", "James Wen", "Tim Moore",
"André Medeiros", "Jessica Lynn Suttles", "Terence Lee", "Carl Lerche",
"Yehuda Katz"
]
s.email = ["team@bundler.io"]
s.homepage = "https://bundler.io"
s.summary = "The best way to manage your application's dependencies"
s.description = "Bundler manages an application's dependencies through its entire life, across many machines, systematically and repeatably"
if s.respond_to?(:metadata=)
s.metadata = {
"bug_tracker_uri" => "https://github.com/rubygems/rubygems/issues?q=is%3Aopen+is%3Aissue+label%3ABundler",
"changelog_uri" => "https://github.com/rubygems/rubygems/blob/master/bundler/CHANGELOG.md",
"homepage_uri" => "https://bundler.io/",
"source_code_uri" => "https://github.com/rubygems/rubygems/",
}
end
s.required_ruby_version = ">= 2.3.0"
s.required_rubygems_version = ">= 2.5.2"
s.files = Dir.glob("lib/bundler{.rb,/**/*}", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
# include the gemspec itself because warbler breaks w/o it
s.files += %w[bundler.gemspec]
s.files += %w[CHANGELOG.md LICENSE.md README.md]
s.bindir = "exe"
s.executables = %w[bundle bundler]
s.require_paths = ["lib"]
end
#!/usr/bin/env ruby
# frozen_string_literal: true
# Exit cleanly from an early interrupt
Signal.trap("INT") do
Bundler.ui.debug("\n#{caller.join("\n")}") if defined?(Bundler)
exit 1
end
base_path = File.expand_path("../lib", __dir__)
if File.exist?(base_path)
require_relative "../lib/bundler"
else
require "bundler"
end
# Workaround for non-activated bundler spec due to missing https://github.com/rubygems/rubygems/commit/4e306d7bcdee924b8d80ca9db6125aa59ee4e5a3
gem "bundler", Bundler::VERSION if Gem.rubygems_version < Gem::Version.new("2.6.2")
if Gem.rubygems_version < Gem::Version.new("3.2.3") && Gem.ruby_version < Gem::Version.new("2.6.a") && !ENV["BUNDLER_NO_OLD_RUBYGEMS_WARNING"]
Bundler.ui.warn \
"Your RubyGems version (#{Gem::VERSION}) has a bug that prevents " \
"`required_ruby_version` from working for Bundler. Any scripts that use " \
"`gem install bundler` will break as soon as Bundler drops support for " \
"your Ruby version. Please upgrade RubyGems to avoid future breakage " \
"and silence this warning by running `gem update --system 3.2.3`"
end
if File.exist?(base_path)
require_relative "../lib/bundler/friendly_errors"
else
require "bundler/friendly_errors"
end
Bundler.with_friendly_errors do
if File.exist?(base_path)
require_relative "../lib/bundler/cli"
else
require "bundler/cli"
end
# Allow any command to use --help flag to show help for that command
help_flags = %w[--help -h]
help_flag_used = ARGV.any? {|a| help_flags.include? a }
args = help_flag_used ? Bundler::CLI.reformatted_help_args(ARGV) : ARGV
Bundler::CLI.start(args, :debug => true)
end
#!/usr/bin/env ruby
# frozen_string_literal: true
load File.expand_path("bundle", __dir__)
# frozen_string_literal: true
module Bundler
# Represents metadata from when the Bundler gem was built.
module BuildMetadata
# begin ivars
@built_at = "2022-08-24".freeze
@git_commit_sha = "d54be5fdd8".freeze
@release = true
# end ivars
# A hash representation of the build metadata.
def self.to_h
{
"Built At" => built_at,
"Git SHA" => git_commit_sha,
"Released Version" => release?,
}
end
# A string representing the date the bundler gem was built.
def self.built_at
@built_at ||= Time.now.utc.strftime("%Y-%m-%d").freeze
end
# The SHA for the git commit the bundler gem was built from.
def self.git_commit_sha
return @git_commit_sha if instance_variable_defined? :@git_commit_sha
# If Bundler has been installed without its .git directory and without a
# commit instance variable then we can't determine its commits SHA.
git_dir = File.expand_path("../../../.git", __dir__)
if File.directory?(git_dir)
return @git_commit_sha = Dir.chdir(git_dir) { `git rev-parse --short HEAD`.strip.freeze }
end
@git_commit_sha ||= "unknown"
end
# Whether this is an official release build of Bundler.
def self.release?
@release
end
end
end
# frozen_string_literal: true
require_relative "shared_helpers"
Bundler::SharedHelpers.major_deprecation 2,
"The Bundler task for Capistrano. Please use https://github.com/capistrano/bundler"
# Capistrano task for Bundler.
#
# Add "require 'bundler/capistrano'" in your Capistrano deploy.rb, and
# Bundler will be activated after each new deployment.
require_relative "deployment"
require "capistrano/version"
if defined?(Capistrano::Version) && Gem::Version.new(Capistrano::Version).release >= Gem::Version.new("3.0")
raise "For Capistrano 3.x integration, please use https://github.com/capistrano/bundler"
end
Capistrano::Configuration.instance(:must_exist).load do
before "deploy:finalize_update", "bundle:install"
Bundler::Deployment.define_task(self, :task, :except => { :no_release => true })
set :rake, lambda { "#{fetch(:bundle_cmd, "bundle")} exec rake" }
end
# frozen_string_literal: true
module Bundler
class CLI::Add
attr_reader :gems, :options, :version
def initialize(options, gems)
@gems = gems
@options = options
@options[:group] = options[:group].split(",").map(&:strip) unless options[:group].nil?
@version = options[:version].split(",").map(&:strip) unless options[:version].nil?
end
def run
validate_options!
inject_dependencies
perform_bundle_install unless options["skip-install"]
end
private
def perform_bundle_install
Installer.install(Bundler.root, Bundler.definition)
Bundler.load.cache if Bundler.app_cache.exist?
end
def inject_dependencies
dependencies = gems.map {|g| Bundler::Dependency.new(g, version, options) }
Injector.inject(dependencies,
:conservative_versioning => options[:version].nil?, # Perform conservative versioning only when version is not specified
:optimistic => options[:optimistic],
:strict => options[:strict])
end
def validate_options!
raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic]
# raise error when no gems are specified
raise InvalidOption, "Please specify gems to add." if gems.empty?
version.to_a.each do |v|
raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s
end
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Binstubs
attr_reader :options, :gems
def initialize(options, gems)
@options = options
@gems = gems
end
def run
Bundler.definition.validate_runtime!
path_option = options["path"]
path_option = nil if path_option && path_option.empty?
Bundler.settings.set_command_option :bin, path_option if options["path"]
Bundler.settings.set_command_option_if_given :shebang, options["shebang"]
installer = Installer.new(Bundler.root, Bundler.definition)
installer_opts = {
:force => options[:force],
:binstubs_cmd => true,
:all_platforms => options["all-platforms"],
}
if options[:all]
raise InvalidOption, "Cannot specify --all with specific gems" unless gems.empty?
@gems = Bundler.definition.specs.map(&:name)
installer_opts.delete(:binstubs_cmd)
elsif gems.empty?
Bundler.ui.error "`bundle binstubs` needs at least one gem to run."
exit 1
end
gems.each do |gem_name|
spec = Bundler.definition.specs.find {|s| s.name == gem_name }
unless spec
raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(
gem_name, Bundler.definition.specs
)
end
if options[:standalone]
next Bundler.ui.warn("Sorry, Bundler can only be run via RubyGems.") if gem_name == "bundler"
Bundler.settings.temporary(:path => (Bundler.settings[:path] || Bundler.root)) do
installer.generate_standalone_bundler_executable_stubs(spec, installer_opts)
end
else
installer.generate_bundler_executable_stubs(spec, installer_opts)
end
end
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Cache
attr_reader :options
def initialize(options)
@options = options
end
def run
Bundler.ui.level = "warn" if options[:quiet]
Bundler.settings.set_command_option_if_given :path, options[:path]
Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"]
setup_cache_all
install
# TODO: move cache contents here now that all bundles are locked
custom_path = Bundler.settings[:path] if options[:path]
Bundler.settings.temporary(:cache_all_platforms => options["all-platforms"]) do
Bundler.load.cache(custom_path)
end
end
private
def install
require_relative "install"
options = self.options.dup
options["local"] = false if Bundler.settings[:cache_all_platforms]
options["no-cache"] = true
Bundler::CLI::Install.new(options).run
end
def setup_cache_all
all = options.fetch(:all, Bundler.feature_flag.cache_all? || nil)
Bundler.settings.set_command_option_if_given :cache_all, all
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Check
attr_reader :options
def initialize(options)
@options = options
end
def run
Bundler.settings.set_command_option_if_given :path, options[:path]
definition = Bundler.definition
definition.validate_runtime!
begin
definition.resolve_only_locally!
not_installed = definition.missing_specs
rescue GemNotFound, VersionConflict
Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies."
Bundler.ui.warn "Install missing gems with `bundle install`."
exit 1
end
if not_installed.any?
Bundler.ui.error "The following gems are missing"
not_installed.each {|s| Bundler.ui.error " * #{s.name} (#{s.version})" }
Bundler.ui.warn "Install missing gems with `bundle install`"
exit 1
elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle?
Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} present"
exit 1
else
Bundler.load.lock(:preserve_unknown_sections => true) unless options[:"dry-run"]
Bundler.ui.info "The Gemfile's dependencies are satisfied"
end
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Clean
attr_reader :options
def initialize(options)
@options = options
end
def run
require_path_or_force unless options[:"dry-run"]
Bundler.load.clean(options[:"dry-run"])
end
protected
def require_path_or_force
return unless Bundler.use_system_gems? && !options[:force]
raise InvalidOption, "Cleaning all the gems on your system is dangerous! " \
"If you're sure you want to remove every system gem not in this " \
"bundle, run `bundle clean --force`."
end
end
end
# frozen_string_literal: true
module Bundler
module CLI::Common
def self.output_post_install_messages(messages)
return if Bundler.settings["ignore_messages"]
messages.to_a.each do |name, msg|
print_post_install_message(name, msg) unless Bundler.settings["ignore_messages.#{name}"]
end
end
def self.print_post_install_message(name, msg)
Bundler.ui.confirm "Post-install message from #{name}:"
Bundler.ui.info msg
end
def self.output_fund_metadata_summary
return if Bundler.settings["ignore_funding_requests"]
definition = Bundler.definition
current_dependencies = definition.requested_dependencies
current_specs = definition.specs
count = current_dependencies.count {|dep| current_specs[dep.name].first.metadata.key?("funding_uri") }
return if count.zero?
intro = count > 1 ? "#{count} installed gems you directly depend on are" : "#{count} installed gem you directly depend on is"
message = "#{intro} looking for funding.\n Run `bundle fund` for details"
Bundler.ui.info message
end
def self.output_without_groups_message(command)
return if Bundler.settings[:without].empty?
Bundler.ui.confirm without_groups_message(command)
end
def self.without_groups_message(command)
command_in_past_tense = command == :install ? "installed" : "updated"
groups = Bundler.settings[:without]
"Gems in the #{verbalize_groups(groups)} were not #{command_in_past_tense}."
end
def self.verbalize_groups(groups)
groups.map! {|g| "'#{g}'" }
group_list = [groups[0...-1].join(", "), groups[-1..-1]].
reject {|s| s.to_s.empty? }.join(" and ")
group_str = groups.size == 1 ? "group" : "groups"
"#{group_str} #{group_list}"
end
def self.select_spec(name, regex_match = nil)
specs = []
regexp = Regexp.new(name) if regex_match
Bundler.definition.specs.each do |spec|
return spec if spec.name == name
specs << spec if regexp && spec.name =~ regexp
end
case specs.count
when 0
dep_in_other_group = Bundler.definition.current_dependencies.find {|dep|dep.name == name }
if dep_in_other_group
raise GemNotFound, "Could not find gem '#{name}', because it's in the #{verbalize_groups(dep_in_other_group.groups)}, configured to be ignored."
else
raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
end
when 1
specs.first
else
ask_for_spec_from(specs)
end
rescue RegexpError
raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
end
def self.ask_for_spec_from(specs)
specs.each_with_index do |spec, index|
Bundler.ui.info "#{index.succ} : #{spec.name}", true
end
Bundler.ui.info "0 : - exit -", true
num = Bundler.ui.ask("> ").to_i
num > 0 ? specs[num - 1] : nil
end
def self.gem_not_found_message(missing_gem_name, alternatives)
require_relative "../similarity_detector"
message = "Could not find gem '#{missing_gem_name}'."
alternate_names = alternatives.map {|a| a.respond_to?(:name) ? a.name : a }
suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name)
message += "\nDid you mean #{suggestions}?" if suggestions
message
end
def self.ensure_all_gems_in_lockfile!(names, locked_gems = Bundler.locked_gems)
return unless locked_gems
locked_names = locked_gems.specs.map(&:name).uniq
names.-(locked_names).each do |g|
raise GemNotFound, gem_not_found_message(g, locked_names)
end
end
def self.configure_gem_version_promoter(definition, options)
patch_level = patch_level_options(options)
patch_level << :patch if patch_level.empty? && Bundler.settings[:prefer_patch]
raise InvalidOption, "Provide only one of the following options: #{patch_level.join(", ")}" unless patch_level.length <= 1
definition.gem_version_promoter.tap do |gvp|
gvp.level = patch_level.first || :major
gvp.strict = options[:strict] || options["filter-strict"]
end
end
def self.patch_level_options(options)
[:major, :minor, :patch].select {|v| options.keys.include?(v.to_s) }
end
def self.clean_after_install?
clean = Bundler.settings[:clean]
return clean unless clean.nil?
clean ||= Bundler.feature_flag.auto_clean_without_path? && Bundler.settings[:path].nil?
clean &&= !Bundler.use_system_gems?
clean
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Config < Thor
class_option :parseable, :type => :boolean, :banner => "Use minimal formatting for more parseable output"
def self.scope_options
method_option :global, :type => :boolean, :banner => "Only change the global config"
method_option :local, :type => :boolean, :banner => "Only change the local config"
end
private_class_method :scope_options
desc "base NAME [VALUE]", "The Bundler 1 config interface", :hide => true
scope_options
method_option :delete, :type => :boolean, :banner => "delete"
def base(name = nil, *value)
new_args =
if ARGV.size == 1
["config", "list"]
elsif ARGV.include?("--delete")
ARGV.map {|arg| arg == "--delete" ? "unset" : arg }
elsif ARGV.include?("--global") || ARGV.include?("--local") || ARGV.size == 3
["config", "set", *ARGV[1..-1]]
else
["config", "get", ARGV[1]]
end
SharedHelpers.major_deprecation 3,
"Using the `config` command without a subcommand [list, get, set, unset] is deprecated and will be removed in the future. Use `bundle #{new_args.join(" ")}` instead."
Base.new(options, name, value, self).run
end
desc "list", "List out all configured settings"
def list
Base.new(options, nil, nil, self).run
end
desc "get NAME", "Returns the value for the given key"
def get(name)
Base.new(options, name, nil, self).run
end
desc "set NAME VALUE", "Sets the given value for the given key"
scope_options
def set(name, value, *value_)
Base.new(options, name, value_.unshift(value), self).run
end
desc "unset NAME", "Unsets the value for the given key"
scope_options
def unset(name)
options[:delete] = true
Base.new(options, name, nil, self).run
end
default_task :base
class Base
attr_reader :name, :value, :options, :scope, :thor
def initialize(options, name, value, thor)
@options = options
@name = name
value = Array(value)
@value = value.empty? ? nil : value.join(" ")
@thor = thor
validate_scope!
end
def run
unless name
warn_unused_scope "Ignoring --#{scope}"
confirm_all
return
end
if options[:delete]
if !explicit_scope? || scope != "global"
Bundler.settings.set_local(name, nil)
end
if !explicit_scope? || scope != "local"
Bundler.settings.set_global(name, nil)
end
return
end
if value.nil?
warn_unused_scope "Ignoring --#{scope} since no value to set was given"
if options[:parseable]
if value = Bundler.settings[name]
Bundler.ui.info("#{name}=#{value}")
end
return
end
confirm(name)
return
end
Bundler.ui.info(message) if message
Bundler.settings.send("set_#{scope}", name, new_value)
end
def confirm_all
if @options[:parseable]
thor.with_padding do
Bundler.settings.all.each do |setting|
val = Bundler.settings[setting]
Bundler.ui.info "#{setting}=#{val}"
end
end
else
Bundler.ui.confirm "Settings are listed in order of priority. The top value will be used.\n"
Bundler.settings.all.each do |setting|
Bundler.ui.confirm setting
show_pretty_values_for(setting)
Bundler.ui.confirm ""
end
end
end
def confirm(name)
Bundler.ui.confirm "Settings for `#{name}` in order of priority. The top value will be used"
show_pretty_values_for(name)
end
def new_value
pathname = Pathname.new(value)
if name.start_with?("local.") && pathname.directory?
pathname.expand_path.to_s
else
value
end
end
def message
locations = Bundler.settings.locations(name)
if @options[:parseable]
"#{name}=#{new_value}" if new_value
elsif scope == "global"
if !locations[:local].nil?
"Your application has set #{name} to #{locations[:local].inspect}. " \
"This will override the global value you are currently setting"
elsif locations[:env]
"You have a bundler environment variable for #{name} set to " \
"#{locations[:env].inspect}. This will take precedence over the global value you are setting"
elsif !locations[:global].nil? && locations[:global] != value
"You are replacing the current global value of #{name}, which is currently " \
"#{locations[:global].inspect}"
end
elsif scope == "local" && !locations[:local].nil? && locations[:local] != value
"You are replacing the current local value of #{name}, which is currently " \
"#{locations[:local].inspect}"
end
end
def show_pretty_values_for(setting)
thor.with_padding do
Bundler.settings.pretty_values_for(setting).each do |line|
Bundler.ui.info line
end
end
end
def explicit_scope?
@explicit_scope
end
def warn_unused_scope(msg)
return unless explicit_scope?
return if options[:parseable]
Bundler.ui.warn(msg)
end
def validate_scope!
@explicit_scope = true
scopes = %w[global local].select {|s| options[s] }
case scopes.size
when 0
@scope = inside_app? ? "local" : "global"
@explicit_scope = false
when 1
@scope = scopes.first
else
raise InvalidOption,
"The options #{scopes.join " and "} were specified. Please only use one of the switches at a time."
end
end
private
def inside_app?
Bundler.root
true
rescue GemfileNotFound
false
end
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Console
attr_reader :options, :group
def initialize(options, group)
@options = options
@group = group
end
def run
Bundler::SharedHelpers.major_deprecation 2, "bundle console will be replaced " \
"by `bin/console` generated by `bundle gem <name>`"
group ? Bundler.require(:default, *group.split(" ").map!(&:to_sym)) : Bundler.require
ARGV.clear
console = get_console(Bundler.settings[:console] || "irb")
console.start
end
def get_console(name)
require name
get_constant(name)
rescue LoadError
Bundler.ui.error "Couldn't load console #{name}, falling back to irb"
require "irb"
get_constant("irb")
end
def get_constant(name)
const_name = {
"pry" => :Pry,
"ripl" => :Ripl,
"irb" => :IRB,
}[name]
Object.const_get(const_name)
rescue NameError
Bundler.ui.error "Could not find constant #{const_name}"
exit 1
end
end
end
# frozen_string_literal: true
require "rbconfig"
require "shellwords"
require "fiddle"
module Bundler
class CLI::Doctor
DARWIN_REGEX = /\s+(.+) \(compatibility /.freeze
LDD_REGEX = /\t\S+ => (\S+) \(\S+\)/.freeze
attr_reader :options
def initialize(options)
@options = options
end
def otool_available?
Bundler.which("otool")
end
def ldd_available?
Bundler.which("ldd")
end
def dylibs_darwin(path)
output = `/usr/bin/otool -L #{path.shellescape}`.chomp
dylibs = output.split("\n")[1..-1].map {|l| l.match(DARWIN_REGEX).captures[0] }.uniq
# ignore @rpath and friends
dylibs.reject {|dylib| dylib.start_with? "@" }
end
def dylibs_ldd(path)
output = `/usr/bin/ldd #{path.shellescape}`.chomp
output.split("\n").map do |l|
match = l.match(LDD_REGEX)
next if match.nil?
match.captures[0]
end.compact
end
def dylibs(path)
case RbConfig::CONFIG["host_os"]
when /darwin/
return [] unless otool_available?
dylibs_darwin(path)
when /(linux|solaris|bsd)/
return [] unless ldd_available?
dylibs_ldd(path)
else # Windows, etc.
Bundler.ui.warn("Dynamic library check not supported on this platform.")
[]
end
end
def bundles_for_gem(spec)
Dir.glob("#{spec.full_gem_path}/**/*.bundle")
end
def check!
require_relative "check"
Bundler::CLI::Check.new({}).run
end
def run
Bundler.ui.level = "warn" if options[:quiet]
Bundler.settings.validate!
check!
definition = Bundler.definition
broken_links = {}
definition.specs.each do |spec|
bundles_for_gem(spec).each do |bundle|
bad_paths = dylibs(bundle).select do |f|
begin
Fiddle.dlopen(f)
false
rescue Fiddle::DLError
true
end
end
if bad_paths.any?
broken_links[spec] ||= []
broken_links[spec].concat(bad_paths)
end
end
end
permissions_valid = check_home_permissions
if broken_links.any?
message = "The following gems are missing OS dependencies:"
broken_links.map do |spec, paths|
paths.uniq.map do |path|
"\n * #{spec.name}: #{path}"
end
end.flatten.sort.each {|m| message += m }
raise ProductionError, message
elsif !permissions_valid
Bundler.ui.info "No issues found with the installed bundle"
end
end
private
def check_home_permissions
require "find"
files_not_readable_or_writable = []
files_not_rw_and_owned_by_different_user = []
files_not_owned_by_current_user_but_still_rw = []
broken_symlinks = []
Find.find(Bundler.bundle_path.to_s).each do |f|
if !File.exist?(f)
broken_symlinks << f
elsif !File.writable?(f) || !File.readable?(f)
if File.stat(f).uid != Process.uid
files_not_rw_and_owned_by_different_user << f
else
files_not_readable_or_writable << f
end
elsif File.stat(f).uid != Process.uid
files_not_owned_by_current_user_but_still_rw << f
end
end
ok = true
if broken_symlinks.any?
Bundler.ui.warn "Broken links exist in the Bundler home. Please report them to the offending gem's upstream repo. These files are:\n - #{broken_symlinks.join("\n - ")}"
ok = false
end
if files_not_owned_by_current_user_but_still_rw.any?
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
"user, but are still readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}"
ok = false
end
if files_not_rw_and_owned_by_different_user.any?
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
"user, and are not readable/writable. These files are:\n - #{files_not_rw_and_owned_by_different_user.join("\n - ")}"
ok = false
end
if files_not_readable_or_writable.any?
Bundler.ui.warn "Files exist in the Bundler home that are not " \
"readable/writable by the current user. These files are:\n - #{files_not_readable_or_writable.join("\n - ")}"
ok = false
end
ok
end
end
end
# frozen_string_literal: true
require_relative "../current_ruby"
module Bundler
class CLI::Exec
attr_reader :options, :args, :cmd
TRAPPED_SIGNALS = %w[INT].freeze
def initialize(options, args)
@options = options
@cmd = args.shift
@args = args
@args << { :close_others => !options.keep_file_descriptors? } unless Bundler.current_ruby.jruby?
end
def run
validate_cmd!
SharedHelpers.set_bundle_environment
if bin_path = Bundler.which(cmd)
if !Bundler.settings[:disable_exec_load] && ruby_shebang?(bin_path)
return kernel_load(bin_path, *args)
end
kernel_exec(bin_path, *args)
else
# exec using the given command
kernel_exec(cmd, *args)
end
end
private
def validate_cmd!
return unless cmd.nil?
Bundler.ui.error "bundler: exec needs a command to run"
exit 128
end
def kernel_exec(*args)
Kernel.exec(*args)
rescue Errno::EACCES, Errno::ENOEXEC
Bundler.ui.error "bundler: not executable: #{cmd}"
exit 126
rescue Errno::ENOENT
Bundler.ui.error "bundler: command not found: #{cmd}"
Bundler.ui.warn "Install missing gem executables with `bundle install`"
exit 127
end
def kernel_load(file, *args)
args.pop if args.last.is_a?(Hash)
ARGV.replace(args)
$0 = file
Process.setproctitle(process_title(file, args)) if Process.respond_to?(:setproctitle)
require_relative "../setup"
TRAPPED_SIGNALS.each {|s| trap(s, "DEFAULT") }
Kernel.load(file)
rescue SystemExit, SignalException
raise
rescue Exception # rubocop:disable Lint/RescueException
Bundler.ui.error "bundler: failed to load command: #{cmd} (#{file})"
Bundler::FriendlyErrors.disable!
raise
end
def process_title(file, args)
"#{file} #{args.join(" ")}".strip
end
def ruby_shebang?(file)
possibilities = [
"#!/usr/bin/env ruby\n",
"#!/usr/bin/env jruby\n",
"#!/usr/bin/env truffleruby\n",
"#!#{Gem.ruby}\n",
]
if File.zero?(file)
Bundler.ui.warn "#{file} is empty"
return false
end
first_line = File.open(file, "rb") {|f| f.read(possibilities.map(&:size).max) }
possibilities.any? {|shebang| first_line.start_with?(shebang) }
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Fund
attr_reader :options
def initialize(options)
@options = options
end
def run
Bundler.definition.validate_runtime!
groups = Array(options[:group]).map(&:to_sym)
deps = if groups.any?
Bundler.definition.dependencies_for(groups)
else
Bundler.definition.current_dependencies
end
fund_info = deps.each_with_object([]) do |dep, arr|
spec = Bundler.definition.specs[dep.name].first
if spec.metadata.key?("funding_uri")
arr << "* #{spec.name} (#{spec.version})\n Funding: #{spec.metadata["funding_uri"]}"
end
end
if fund_info.empty?
Bundler.ui.info "None of the installed gems you directly depend on are looking for funding."
else
Bundler.ui.info fund_info.join("\n")
end
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Info
attr_reader :gem_name, :options
def initialize(options, gem_name)
@options = options
@gem_name = gem_name
end
def run
Bundler.ui.silence do
Bundler.definition.validate_runtime!
Bundler.load.lock
end
spec = spec_for_gem(gem_name)
if spec
return print_gem_path(spec) if @options[:path]
return print_gem_version(spec) if @options[:version]
print_gem_info(spec)
end
end
private
def spec_for_gem(gem_name)
spec = Bundler.definition.specs.find {|s| s.name == gem_name }
spec || default_gem_spec(gem_name) || Bundler::CLI::Common.select_spec(gem_name, :regex_match)
end
def default_gem_spec(gem_name)
return unless Gem::Specification.respond_to?(:find_all_by_name)
gem_spec = Gem::Specification.find_all_by_name(gem_name).last
return gem_spec if gem_spec && gem_spec.respond_to?(:default_gem?) && gem_spec.default_gem?
end
def spec_not_found(gem_name)
raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(gem_name, Bundler.definition.dependencies)
end
def print_gem_version(spec)
Bundler.ui.info spec.version.to_s
end
def print_gem_path(spec)
name = spec.name
if name == "bundler"
path = File.expand_path("../../..", __dir__)
else
path = spec.full_gem_path
if spec.deleted_gem?
return Bundler.ui.warn "The gem #{name} has been deleted. It was installed at: #{path}"
end
end
Bundler.ui.info path
end
def print_gem_info(spec)
metadata = spec.metadata
name = spec.name
gem_info = String.new
gem_info << " * #{name} (#{spec.version}#{spec.git_version})\n"
gem_info << "\tSummary: #{spec.summary}\n" if spec.summary
gem_info << "\tHomepage: #{spec.homepage}\n" if spec.homepage
gem_info << "\tDocumentation: #{metadata["documentation_uri"]}\n" if metadata.key?("documentation_uri")
gem_info << "\tSource Code: #{metadata["source_code_uri"]}\n" if metadata.key?("source_code_uri")
gem_info << "\tFunding: #{metadata["funding_uri"]}\n" if metadata.key?("funding_uri")
gem_info << "\tWiki: #{metadata["wiki_uri"]}\n" if metadata.key?("wiki_uri")
gem_info << "\tChangelog: #{metadata["changelog_uri"]}\n" if metadata.key?("changelog_uri")
gem_info << "\tBug Tracker: #{metadata["bug_tracker_uri"]}\n" if metadata.key?("bug_tracker_uri")
gem_info << "\tMailing List: #{metadata["mailing_list_uri"]}\n" if metadata.key?("mailing_list_uri")
gem_info << "\tPath: #{spec.full_gem_path}\n"
gem_info << "\tDefault Gem: yes\n" if spec.respond_to?(:default_gem?) && spec.default_gem?
gem_info << "\tReverse Dependencies: \n\t\t#{gem_dependencies.join("\n\t\t")}" if gem_dependencies.any?
if name != "bundler" && spec.deleted_gem?
return Bundler.ui.warn "The gem #{name} has been deleted. Gemspec information is still available though:\n#{gem_info}"
end
Bundler.ui.info gem_info
end
def gem_dependencies
@gem_dependencies ||= Bundler.definition.specs.map do |spec|
dependency = spec.dependencies.find {|dep| dep.name == gem_name }
next unless dependency
"#{spec.name} (#{spec.version}) depends on #{gem_name} (#{dependency.requirements_list.join(", ")})"
end.compact.sort
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Init
attr_reader :options
def initialize(options)
@options = options
end
def run
if File.exist?(gemfile)
Bundler.ui.error "#{gemfile} already exists at #{File.expand_path(gemfile)}"
exit 1
end
unless File.writable?(Dir.pwd)
Bundler.ui.error "Can not create #{gemfile} as the current directory is not writable."
exit 1
end
if options[:gemspec]
gemspec = File.expand_path(options[:gemspec])
unless File.exist?(gemspec)
Bundler.ui.error "Gem specification #{gemspec} doesn't exist"
exit 1
end
spec = Bundler.load_gemspec_uncached(gemspec)
File.open(gemfile, "wb") do |file|
file << "# Generated from #{gemspec}\n"
file << spec.to_gemfile
end
else
FileUtils.cp(File.expand_path("../templates/#{gemfile}", __dir__), gemfile)
end
puts "Writing new #{gemfile} to #{SharedHelpers.pwd}/#{gemfile}"
end
private
def gemfile
@gemfile ||= Bundler.preferred_gemfile_name
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Inject
attr_reader :options, :name, :version, :group, :source, :gems
def initialize(options, name, version)
@options = options
@name = name
@version = version || last_version_number
@group = options[:group].split(",") unless options[:group].nil?
@source = options[:source]
@gems = []
end
def run
# The required arguments allow Thor to give useful feedback when the arguments
# are incorrect. This adds those first two arguments onto the list as a whole.
gems.unshift(source).unshift(group).unshift(version).unshift(name)
# Build an array of Dependency objects out of the arguments
deps = []
# when `inject` support addition of more than one gem, then this loop will
# help. Currently this loop is running once.
gems.each_slice(4) do |gem_name, gem_version, gem_group, gem_source|
ops = Gem::Requirement::OPS.map {|key, _val| key }
has_op = ops.any? {|op| gem_version.start_with? op }
gem_version = "~> #{gem_version}" unless has_op
deps << Bundler::Dependency.new(gem_name, gem_version, "group" => gem_group, "source" => gem_source)
end
added = Injector.inject(deps, options)
if added.any?
Bundler.ui.confirm "Added to Gemfile:"
Bundler.ui.confirm(added.map do |d|
name = "'#{d.name}'"
requirement = ", '#{d.requirement}'"
group = ", :group => #{d.groups.inspect}" if d.groups != Array(:default)
source = ", :source => '#{d.source}'" unless d.source.nil?
%(gem #{name}#{requirement}#{group}#{source})
end.join("\n"))
else
Bundler.ui.confirm "All gems were already present in the Gemfile"
end
end
private
def last_version_number
definition = Bundler.definition(true)
definition.resolve_remotely!
specs = definition.index[name].sort_by(&:version)
unless options[:pre]
specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
end
spec = specs.last
spec.version.to_s
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Install
attr_reader :options
def initialize(options)
@options = options
end
def run
Bundler.ui.level = "warn" if options[:quiet]
warn_if_root
Bundler.self_manager.install_locked_bundler_and_restart_with_it_if_needed
Bundler::SharedHelpers.set_env "RB_USER_INSTALL", "1" if Bundler::FREEBSD
# Disable color in deployment mode
Bundler.ui.shell = Thor::Shell::Basic.new if options[:deployment]
check_for_options_conflicts
check_trust_policy
if options[:deployment] || options[:frozen] || Bundler.frozen_bundle?
unless Bundler.default_lockfile.exist?
flag = "--deployment flag" if options[:deployment]
flag ||= "--frozen flag" if options[:frozen]
flag ||= "deployment setting"
raise ProductionError, "The #{flag} requires a #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}. Please make " \
"sure you have checked your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} into version control " \
"before deploying."
end
options[:local] = true if Bundler.app_cache.exist?
Bundler.settings.set_command_option :deployment, true if options[:deployment]
Bundler.settings.set_command_option :frozen, true if options[:frozen]
end
# When install is called with --no-deployment, disable deployment mode
if options[:deployment] == false
Bundler.settings.set_command_option :frozen, nil
options[:system] = true
end
normalize_settings
Bundler::Fetcher.disable_endpoint = options["full-index"]
if options["binstubs"]
Bundler::SharedHelpers.major_deprecation 2,
"The --binstubs option will be removed in favor of `bundle binstubs --all`"
end
Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?
definition = Bundler.definition
definition.validate_runtime!
installer = Installer.install(Bundler.root, definition, options)
Bundler.settings.temporary(:cache_all_platforms => options[:local] ? false : Bundler.settings[:cache_all_platforms]) do
Bundler.load.cache(nil, options[:local]) if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle?
end
Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}."
Bundler::CLI::Common.output_without_groups_message(:install)
if Bundler.use_system_gems?
Bundler.ui.confirm "Use `bundle info [gemname]` to see where a bundled gem is installed."
else
relative_path = Bundler.configured_bundle_path.base_path_relative_to_pwd
Bundler.ui.confirm "Bundled gems are installed into `#{relative_path}`"
end
Bundler::CLI::Common.output_post_install_messages installer.post_install_messages
warn_ambiguous_gems
if CLI::Common.clean_after_install?
require_relative "clean"
Bundler::CLI::Clean.new(options).run
end
Bundler::CLI::Common.output_fund_metadata_summary
rescue Gem::InvalidSpecificationException
Bundler.ui.warn "You have one or more invalid gemspecs that need to be fixed."
raise
end
private
def warn_if_root
return if Bundler.settings[:silence_root_warning] || Gem.win_platform? || !Process.uid.zero?
Bundler.ui.warn "Don't run Bundler as root. Bundler can ask for sudo " \
"if it is needed, and installing your bundle as root will break this " \
"application for all non-root users on this machine.", :wrap => true
end
def dependencies_count_for(definition)
count = definition.dependencies.count
"#{count} Gemfile #{count == 1 ? "dependency" : "dependencies"}"
end
def gems_installed_for(definition)
count = definition.specs.count
"#{count} #{count == 1 ? "gem" : "gems"} now installed"
end
def check_for_group_conflicts_in_cli_options
conflicting_groups = Array(options[:without]) & Array(options[:with])
return if conflicting_groups.empty?
raise InvalidOption, "You can't list a group in both with and without." \
" The offending groups are: #{conflicting_groups.join(", ")}."
end
def check_for_options_conflicts
if (options[:path] || options[:deployment]) && options[:system]
error_message = String.new
error_message << "You have specified both --path as well as --system. Please choose only one option.\n" if options[:path]
error_message << "You have specified both --deployment as well as --system. Please choose only one option.\n" if options[:deployment]
raise InvalidOption.new(error_message)
end
end
def check_trust_policy
trust_policy = options["trust-policy"]
unless Bundler.rubygems.security_policies.keys.unshift(nil).include?(trust_policy)
raise InvalidOption, "RubyGems doesn't know about trust policy '#{trust_policy}'. " \
"The known policies are: #{Bundler.rubygems.security_policies.keys.join(", ")}."
end
Bundler.settings.set_command_option_if_given :"trust-policy", trust_policy
end
def normalize_groups
check_for_group_conflicts_in_cli_options
# need to nil them out first to get around validation for backwards compatibility
Bundler.settings.set_command_option :without, nil
Bundler.settings.set_command_option :with, nil
Bundler.settings.set_command_option :without, options[:without]
Bundler.settings.set_command_option :with, options[:with]
end
def normalize_settings
Bundler.settings.set_command_option :path, nil if options[:system]
Bundler.settings.set_command_option_if_given :path, options[:path]
if options["standalone"] && Bundler.settings[:path].nil? && !options["local"]
Bundler.settings.temporary(:path_relative_to_cwd => false) do
Bundler.settings.set_command_option :path, "bundle"
end
end
bin_option = options["binstubs"]
bin_option = nil if bin_option && bin_option.empty?
Bundler.settings.set_command_option :bin, bin_option if options["binstubs"]
Bundler.settings.set_command_option_if_given :shebang, options["shebang"]
Bundler.settings.set_command_option_if_given :jobs, options["jobs"]
Bundler.settings.set_command_option_if_given :no_prune, options["no-prune"]
Bundler.settings.set_command_option_if_given :no_install, options["no-install"]
Bundler.settings.set_command_option_if_given :clean, options["clean"]
normalize_groups if options[:without] || options[:with]
options[:force] = options[:redownload]
end
def warn_ambiguous_gems
# TODO: remove this when we drop Bundler 1.x support
Installer.ambiguous_gems.to_a.each do |name, installed_from_uri, *also_found_in_uris|
Bundler.ui.warn "Warning: the gem '#{name}' was found in multiple sources."
Bundler.ui.warn "Installed from: #{installed_from_uri}"
Bundler.ui.warn "Also found in:"
also_found_in_uris.each {|uri| Bundler.ui.warn " * #{uri}" }
Bundler.ui.warn "You should add a source requirement to restrict this gem to your preferred source."
Bundler.ui.warn "For example:"
Bundler.ui.warn " gem '#{name}', :source => '#{installed_from_uri}'"
Bundler.ui.warn "Then uninstall the gem '#{name}' (or delete all bundled gems) and then install again."
end
end
end
end
# frozen_string_literal: true
require "rbconfig"
module Bundler
class CLI::Issue
def run
Bundler.ui.info <<-EOS.gsub(/^ {8}/, "")
Did you find an issue with Bundler? Before filing a new issue,
be sure to check out these resources:
1. Check out our troubleshooting guide for quick fixes to common issues:
https://github.com/rubygems/rubygems/blob/master/bundler/doc/TROUBLESHOOTING.md
2. Instructions for common Bundler uses can be found on the documentation
site: https://bundler.io/
3. Information about each Bundler command can be found in the Bundler
man pages: https://bundler.io/man/bundle.1.html
Hopefully the troubleshooting steps above resolved your problem! If things
still aren't working the way you expect them to, please let us know so
that we can diagnose and help fix the problem you're having, by filling
in the new issue form located at
https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md,
and copy and pasting the information below.
EOS
Bundler.ui.info Bundler::Env.report
Bundler.ui.info "\n## Bundle Doctor"
doctor
end
def doctor
require_relative "doctor"
Bundler::CLI::Doctor.new({}).run
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::List
def initialize(options)
@options = options
@without_group = options["without-group"].map(&:to_sym)
@only_group = options["only-group"].map(&:to_sym)
end
def run
raise InvalidOption, "The `--only-group` and `--without-group` options cannot be used together" if @only_group.any? && @without_group.any?
raise InvalidOption, "The `--name-only` and `--paths` options cannot be used together" if @options["name-only"] && @options[:paths]
specs = if @only_group.any? || @without_group.any?
filtered_specs_by_groups
else
begin
Bundler.load.specs
rescue GemNotFound => e
Bundler.ui.error e.message
Bundler.ui.warn "Install missing gems with `bundle install`."
exit 1
end
end.reject {|s| s.name == "bundler" }.sort_by(&:name)
return Bundler.ui.info "No gems in the Gemfile" if specs.empty?
return specs.each {|s| Bundler.ui.info s.name } if @options["name-only"]
return specs.each {|s| Bundler.ui.info s.full_gem_path } if @options["paths"]
Bundler.ui.info "Gems included by the bundle:"
specs.each {|s| Bundler.ui.info " * #{s.name} (#{s.version}#{s.git_version})" }
Bundler.ui.info "Use `bundle info` to print more detailed information about a gem"
end
private
def verify_group_exists(groups)
(@without_group + @only_group).each do |group|
raise InvalidOption, "`#{group}` group could not be found." unless groups.include?(group)
end
end
def filtered_specs_by_groups
definition = Bundler.definition
groups = definition.groups
verify_group_exists(groups)
show_groups =
if @without_group.any?
groups.reject {|g| @without_group.include?(g) }
elsif @only_group.any?
groups.select {|g| @only_group.include?(g) }
else
groups
end.map(&:to_sym)
definition.specs_for(show_groups)
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Lock
attr_reader :options
def initialize(options)
@options = options
end
def run
unless Bundler.default_gemfile
Bundler.ui.error "Unable to find a Gemfile to lock"
exit 1
end
print = options[:print]
ui = Bundler.ui
Bundler.ui = UI::Silent.new if print
Bundler::Fetcher.disable_endpoint = options["full-index"]
update = options[:update]
conservative = options[:conservative]
if update.is_a?(Array) # unlocking specific gems
Bundler::CLI::Common.ensure_all_gems_in_lockfile!(update)
update = { :gems => update, :conservative => conservative }
elsif update
update = { :conservative => conservative } if conservative
end
definition = Bundler.definition(update)
Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options) if options[:update]
options["remove-platform"].each do |platform|
definition.remove_platform(platform)
end
options["add-platform"].each do |platform_string|
platform = Gem::Platform.new(platform_string)
if platform.to_s == "unknown"
Bundler.ui.warn "The platform `#{platform_string}` is unknown to RubyGems " \
"and adding it will likely lead to resolution errors"
end
definition.add_platform(platform)
end
if definition.platforms.empty?
raise InvalidOption, "Removing all platforms from the bundle is not allowed"
end
definition.resolve_remotely! unless options[:local]
if print
puts definition.to_lock
else
file = options[:lockfile]
file = file ? File.expand_path(file) : Bundler.default_lockfile
puts "Writing lockfile to #{file}"
definition.lock(file)
end
Bundler.ui = ui
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Open
attr_reader :options, :name
def initialize(options, name)
@options = options
@name = name
end
def run
editor = [ENV["BUNDLER_EDITOR"], ENV["VISUAL"], ENV["EDITOR"]].find {|e| !e.nil? && !e.empty? }
return Bundler.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR") unless editor
return unless spec = Bundler::CLI::Common.select_spec(name, :regex_match)
if spec.default_gem?
Bundler.ui.info "Unable to open #{name} because it's a default gem, so the directory it would normally be installed to does not exist."
else
path = spec.full_gem_path
Dir.chdir(path) do
require "shellwords"
command = Shellwords.split(editor) + [path]
Bundler.with_original_env do
system(*command)
end || Bundler.ui.info("Could not run '#{command.join(" ")}'")
end
end
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Outdated
attr_reader :options, :gems, :options_include_groups, :filter_options_patch, :sources, :strict
attr_accessor :outdated_gems
def initialize(options, gems)
@options = options
@gems = gems
@sources = Array(options[:source])
@filter_options_patch = options.keys & %w[filter-major filter-minor filter-patch]
@outdated_gems = []
@options_include_groups = [:group, :groups].any? do |v|
options.keys.include?(v.to_s)
end
# the patch level options imply strict is also true. It wouldn't make
# sense otherwise.
@strict = options["filter-strict"] || Bundler::CLI::Common.patch_level_options(options).any?
end
def run
check_for_deployment_mode!
gems.each do |gem_name|
Bundler::CLI::Common.select_spec(gem_name)
end
Bundler.definition.validate_runtime!
current_specs = Bundler.ui.silence { Bundler.definition.resolve }
current_dependencies = Bundler.ui.silence do
Bundler.load.dependencies.map {|dep| [dep.name, dep] }.to_h
end
definition = if gems.empty? && sources.empty?
# We're doing a full update
Bundler.definition(true)
else
Bundler.definition(:gems => gems, :sources => sources)
end
Bundler::CLI::Common.configure_gem_version_promoter(
Bundler.definition,
options.merge(:strict => @strict)
)
definition_resolution = proc do
options[:local] ? definition.resolve_with_cache! : definition.resolve_remotely!
end
if options[:parseable]
Bundler.ui.silence(&definition_resolution)
else
definition_resolution.call
end
Bundler.ui.info ""
# Loop through the current specs
gemfile_specs, dependency_specs = current_specs.partition do |spec|
current_dependencies.key? spec.name
end
specs = if options["only-explicit"]
gemfile_specs
else
gemfile_specs + dependency_specs
end
specs.sort_by(&:name).uniq(&:name).each do |current_spec|
next unless gems.empty? || gems.include?(current_spec.name)
active_spec = retrieve_active_spec(definition, current_spec)
next unless active_spec
next unless filter_options_patch.empty? || update_present_via_semver_portions(current_spec, active_spec, options)
gem_outdated = Gem::Version.new(active_spec.version) > Gem::Version.new(current_spec.version)
next unless gem_outdated || (current_spec.git_version != active_spec.git_version)
dependency = current_dependencies[current_spec.name]
groups = ""
if dependency && !options[:parseable]
groups = dependency.groups.join(", ")
end
outdated_gems << {
:active_spec => active_spec,
:current_spec => current_spec,
:dependency => dependency,
:groups => groups,
}
end
if outdated_gems.empty?
unless options[:parseable]
Bundler.ui.info(nothing_outdated_message)
end
else
if options_include_groups
relevant_outdated_gems = outdated_gems.group_by {|g| g[:groups] }.sort.flat_map do |groups, gems|
contains_group = groups.split(", ").include?(options[:group])
next unless options[:groups] || contains_group
gems
end.compact
if options[:parseable]
relevant_outdated_gems.each do |gems|
print_gems(gems)
end
else
print_gems_table(relevant_outdated_gems)
end
elsif options[:parseable]
print_gems(outdated_gems)
else
print_gems_table(outdated_gems)
end
exit 1
end
end
private
def loaded_from_for(spec)
return unless spec.respond_to?(:loaded_from)
spec.loaded_from
end
def groups_text(group_text, groups)
"#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\""
end
def nothing_outdated_message
if filter_options_patch.any?
display = filter_options_patch.map do |o|
o.sub("filter-", "")
end.join(" or ")
"No #{display} updates to display.\n"
else
"Bundle up to date!\n"
end
end
def retrieve_active_spec(definition, current_spec)
active_spec = definition.resolve.find_by_name_and_platform(current_spec.name, current_spec.platform)
return unless active_spec
return active_spec if strict
active_specs = active_spec.source.specs.search(current_spec.name).select {|spec| spec.match_platform(current_spec.platform) }.sort_by(&:version)
if !current_spec.version.prerelease? && !options[:pre] && active_specs.size > 1
active_specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
end
active_specs.last
end
def print_gems(gems_list)
gems_list.each do |gem|
print_gem(
gem[:current_spec],
gem[:active_spec],
gem[:dependency],
gem[:groups],
)
end
end
def print_gems_table(gems_list)
data = gems_list.map do |gem|
gem_column_for(
gem[:current_spec],
gem[:active_spec],
gem[:dependency],
gem[:groups],
)
end
print_indented([table_header] + data)
end
def print_gem(current_spec, active_spec, dependency, groups)
spec_version = "#{active_spec.version}#{active_spec.git_version}"
if Bundler.ui.debug?
loaded_from = loaded_from_for(active_spec)
spec_version += " (from #{loaded_from})" if loaded_from
end
current_version = "#{current_spec.version}#{current_spec.git_version}"
if dependency && dependency.specific?
dependency_version = %(, requested #{dependency.requirement})
end
spec_outdated_info = "#{active_spec.name} (newest #{spec_version}, " \
"installed #{current_version}#{dependency_version})"
output_message = if options[:parseable]
spec_outdated_info.to_s
elsif options_include_groups || groups.empty?
" * #{spec_outdated_info}"
else
" * #{spec_outdated_info} in #{groups_text("group", groups)}"
end
Bundler.ui.info output_message.rstrip
end
def gem_column_for(current_spec, active_spec, dependency, groups)
current_version = "#{current_spec.version}#{current_spec.git_version}"
spec_version = "#{active_spec.version}#{active_spec.git_version}"
dependency = dependency.requirement if dependency
ret_val = [active_spec.name, current_version, spec_version, dependency.to_s, groups.to_s]
ret_val << loaded_from_for(active_spec).to_s if Bundler.ui.debug?
ret_val
end
def check_for_deployment_mode!
return unless Bundler.frozen_bundle?
suggested_command = if Bundler.settings.locations("frozen").keys.&([:global, :local]).any?
"bundle config unset frozen"
elsif Bundler.settings.locations("deployment").keys.&([:global, :local]).any?
"bundle config unset deployment"
end
raise ProductionError, "You are trying to check outdated gems in " \
"deployment mode. Run `bundle outdated` elsewhere.\n" \
"\nIf this is a development machine, remove the " \
"#{Bundler.default_gemfile} freeze" \
"\nby running `#{suggested_command}`."
end
def update_present_via_semver_portions(current_spec, active_spec, options)
current_major = current_spec.version.segments.first
active_major = active_spec.version.segments.first
update_present = false
update_present = active_major > current_major if options["filter-major"]
if !update_present && (options["filter-minor"] || options["filter-patch"]) && current_major == active_major
current_minor = get_version_semver_portion_value(current_spec, 1)
active_minor = get_version_semver_portion_value(active_spec, 1)
update_present = active_minor > current_minor if options["filter-minor"]
if !update_present && options["filter-patch"] && current_minor == active_minor
current_patch = get_version_semver_portion_value(current_spec, 2)
active_patch = get_version_semver_portion_value(active_spec, 2)
update_present = active_patch > current_patch
end
end
update_present
end
def get_version_semver_portion_value(spec, version_portion_index)
version_section = spec.version.segments[version_portion_index, 1]
version_section.to_a[0].to_i
end
def print_indented(matrix)
header = matrix[0]
data = matrix[1..-1]
column_sizes = Array.new(header.size) do |index|
matrix.max_by {|row| row[index].length }[index].length
end
Bundler.ui.info justify(header, column_sizes)
data.sort_by! {|row| row[0] }
data.each do |row|
Bundler.ui.info justify(row, column_sizes)
end
end
def table_header
header = ["Gem", "Current", "Latest", "Requested", "Groups"]
header << "Path" if Bundler.ui.debug?
header
end
def justify(row, sizes)
row.each_with_index.map do |element, index|
element.ljust(sizes[index])
end.join(" ").strip + "\n"
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Platform
attr_reader :options
def initialize(options)
@options = options
end
def run
platforms, ruby_version = Bundler.ui.silence do
locked_ruby_version = Bundler.locked_gems && Bundler.locked_gems.ruby_version&.gsub(/p\d+\Z/, "")
gemfile_ruby_version = Bundler.definition.ruby_version && Bundler.definition.ruby_version.single_version_string
[Bundler.definition.platforms.map {|p| "* #{p}" },
locked_ruby_version || gemfile_ruby_version]
end
output = []
if options[:ruby]
if ruby_version
output << ruby_version
else
output << "No ruby version specified"
end
else
output << "Your platform is: #{Gem::Platform.local}"
output << "Your app has gems that work on these platforms:\n#{platforms.join("\n")}"
if ruby_version
output << "Your Gemfile specifies a Ruby version requirement:\n* #{ruby_version}"
begin
Bundler.definition.validate_runtime!
output << "Your current platform satisfies the Ruby version requirement."
rescue RubyVersionMismatch => e
output << e.message
end
else
output << "Your Gemfile does not specify a Ruby version requirement."
end
end
Bundler.ui.info output.join("\n\n")
end
end
end
# frozen_string_literal: true
require_relative "../vendored_thor"
module Bundler
class CLI::Plugin < Thor
desc "install PLUGINS", "Install the plugin from the source"
long_desc <<-D
Install plugins either from the rubygems source provided (with --source option) or from a git source provided with --git (for remote repos) or --local_git (for local repos). If no sources are provided, it uses Gem.sources
D
method_option "source", :type => :string, :default => nil, :banner =>
"URL of the RubyGems source to fetch the plugin from"
method_option "version", :type => :string, :default => nil, :banner =>
"The version of the plugin to fetch"
method_option "git", :type => :string, :default => nil, :banner =>
"URL of the git repo to fetch from"
method_option "local_git", :type => :string, :default => nil, :banner =>
"Path of the local git repo to fetch from"
method_option "branch", :type => :string, :default => nil, :banner =>
"The git branch to checkout"
method_option "ref", :type => :string, :default => nil, :banner =>
"The git revision to check out"
def install(*plugins)
Bundler::Plugin.install(plugins, options)
end
desc "uninstall PLUGINS", "Uninstall the plugins"
long_desc <<-D
Uninstall given list of plugins. To uninstall all the plugins, use -all option.
D
method_option "all", :type => :boolean, :default => nil, :banner =>
"Uninstall all the installed plugins. If no plugin is installed, then it does nothing."
def uninstall(*plugins)
Bundler::Plugin.uninstall(plugins, options)
end
desc "list", "List the installed plugins and available commands"
def list
Bundler::Plugin.list
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Pristine
def initialize(gems)
@gems = gems
end
def run
CLI::Common.ensure_all_gems_in_lockfile!(@gems)
definition = Bundler.definition
definition.validate_runtime!
installer = Bundler::Installer.new(Bundler.root, definition)
Bundler.load.specs.each do |spec|
next if spec.name == "bundler" # Source::Rubygems doesn't install bundler
next if !@gems.empty? && !@gems.include?(spec.name)
gem_name = "#{spec.name} (#{spec.version}#{spec.git_version})"
gem_name += " (#{spec.platform})" if !spec.platform.nil? && spec.platform != Gem::Platform::RUBY
case source = spec.source
when Source::Rubygems
cached_gem = spec.cache_file
unless File.exist?(cached_gem)
Bundler.ui.error("Failed to pristine #{gem_name}. Cached gem #{cached_gem} does not exist.")
next
end
FileUtils.rm_rf spec.full_gem_path
when Source::Git
if source.local?
Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is locally overridden.")
next
end
source.remote!
if extension_cache_path = source.extension_cache_path(spec)
FileUtils.rm_rf extension_cache_path
end
FileUtils.rm_rf spec.extension_dir
FileUtils.rm_rf spec.full_gem_path
else
Bundler.ui.warn("Cannot pristine #{gem_name}. Gem is sourced from local path.")
next
end
Bundler::GemInstaller.new(spec, installer, false, 0, true).install_from_spec
end
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Remove
def initialize(gems, options)
@gems = gems
@options = options
end
def run
raise InvalidOption, "Please specify gems to remove." if @gems.empty?
Injector.remove(@gems, {})
Installer.install(Bundler.root, Bundler.definition)
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Show
attr_reader :options, :gem_name, :latest_specs
def initialize(options, gem_name)
@options = options
@gem_name = gem_name
@verbose = options[:verbose] || options[:outdated]
@latest_specs = fetch_latest_specs if @verbose
end
def run
Bundler.ui.silence do
Bundler.definition.validate_runtime!
Bundler.load.lock
end
if gem_name
if gem_name == "bundler"
path = File.expand_path("../../..", __dir__)
else
spec = Bundler::CLI::Common.select_spec(gem_name, :regex_match)
return unless spec
path = spec.full_gem_path
unless File.directory?(path)
return Bundler.ui.warn "The gem #{gem_name} has been deleted. It was installed at: #{path}"
end
end
return Bundler.ui.info(path)
end
if options[:paths]
Bundler.load.specs.sort_by(&:name).map do |s|
Bundler.ui.info s.full_gem_path
end
else
Bundler.ui.info "Gems included by the bundle:"
Bundler.load.specs.sort_by(&:name).each do |s|
desc = " * #{s.name} (#{s.version}#{s.git_version})"
if @verbose
latest = latest_specs.find {|l| l.name == s.name }
Bundler.ui.info <<-END.gsub(/^ +/, "")
#{desc}
\tSummary: #{s.summary || "No description available."}
\tHomepage: #{s.homepage || "No website available."}
\tStatus: #{outdated?(s, latest) ? "Outdated - #{s.version} < #{latest.version}" : "Up to date"}
END
else
Bundler.ui.info desc
end
end
end
end
private
def fetch_latest_specs
definition = Bundler.definition(true)
if options[:outdated]
Bundler.ui.info "Fetching remote specs for outdated check...\n\n"
Bundler.ui.silence { definition.resolve_remotely! }
else
definition.resolve_with_cache!
end
Bundler.reset!
definition.specs
end
def outdated?(current, latest)
return false unless latest
Gem::Version.new(current.version) < Gem::Version.new(latest.version)
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Update
attr_reader :options, :gems
def initialize(options, gems)
@options = options
@gems = gems
end
def run
Bundler.ui.level = "warn" if options[:quiet]
update_bundler = options[:bundler]
Bundler.self_manager.update_bundler_and_restart_with_it_if_needed(update_bundler) if update_bundler
Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?
sources = Array(options[:source])
groups = Array(options[:group]).map(&:to_sym)
full_update = gems.empty? && sources.empty? && groups.empty? && !options[:ruby] && !update_bundler
if full_update && !options[:all]
if Bundler.feature_flag.update_requires_all_flag?
raise InvalidOption, "To update everything, pass the `--all` flag."
end
SharedHelpers.major_deprecation 3, "Pass --all to `bundle update` to update everything"
elsif !full_update && options[:all]
raise InvalidOption, "Cannot specify --all along with specific options."
end
conservative = options[:conservative]
if full_update
if conservative
Bundler.definition(:conservative => conservative)
else
Bundler.definition(true)
end
else
unless Bundler.default_lockfile.exist?
raise GemfileLockNotFound, "This Bundle hasn't been installed yet. " \
"Run `bundle install` to update and install the bundled gems."
end
Bundler::CLI::Common.ensure_all_gems_in_lockfile!(gems)
if groups.any?
deps = Bundler.definition.dependencies.select {|d| (d.groups & groups).any? }
gems.concat(deps.map(&:name))
end
Bundler.definition(:gems => gems, :sources => sources, :ruby => options[:ruby],
:conservative => conservative,
:bundler => update_bundler)
end
Bundler::CLI::Common.configure_gem_version_promoter(Bundler.definition, options)
Bundler::Fetcher.disable_endpoint = options["full-index"]
opts = options.dup
opts["update"] = true
opts["local"] = options[:local]
Bundler.settings.set_command_option_if_given :jobs, opts["jobs"]
Bundler.definition.validate_runtime!
if locked_gems = Bundler.definition.locked_gems
previous_locked_info = locked_gems.specs.reduce({}) do |h, s|
h[s.name] = { :spec => s, :version => s.version, :source => s.source.identifier }
h
end
end
installer = Installer.install Bundler.root, Bundler.definition, opts
Bundler.load.cache if Bundler.app_cache.exist?
if CLI::Common.clean_after_install?
require_relative "clean"
Bundler::CLI::Clean.new(options).run
end
if locked_gems
gems.each do |name|
locked_info = previous_locked_info[name]
next unless locked_info
locked_spec = locked_info[:spec]
new_spec = Bundler.definition.specs[name].first
unless new_spec
unless locked_spec.match_platform(Bundler.local_platform)
Bundler.ui.warn "Bundler attempted to update #{name} but it was not considered because it is for a different platform from the current one"
end
next
end
locked_source = locked_info[:source]
new_source = new_spec.source.identifier
next if locked_source != new_source
new_version = new_spec.version
locked_version = locked_info[:version]
if new_version < locked_version
Bundler.ui.warn "Note: #{name} version regressed from #{locked_version} to #{new_version}"
elsif new_version == locked_version
Bundler.ui.warn "Bundler attempted to update #{name} but its version stayed the same"
end
end
end
Bundler.ui.confirm "Bundle updated!"
Bundler::CLI::Common.output_without_groups_message(:update)
Bundler::CLI::Common.output_post_install_messages installer.post_install_messages
Bundler::CLI::Common.output_fund_metadata_summary
end
end
end
# frozen_string_literal: true
module Bundler
class CLI::Viz
attr_reader :options, :gem_name
def initialize(options)
@options = options
end
def run
# make sure we get the right `graphviz`. There is also a `graphviz`
# gem we're not built to support
gem "ruby-graphviz"
require "graphviz"
options[:without] = options[:without].join(":").tr(" ", ":").split(":")
output_file = File.expand_path(options[:file])
graph = Graph.new(Bundler.load, output_file, options[:version], options[:requirements], options[:format], options[:without])
graph.viz
rescue LoadError => e
Bundler.ui.error e.inspect
Bundler.ui.warn "Make sure you have the graphviz ruby gem. You can install it with:"
Bundler.ui.warn "`gem install ruby-graphviz`"
rescue StandardError => e
raise unless e.message =~ /GraphViz not installed or dot not in PATH/
Bundler.ui.error e.message
Bundler.ui.warn "Please install GraphViz. On a Mac with Homebrew, you can run `brew install graphviz`."
end
end
end
# frozen_string_literal: true
require "pathname"
require "set"
module Bundler
class CompactIndexClient
DEBUG_MUTEX = Thread::Mutex.new
def self.debug
return unless ENV["DEBUG_COMPACT_INDEX"]
DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") }
end
class Error < StandardError; end
require_relative "compact_index_client/cache"
require_relative "compact_index_client/updater"
attr_reader :directory
def initialize(directory, fetcher)
@directory = Pathname.new(directory)
@updater = Updater.new(fetcher)
@cache = Cache.new(@directory)
@endpoints = Set.new
@info_checksums_by_name = {}
@parsed_checksums = false
@mutex = Thread::Mutex.new
end
def execution_mode=(block)
Bundler::CompactIndexClient.debug { "execution_mode=" }
@endpoints = Set.new
@execution_mode = block
end
# @return [Lambda] A lambda that takes an array of inputs and a block, and
# maps the inputs with the block in parallel.
#
def execution_mode
@execution_mode || sequentially
end
def sequential_execution_mode!
self.execution_mode = sequentially
end
def sequentially
@sequentially ||= lambda do |inputs, &blk|
inputs.map(&blk)
end
end
def names
Bundler::CompactIndexClient.debug { "/names" }
update(@cache.names_path, "names")
@cache.names
end
def versions
Bundler::CompactIndexClient.debug { "/versions" }
update(@cache.versions_path, "versions")
versions, @info_checksums_by_name = @cache.versions
versions
end
def dependencies(names)
Bundler::CompactIndexClient.debug { "dependencies(#{names})" }
execution_mode.call(names) do |name|
update_info(name)
@cache.dependencies(name).map {|d| d.unshift(name) }
end.flatten(1)
end
def update_and_parse_checksums!
Bundler::CompactIndexClient.debug { "update_and_parse_checksums!" }
return @info_checksums_by_name if @parsed_checksums
update(@cache.versions_path, "versions")
@info_checksums_by_name = @cache.checksums
@parsed_checksums = true
end
private
def update(local_path, remote_path)
Bundler::CompactIndexClient.debug { "update(#{local_path}, #{remote_path})" }
unless synchronize { @endpoints.add?(remote_path) }
Bundler::CompactIndexClient.debug { "already fetched #{remote_path}" }
return
end
@updater.update(local_path, url(remote_path))
end
def update_info(name)
Bundler::CompactIndexClient.debug { "update_info(#{name})" }
path = @cache.info_path(name)
checksum = @updater.checksum_for_file(path)
unless existing = @info_checksums_by_name[name]
Bundler::CompactIndexClient.debug { "skipping updating info for #{name} since it is missing from versions" }
return
end
if checksum == existing
Bundler::CompactIndexClient.debug { "skipping updating info for #{name} since the versions checksum matches the local checksum" }
return
end
Bundler::CompactIndexClient.debug { "updating info for #{name} since the versions checksum #{existing} != the local checksum #{checksum}" }
update(path, "info/#{name}")
end
def url(path)
path
end
def synchronize
@mutex.synchronize { yield }
end
end
end
# frozen_string_literal: true
require_relative "gem_parser"
module Bundler
class CompactIndexClient
class Cache
attr_reader :directory
def initialize(directory)
@directory = Pathname.new(directory).expand_path
info_roots.each do |dir|
SharedHelpers.filesystem_access(dir) do
FileUtils.mkdir_p(dir)
end
end
end
def names
lines(names_path)
end
def names_path
directory.join("names")
end
def versions
versions_by_name = Hash.new {|hash, key| hash[key] = [] }
info_checksums_by_name = {}
lines(versions_path).each do |line|
name, versions_string, info_checksum = line.split(" ", 3)
info_checksums_by_name[name] = info_checksum || ""
versions_string.split(",").each do |version|
if version.start_with?("-")
version = version[1..-1].split("-", 2).unshift(name)
versions_by_name[name].delete(version)
else
version = version.split("-", 2).unshift(name)
versions_by_name[name] << version
end
end
end
[versions_by_name, info_checksums_by_name]
end
def versions_path
directory.join("versions")
end
def checksums
checksums = {}
lines(versions_path).each do |line|
name, _, checksum = line.split(" ", 3)
checksums[name] = checksum
end
checksums
end
def dependencies(name)
lines(info_path(name)).map do |line|
parse_gem(line)
end
end
def info_path(name)
name = name.to_s
if name =~ /[^a-z0-9_-]/
name += "-#{SharedHelpers.digest(:MD5).hexdigest(name).downcase}"
info_roots.last.join(name)
else
info_roots.first.join(name)
end
end
private
def lines(path)
return [] unless path.file?
lines = SharedHelpers.filesystem_access(path, :read, &:read).split("\n")
header = lines.index("---")
header ? lines[header + 1..-1] : lines
end
def parse_gem(line)
@dependency_parser ||= GemParser.new
@dependency_parser.parse(line)
end
def info_roots
[
directory.join("info"),
directory.join("info-special-characters"),
]
end
end
end
end