travis-backup 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +7 -0
- data/.travis.yml +33 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +212 -0
- data/README.md +109 -0
- data/Rakefile +18 -0
- data/bin/bundle +114 -0
- data/bin/console +8 -0
- data/bin/rails +5 -0
- data/bin/rake +7 -0
- data/bin/setup +36 -0
- data/bin/spring +14 -0
- data/bin/travis_backup +7 -0
- data/bin/yarn +17 -0
- data/config/application.rb +22 -0
- data/config/boot.rb +4 -0
- data/config/cable.yml +10 -0
- data/config/credentials.yml.enc +1 -0
- data/config/database.yml +20 -0
- data/config/environment.rb +5 -0
- data/config/environments/development.rb +76 -0
- data/config/environments/production.rb +120 -0
- data/config/environments/test.rb +60 -0
- data/config/initializers/application_controller_renderer.rb +8 -0
- data/config/initializers/assets.rb +14 -0
- data/config/initializers/backtrace_silencers.rb +8 -0
- data/config/initializers/content_security_policy.rb +30 -0
- data/config/initializers/cookies_serializer.rb +5 -0
- data/config/initializers/filter_parameter_logging.rb +6 -0
- data/config/initializers/inflections.rb +16 -0
- data/config/initializers/mime_types.rb +4 -0
- data/config/initializers/permissions_policy.rb +11 -0
- data/config/initializers/wrap_parameters.rb +14 -0
- data/config/locales/en.yml +33 -0
- data/config/puma.rb +43 -0
- data/config/routes.rb +3 -0
- data/config/settings.yml +7 -0
- data/config/spring.rb +6 -0
- data/config.ru +5 -0
- data/db/schema.sql +3502 -0
- data/dump/.keep +0 -0
- data/lib/config.rb +127 -0
- data/lib/models/build.rb +13 -0
- data/lib/models/job.rb +13 -0
- data/lib/models/model.rb +8 -0
- data/lib/models/organization.rb +7 -0
- data/lib/models/repository.rb +11 -0
- data/lib/models/user.rb +7 -0
- data/lib/travis-backup.rb +134 -0
- data/log/.keep +0 -0
- data/package.json +11 -0
- data/tmp/.keep +0 -0
- data/travis-backup.gemspec +29 -0
- data/vendor/.keep +0 -0
- metadata +286 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b88fafbc38de9343ca5ead6600c182858c39b14210a60f05081543bf74c8964
|
4
|
+
data.tar.gz: d45a8734295f8dfb01675e333d99c6e19b441fd2290be042ced8b0e2d3e161c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 879009e7cbffc3be645bc12746ce25598b9d013ca81e0aa18370644c6c5bfba3d300d67fcd297e36fc0f941c41a0250cbd50fb3426211ae655e16c0f006b2a56
|
7
|
+
data.tar.gz: 316429ee0dd693f3ba737abbc341f0afef919c4ff85d677fc2652dc71f42b6ba6a76580526f0f42f8bff8ed9fc28fbd0743f3157f559209f19844899ee13b421
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
rvm: 2.7.2
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
services:
|
5
|
+
- redis
|
6
|
+
|
7
|
+
env:
|
8
|
+
global:
|
9
|
+
- PATH=/snap/bin:$PATH
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
include:
|
13
|
+
- stage: "testing time"
|
14
|
+
script: bundle exec rspec
|
15
|
+
|
16
|
+
dist: xenial
|
17
|
+
|
18
|
+
before_install:
|
19
|
+
- gem install bundler
|
20
|
+
- sudo apt-get install -yq --no-install-suggests --no-install-recommends postgresql-common
|
21
|
+
- sudo service postgresql stop
|
22
|
+
- sudo apt install -yq --no-install-suggests --no-install-recommends postgresql-11 postgresql-client-11
|
23
|
+
- sed -e 's/^port.*/port = 5432/' /etc/postgresql/11/main/postgresql.conf > postgresql.conf
|
24
|
+
- sudo chown postgres postgresql.conf
|
25
|
+
- sudo mv postgresql.conf /etc/postgresql/11/main
|
26
|
+
- sudo cp /etc/postgresql/{10,11}/main/pg_hba.conf
|
27
|
+
- sudo service postgresql start 11
|
28
|
+
|
29
|
+
before_script:
|
30
|
+
- psql --version
|
31
|
+
- psql -c 'CREATE DATABASE travis_test;' -U postgres
|
32
|
+
- psql -t -c "SELECT 1 FROM pg_roles WHERE rolname='travis'" -U postgres | grep 1 || psql -c 'CREATE ROLE travis SUPERUSER LOGIN CREATEDB;' -U postgres
|
33
|
+
- psql -f db/schema.sql -v ON_ERROR_STOP=1 travis_test
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,212 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
travis-backup (0.0.1)
|
5
|
+
activerecord
|
6
|
+
bootsnap
|
7
|
+
pg
|
8
|
+
pry
|
9
|
+
rails
|
10
|
+
tzinfo-data
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
actioncable (6.1.4.1)
|
16
|
+
actionpack (= 6.1.4.1)
|
17
|
+
activesupport (= 6.1.4.1)
|
18
|
+
nio4r (~> 2.0)
|
19
|
+
websocket-driver (>= 0.6.1)
|
20
|
+
actionmailbox (6.1.4.1)
|
21
|
+
actionpack (= 6.1.4.1)
|
22
|
+
activejob (= 6.1.4.1)
|
23
|
+
activerecord (= 6.1.4.1)
|
24
|
+
activestorage (= 6.1.4.1)
|
25
|
+
activesupport (= 6.1.4.1)
|
26
|
+
mail (>= 2.7.1)
|
27
|
+
actionmailer (6.1.4.1)
|
28
|
+
actionpack (= 6.1.4.1)
|
29
|
+
actionview (= 6.1.4.1)
|
30
|
+
activejob (= 6.1.4.1)
|
31
|
+
activesupport (= 6.1.4.1)
|
32
|
+
mail (~> 2.5, >= 2.5.4)
|
33
|
+
rails-dom-testing (~> 2.0)
|
34
|
+
actionpack (6.1.4.1)
|
35
|
+
actionview (= 6.1.4.1)
|
36
|
+
activesupport (= 6.1.4.1)
|
37
|
+
rack (~> 2.0, >= 2.0.9)
|
38
|
+
rack-test (>= 0.6.3)
|
39
|
+
rails-dom-testing (~> 2.0)
|
40
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
41
|
+
actiontext (6.1.4.1)
|
42
|
+
actionpack (= 6.1.4.1)
|
43
|
+
activerecord (= 6.1.4.1)
|
44
|
+
activestorage (= 6.1.4.1)
|
45
|
+
activesupport (= 6.1.4.1)
|
46
|
+
nokogiri (>= 1.8.5)
|
47
|
+
actionview (6.1.4.1)
|
48
|
+
activesupport (= 6.1.4.1)
|
49
|
+
builder (~> 3.1)
|
50
|
+
erubi (~> 1.4)
|
51
|
+
rails-dom-testing (~> 2.0)
|
52
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
53
|
+
activejob (6.1.4.1)
|
54
|
+
activesupport (= 6.1.4.1)
|
55
|
+
globalid (>= 0.3.6)
|
56
|
+
activemodel (6.1.4.1)
|
57
|
+
activesupport (= 6.1.4.1)
|
58
|
+
activerecord (6.1.4.1)
|
59
|
+
activemodel (= 6.1.4.1)
|
60
|
+
activesupport (= 6.1.4.1)
|
61
|
+
activestorage (6.1.4.1)
|
62
|
+
actionpack (= 6.1.4.1)
|
63
|
+
activejob (= 6.1.4.1)
|
64
|
+
activerecord (= 6.1.4.1)
|
65
|
+
activesupport (= 6.1.4.1)
|
66
|
+
marcel (~> 1.0.0)
|
67
|
+
mini_mime (>= 1.1.0)
|
68
|
+
activesupport (6.1.4.1)
|
69
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
70
|
+
i18n (>= 1.6, < 2)
|
71
|
+
minitest (>= 5.1)
|
72
|
+
tzinfo (~> 2.0)
|
73
|
+
zeitwerk (~> 2.3)
|
74
|
+
ast (2.4.2)
|
75
|
+
bootsnap (1.7.7)
|
76
|
+
msgpack (~> 1.0)
|
77
|
+
brakeman (5.1.1)
|
78
|
+
builder (3.2.4)
|
79
|
+
byebug (11.1.3)
|
80
|
+
coderay (1.1.3)
|
81
|
+
concurrent-ruby (1.1.9)
|
82
|
+
crass (1.0.6)
|
83
|
+
diff-lcs (1.4.4)
|
84
|
+
erubi (1.10.0)
|
85
|
+
factory_bot (6.2.0)
|
86
|
+
activesupport (>= 5.0.0)
|
87
|
+
ffi (1.15.3)
|
88
|
+
globalid (0.5.2)
|
89
|
+
activesupport (>= 5.0)
|
90
|
+
i18n (1.8.10)
|
91
|
+
concurrent-ruby (~> 1.0)
|
92
|
+
jaro_winkler (1.5.4)
|
93
|
+
listen (3.7.0)
|
94
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
95
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
96
|
+
loofah (2.12.0)
|
97
|
+
crass (~> 1.0.2)
|
98
|
+
nokogiri (>= 1.5.9)
|
99
|
+
mail (2.7.1)
|
100
|
+
mini_mime (>= 0.1.1)
|
101
|
+
marcel (1.0.1)
|
102
|
+
method_source (1.0.0)
|
103
|
+
mini_mime (1.1.1)
|
104
|
+
mini_portile2 (2.6.1)
|
105
|
+
minitest (5.14.4)
|
106
|
+
msgpack (1.4.2)
|
107
|
+
nio4r (2.5.8)
|
108
|
+
nokogiri (1.12.3)
|
109
|
+
mini_portile2 (~> 2.6.1)
|
110
|
+
racc (~> 1.4)
|
111
|
+
parallel (1.20.1)
|
112
|
+
parser (3.0.2.0)
|
113
|
+
ast (~> 2.4.1)
|
114
|
+
pg (1.2.3)
|
115
|
+
pry (0.14.1)
|
116
|
+
coderay (~> 1.1)
|
117
|
+
method_source (~> 1.0)
|
118
|
+
racc (1.5.2)
|
119
|
+
rack (2.2.3)
|
120
|
+
rack-test (1.1.0)
|
121
|
+
rack (>= 1.0, < 3)
|
122
|
+
rails (6.1.4.1)
|
123
|
+
actioncable (= 6.1.4.1)
|
124
|
+
actionmailbox (= 6.1.4.1)
|
125
|
+
actionmailer (= 6.1.4.1)
|
126
|
+
actionpack (= 6.1.4.1)
|
127
|
+
actiontext (= 6.1.4.1)
|
128
|
+
actionview (= 6.1.4.1)
|
129
|
+
activejob (= 6.1.4.1)
|
130
|
+
activemodel (= 6.1.4.1)
|
131
|
+
activerecord (= 6.1.4.1)
|
132
|
+
activestorage (= 6.1.4.1)
|
133
|
+
activesupport (= 6.1.4.1)
|
134
|
+
bundler (>= 1.15.0)
|
135
|
+
railties (= 6.1.4.1)
|
136
|
+
sprockets-rails (>= 2.0.0)
|
137
|
+
rails-dom-testing (2.0.3)
|
138
|
+
activesupport (>= 4.2.0)
|
139
|
+
nokogiri (>= 1.6)
|
140
|
+
rails-html-sanitizer (1.4.1)
|
141
|
+
loofah (~> 2.3)
|
142
|
+
railties (6.1.4.1)
|
143
|
+
actionpack (= 6.1.4.1)
|
144
|
+
activesupport (= 6.1.4.1)
|
145
|
+
method_source
|
146
|
+
rake (>= 0.13)
|
147
|
+
thor (~> 1.0)
|
148
|
+
rainbow (3.0.0)
|
149
|
+
rake (13.0.6)
|
150
|
+
rb-fsevent (0.11.0)
|
151
|
+
rb-inotify (0.10.1)
|
152
|
+
ffi (~> 1.0)
|
153
|
+
rspec-core (3.10.1)
|
154
|
+
rspec-support (~> 3.10.0)
|
155
|
+
rspec-expectations (3.10.1)
|
156
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
157
|
+
rspec-support (~> 3.10.0)
|
158
|
+
rspec-mocks (3.10.2)
|
159
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
160
|
+
rspec-support (~> 3.10.0)
|
161
|
+
rspec-rails (5.0.2)
|
162
|
+
actionpack (>= 5.2)
|
163
|
+
activesupport (>= 5.2)
|
164
|
+
railties (>= 5.2)
|
165
|
+
rspec-core (~> 3.10)
|
166
|
+
rspec-expectations (~> 3.10)
|
167
|
+
rspec-mocks (~> 3.10)
|
168
|
+
rspec-support (~> 3.10)
|
169
|
+
rspec-support (3.10.2)
|
170
|
+
rubocop (0.75.1)
|
171
|
+
jaro_winkler (~> 1.5.1)
|
172
|
+
parallel (~> 1.10)
|
173
|
+
parser (>= 2.6)
|
174
|
+
rainbow (>= 2.2.2, < 4.0)
|
175
|
+
ruby-progressbar (~> 1.7)
|
176
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
177
|
+
rubocop-rspec (1.41.0)
|
178
|
+
rubocop (>= 0.68.1)
|
179
|
+
ruby-progressbar (1.11.0)
|
180
|
+
sprockets (4.0.2)
|
181
|
+
concurrent-ruby (~> 1.0)
|
182
|
+
rack (> 1, < 3)
|
183
|
+
sprockets-rails (3.2.2)
|
184
|
+
actionpack (>= 4.0)
|
185
|
+
activesupport (>= 4.0)
|
186
|
+
sprockets (>= 3.0.0)
|
187
|
+
thor (1.1.0)
|
188
|
+
tzinfo (2.0.4)
|
189
|
+
concurrent-ruby (~> 1.0)
|
190
|
+
tzinfo-data (1.2021.1)
|
191
|
+
tzinfo (>= 1.0.0)
|
192
|
+
unicode-display_width (1.6.1)
|
193
|
+
websocket-driver (0.7.5)
|
194
|
+
websocket-extensions (>= 0.1.0)
|
195
|
+
websocket-extensions (0.1.5)
|
196
|
+
zeitwerk (2.4.2)
|
197
|
+
|
198
|
+
PLATFORMS
|
199
|
+
ruby
|
200
|
+
|
201
|
+
DEPENDENCIES
|
202
|
+
brakeman
|
203
|
+
byebug
|
204
|
+
factory_bot
|
205
|
+
listen
|
206
|
+
rspec-rails
|
207
|
+
rubocop (~> 0.75.1)
|
208
|
+
rubocop-rspec
|
209
|
+
travis-backup!
|
210
|
+
|
211
|
+
BUNDLED WITH
|
212
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
*travis-backup* is an application that removes builds and their corresponding jobs
|
4
|
+
and exports them (optionally) to json files.
|
5
|
+
|
6
|
+
### Installation and run
|
7
|
+
|
8
|
+
You can install the gem using
|
9
|
+
|
10
|
+
`gem install travis-backup`
|
11
|
+
|
12
|
+
Next you can run it in your app like
|
13
|
+
|
14
|
+
```
|
15
|
+
require 'travis-backup'
|
16
|
+
|
17
|
+
backup = Backup.new
|
18
|
+
backup.run
|
19
|
+
|
20
|
+
# or with configs:
|
21
|
+
|
22
|
+
backup = Backup.new(
|
23
|
+
if_backup: true,
|
24
|
+
limit: 500,
|
25
|
+
threshold: 12,
|
26
|
+
files_location: './my_folder/dump',
|
27
|
+
database_url: 'postgresql://postgres:pass@localhost:5432/my_db'
|
28
|
+
)
|
29
|
+
backup.run
|
30
|
+
```
|
31
|
+
|
32
|
+
You can also run backup only for given user, organisation or repository:
|
33
|
+
|
34
|
+
```
|
35
|
+
backup = Backup.new
|
36
|
+
backup.run(user_id: 1)
|
37
|
+
# or
|
38
|
+
backup.run(org_id: 1)
|
39
|
+
# or
|
40
|
+
backup.run(repo_id: 1)
|
41
|
+
```
|
42
|
+
|
43
|
+
### Configuration
|
44
|
+
|
45
|
+
One of the ways you can configure your export is a file `config/settinigs.yml` that you should place in your app's main directory. The gem uses the properties in following format:
|
46
|
+
|
47
|
+
```
|
48
|
+
backup:
|
49
|
+
if_backup: true # when false, removes data without saving it to file
|
50
|
+
dry_run: false # when true, only prints in console what data should be backuped and deleted
|
51
|
+
limit: 1000 # builds limit for one backup file
|
52
|
+
threshold: 6 # number of months from now - data younger than this time won't be backuped
|
53
|
+
files_location: './dump' # path of the folder in which backup files will be placed
|
54
|
+
user_id # run only for given user
|
55
|
+
org_id # run only for given organization
|
56
|
+
repo_id # run only for given repository
|
57
|
+
```
|
58
|
+
|
59
|
+
You can also set these properties as hash arguments while creating `Backup` instance or use env vars corresponding to them: `IF_BACKUP`, `BACKUP_DRY_RUN`, `BACKUP_LIMIT`, `BACKUP_THRESHOLD`, `BACKUP_FILES_LOCATION`, `USER_ID`, `ORG_ID`, `REPO_ID`.
|
60
|
+
|
61
|
+
You should also specify your database url. You can do this the standard way in `config/database.yml` file, setting the `database_url` hash argument while creating `Backup` instance or using the `DATABASE_URL` env var. Your database should be consistent with the Travis 2.2 database schema.
|
62
|
+
|
63
|
+
### How to run the test suite
|
64
|
+
|
65
|
+
You can run the test after cloning this repository. Next you should call
|
66
|
+
|
67
|
+
```
|
68
|
+
bundle install
|
69
|
+
```
|
70
|
+
|
71
|
+
and
|
72
|
+
|
73
|
+
```
|
74
|
+
bundle exec rspec
|
75
|
+
```
|
76
|
+
|
77
|
+
To make tests working properly you should also ensure the database connection string for an empty test database. You can set it as `DATABASE_URL` environment variable or in `config/database.yml`.
|
78
|
+
|
79
|
+
**Warning: this database will be cleaned during tests, so ensure that it includes no important data.**
|
80
|
+
|
81
|
+
#### Using as standalone application
|
82
|
+
|
83
|
+
After cloning this repo you can also run it as a standalone app using
|
84
|
+
|
85
|
+
```
|
86
|
+
bundle exec bin/travis_backup
|
87
|
+
```
|
88
|
+
|
89
|
+
You can also pass arguments:
|
90
|
+
|
91
|
+
```
|
92
|
+
first argument, no flag # database url
|
93
|
+
-b, --backup # when not present, removes data without saving it to file
|
94
|
+
-d, --dry_run # only prints in console what data will be backuped and deleted
|
95
|
+
-l, --limit LIMIT # builds limit for one backup file
|
96
|
+
-t, --threshold MONTHS # number of months from now - data younger than this time won't be backuped
|
97
|
+
-f, --files_location PATH # path of the folder in which backup files will be placed
|
98
|
+
-u, --user_id ID # run only for given user
|
99
|
+
-o, --org_id ID # run only for given organization
|
100
|
+
-r, --repo_id ID # run only for given repository
|
101
|
+
|
102
|
+
# example:
|
103
|
+
|
104
|
+
bundle exec bin/travis_backup 'postgres://user:pass@localhost:5432/my_db' -b
|
105
|
+
```
|
106
|
+
|
107
|
+
### Ruby version
|
108
|
+
|
109
|
+
2.7.2
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :backup do
|
2
|
+
desc 'Backup all daily outdated build/job'
|
3
|
+
task :cron do
|
4
|
+
$: << 'lib'
|
5
|
+
require 'travis-backup'
|
6
|
+
|
7
|
+
Backup.new.run
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
namespace :spec do
|
12
|
+
desc 'Run all specs'
|
13
|
+
task :all do
|
14
|
+
sh 'bundle exec rspec spec'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
task :default => :'backup:cron'
|
data/bin/bundle
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
27
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||=
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version
|
67
|
+
end
|
68
|
+
|
69
|
+
def bundler_requirement
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
71
|
+
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
73
|
+
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
75
|
+
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
77
|
+
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
79
|
+
|
80
|
+
requirement
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_bundler!
|
84
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
85
|
+
|
86
|
+
activate_bundler
|
87
|
+
end
|
88
|
+
|
89
|
+
def activate_bundler
|
90
|
+
gem_error = activation_error_handling do
|
91
|
+
gem "bundler", bundler_requirement
|
92
|
+
end
|
93
|
+
return if gem_error.nil?
|
94
|
+
require_error = activation_error_handling do
|
95
|
+
require "bundler/version"
|
96
|
+
end
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
99
|
+
exit 42
|
100
|
+
end
|
101
|
+
|
102
|
+
def activation_error_handling
|
103
|
+
yield
|
104
|
+
nil
|
105
|
+
rescue StandardError, LoadError => e
|
106
|
+
e
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
m.load_bundler!
|
111
|
+
|
112
|
+
if m.invoked_as_script?
|
113
|
+
load Gem.bin_path("bundler", "bundle")
|
114
|
+
end
|