rubygems-await 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1114eb23bcdd6c4932bbd835f9d2b8be1ea2bcb49070847cd4b651d9275d1cd5
4
+ data.tar.gz: 95ce1d2b97f8a38d66a0f6c5d40057d184b4b70462abe4bddeea81c87fb20c22
5
+ SHA512:
6
+ metadata.gz: 84ad10350999301e02a003d77b601d6bafdc73e5c9ca7f525cae3d2087a335f01d1b8497e4e03bcca0a8bc1704443f9cc94636a4dfdef207c4efc1cd7cb94636
7
+ data.tar.gz: 79322fc8694d5e31e78ded0ec4a4a759335d409791066ada7582c05bff207644c6490c8f92b7163733b5e83c04b0881ae20e744930db342ef511aa5a3b4a798b
data/.rubocop.yml ADDED
@@ -0,0 +1,213 @@
1
+ require:
2
+ - rubocop-rake
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 3.2
6
+
7
+ Style/StringLiterals:
8
+ Enabled: true
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ Enabled: true
13
+ EnforcedStyle: double_quotes
14
+
15
+ Layout/LineLength:
16
+ Max: 120
17
+
18
+ Metrics:
19
+ Enabled: false
20
+
21
+ Style/Documentation:
22
+ Enabled: false
23
+
24
+ Gemspec/DeprecatedAttributeAssignment: # new in 1.30
25
+ Enabled: true
26
+ Gemspec/DevelopmentDependencies: # new in 1.44
27
+ Enabled: true
28
+ Gemspec/RequireMFA: # new in 1.23
29
+ Enabled: true
30
+ Layout/LineContinuationLeadingSpace: # new in 1.31
31
+ Enabled: true
32
+ Layout/LineContinuationSpacing: # new in 1.31
33
+ Enabled: true
34
+ Layout/LineEndStringConcatenationIndentation: # new in 1.18
35
+ Enabled: true
36
+ Layout/SpaceBeforeBrackets: # new in 1.7
37
+ Enabled: true
38
+ Lint/AmbiguousAssignment: # new in 1.7
39
+ Enabled: true
40
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
41
+ Enabled: true
42
+ Lint/AmbiguousRange: # new in 1.19
43
+ Enabled: true
44
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
45
+ Enabled: true
46
+ Lint/DeprecatedConstants: # new in 1.8
47
+ Enabled: true
48
+ Lint/DuplicateBranch: # new in 1.3
49
+ Enabled: true
50
+ Lint/DuplicateMagicComment: # new in 1.37
51
+ Enabled: true
52
+ Lint/DuplicateMatchPattern: # new in 1.50
53
+ Enabled: true
54
+ Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
55
+ Enabled: true
56
+ Lint/EmptyBlock: # new in 1.1
57
+ Enabled: true
58
+ Lint/EmptyClass: # new in 1.3
59
+ Enabled: true
60
+ Lint/EmptyInPattern: # new in 1.16
61
+ Enabled: true
62
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
63
+ Enabled: true
64
+ Lint/LambdaWithoutLiteralBlock: # new in 1.8
65
+ Enabled: true
66
+ Lint/MixedCaseRange: # new in 1.53
67
+ Enabled: true
68
+ Lint/NoReturnInBeginEndBlocks: # new in 1.2
69
+ Enabled: true
70
+ Lint/NonAtomicFileOperation: # new in 1.31
71
+ Enabled: true
72
+ Lint/NumberedParameterAssignment: # new in 1.9
73
+ Enabled: true
74
+ Lint/OrAssignmentToConstant: # new in 1.9
75
+ Enabled: true
76
+ Lint/RedundantDirGlobSort: # new in 1.8
77
+ Enabled: true
78
+ Lint/RedundantRegexpQuantifiers: # new in 1.53
79
+ Enabled: true
80
+ Lint/RefinementImportMethods: # new in 1.27
81
+ Enabled: true
82
+ Lint/RequireRangeParentheses: # new in 1.32
83
+ Enabled: true
84
+ Lint/RequireRelativeSelfPath: # new in 1.22
85
+ Enabled: true
86
+ Lint/SymbolConversion: # new in 1.9
87
+ Enabled: true
88
+ Lint/ToEnumArguments: # new in 1.1
89
+ Enabled: true
90
+ Lint/TripleQuotes: # new in 1.9
91
+ Enabled: true
92
+ Lint/UnexpectedBlockArity: # new in 1.5
93
+ Enabled: true
94
+ Lint/UnmodifiedReduceAccumulator: # new in 1.1
95
+ Enabled: true
96
+ Lint/UselessRescue: # new in 1.43
97
+ Enabled: true
98
+ Lint/UselessRuby2Keywords: # new in 1.23
99
+ Enabled: true
100
+ Naming/BlockForwarding: # new in 1.24
101
+ Enabled: true
102
+ Security/CompoundHash: # new in 1.28
103
+ Enabled: true
104
+ Security/IoMethods: # new in 1.22
105
+ Enabled: true
106
+ Style/ArgumentsForwarding: # new in 1.1
107
+ Enabled: true
108
+ Style/ArrayIntersect: # new in 1.40
109
+ Enabled: true
110
+ Style/CollectionCompact: # new in 1.2
111
+ Enabled: true
112
+ Style/ComparableClamp: # new in 1.44
113
+ Enabled: true
114
+ Style/ConcatArrayLiterals: # new in 1.41
115
+ Enabled: true
116
+ Style/DataInheritance: # new in 1.49
117
+ Enabled: true
118
+ Style/DirEmpty: # new in 1.48
119
+ Enabled: true
120
+ Style/DocumentDynamicEvalDefinition: # new in 1.1
121
+ Enabled: true
122
+ Style/EmptyHeredoc: # new in 1.32
123
+ Enabled: true
124
+ Style/EndlessMethod: # new in 1.8
125
+ Enabled: true
126
+ Style/EnvHome: # new in 1.29
127
+ Enabled: true
128
+ Style/ExactRegexpMatch: # new in 1.51
129
+ Enabled: true
130
+ Style/FetchEnvVar: # new in 1.28
131
+ Enabled: true
132
+ Style/FileEmpty: # new in 1.48
133
+ Enabled: true
134
+ Style/FileRead: # new in 1.24
135
+ Enabled: true
136
+ Style/FileWrite: # new in 1.24
137
+ Enabled: true
138
+ Style/HashConversion: # new in 1.10
139
+ Enabled: true
140
+ Style/HashExcept: # new in 1.7
141
+ Enabled: true
142
+ Style/IfWithBooleanLiteralBranches: # new in 1.9
143
+ Enabled: true
144
+ Style/InPatternThen: # new in 1.16
145
+ Enabled: true
146
+ Style/MagicCommentFormat: # new in 1.35
147
+ Enabled: true
148
+ Style/MapCompactWithConditionalBlock: # new in 1.30
149
+ Enabled: true
150
+ Style/MapToHash: # new in 1.24
151
+ Enabled: true
152
+ Style/MapToSet: # new in 1.42
153
+ Enabled: true
154
+ Style/MinMaxComparison: # new in 1.42
155
+ Enabled: true
156
+ Style/MultilineInPatternThen: # new in 1.16
157
+ Enabled: true
158
+ Style/NegatedIfElseCondition: # new in 1.2
159
+ Enabled: true
160
+ Style/NestedFileDirname: # new in 1.26
161
+ Enabled: true
162
+ Style/NilLambda: # new in 1.3
163
+ Enabled: true
164
+ Style/NumberedParameters: # new in 1.22
165
+ Enabled: true
166
+ Style/NumberedParametersLimit: # new in 1.22
167
+ Enabled: true
168
+ Style/ObjectThen: # new in 1.28
169
+ Enabled: true
170
+ Style/OpenStructUse: # new in 1.23
171
+ Enabled: true
172
+ Style/OperatorMethodCall: # new in 1.37
173
+ Enabled: true
174
+ Style/QuotedSymbols: # new in 1.16
175
+ Enabled: true
176
+ Style/RedundantArgument: # new in 1.4
177
+ Enabled: true
178
+ Style/RedundantArrayConstructor: # new in 1.52
179
+ Enabled: true
180
+ Style/RedundantConstantBase: # new in 1.40
181
+ Enabled: true
182
+ Style/RedundantCurrentDirectoryInPath: # new in 1.53
183
+ Enabled: true
184
+ Style/RedundantDoubleSplatHashBraces: # new in 1.41
185
+ Enabled: true
186
+ Style/RedundantEach: # new in 1.38
187
+ Enabled: true
188
+ Style/RedundantFilterChain: # new in 1.52
189
+ Enabled: true
190
+ Style/RedundantHeredocDelimiterQuotes: # new in 1.45
191
+ Enabled: true
192
+ Style/RedundantInitialize: # new in 1.27
193
+ Enabled: true
194
+ Style/RedundantLineContinuation: # new in 1.49
195
+ Enabled: true
196
+ Style/RedundantRegexpArgument: # new in 1.53
197
+ Enabled: true
198
+ Style/RedundantRegexpConstructor: # new in 1.52
199
+ Enabled: true
200
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
201
+ Enabled: true
202
+ Style/RedundantStringEscape: # new in 1.37
203
+ Enabled: true
204
+ Style/ReturnNilInPredicateMethodDefinition: # new in 1.53
205
+ Enabled: true
206
+ Style/SelectByRegexp: # new in 1.22
207
+ Enabled: true
208
+ Style/StringChars: # new in 1.12
209
+ Enabled: true
210
+ Style/SwapValues: # new in 1.1
211
+ Enabled: true
212
+ Style/YAMLFileRead: # new in 1.53
213
+ Enabled: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-10-02
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders 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, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at segiddins@segiddins.me. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Samuel Giddins
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # `rubygems-await`
2
+
3
+ ## Installation
4
+
5
+ Install the gem and add to the application's Gemfile by executing:
6
+
7
+ $ bundle add rubygems-await
8
+
9
+ If bundler is not being used to manage dependencies, install the gem by executing:
10
+
11
+ $ gem install rubygems-await
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ Usage: gem await [OPTIONS] GEMNAME:VERSION[:PLATFORM] ... [options]
17
+
18
+ Options:
19
+ --skip NAME Skip the given awaiter
20
+ --include NAME Do not skip the given awaiter
21
+ --only NAME Only run the given awaiter
22
+
23
+
24
+ Local/Remote Options:
25
+ -s, --source URL Append URL to list of remote gem sources
26
+
27
+
28
+ Timing Options:
29
+ -t, --timeout DURATION Wait for the given duration before failing
30
+
31
+
32
+ Common Options:
33
+ -h, --help Get help on this command
34
+ -V, --[no-]verbose Set the verbose level of output
35
+ -q, --quiet Silence command progress meter
36
+ --silent Silence RubyGems output
37
+ --config-file FILE Use this config file instead of default
38
+ --backtrace Show stack backtrace on errors
39
+ --debug Turn on Ruby debugging
40
+ --norc Avoid loading any .gemrc file
41
+
42
+
43
+ Arguments:
44
+ GEMNAME:VERSION[:PLATFORM] name, version and (optional) platform of the gem to await
45
+
46
+ Summary:
47
+ Await pushed gems being available
48
+
49
+ Description:
50
+ The await command will wait for pushed gems to be available on the given
51
+ source. It will wait for the given timeout, or 5 minutes by default.
52
+
53
+ The available awaiters are: dependency api, pre index, full index, gems,
54
+ gemspecs, info, names, versions.
55
+
56
+ Defaults:
57
+ --timeout 300 --skip "dependency api"
58
+ ```
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test-unit` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/segiddins/rubygems-await. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/segiddins/rubygems-await/blob/main/CODE_OF_CONDUCT.md).
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
73
+
74
+ ## Code of Conduct
75
+
76
+ Everyone interacting in the Rubygems::Await project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/segiddins/rubygems-await/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rubygems
4
+ module Await
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,341 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "await/version"
4
+
5
+ module Rubygems
6
+ module Await
7
+ class Error < StandardError; end
8
+
9
+ class Awaiter
10
+ attr_reader :gems, :source, :deadline, :name_indent, :source_uri
11
+
12
+ def initialize(gems, source, deadline, name_indent = 10)
13
+ @gems = gems
14
+ @source = source
15
+ @source_uri = Bundler::URI.parse(source)
16
+ @deadline = deadline
17
+ @name_indent = name_indent
18
+ end
19
+
20
+ def self.call(...)
21
+ Thread.new do
22
+ awaiter = new(...)
23
+ Thread.current.name = "#{awaiter_name} awaiter"
24
+ Thread.current.report_on_exception = false
25
+
26
+ awaiter.call
27
+ end
28
+ end
29
+
30
+ def collection
31
+ Set.new(@gems)
32
+ end
33
+
34
+ def call
35
+ missing = collection
36
+ iteration = 0
37
+ loop do
38
+ break if missing.empty? || expired?(iteration)
39
+
40
+ sleep iteration if iteration.positive?
41
+ start = Time.now
42
+
43
+ log { "#{Bundler.ui.add_color("missing", :yellow)}: #{format_element(missing)}" }
44
+ process_collection(missing)
45
+ rescue StandardError => e
46
+ log_error(e)
47
+ ensure
48
+ iteration += 1
49
+ log(level: "debug") { "##{iteration} #{Time.now.-(start).round(2)}s" } if start
50
+ end
51
+
52
+ if missing.empty?
53
+ log { Bundler.ui.add_color("all found!", :green, :bold) }
54
+ else
55
+ log(level: "error") { "#{Bundler.ui.add_color("missing", :red, :bold)} #{format_element(missing)}" }
56
+ end
57
+
58
+ missing
59
+ end
60
+
61
+ def process_collection(missing)
62
+ to_delete = []
63
+
64
+ missing.each do |m|
65
+ to_delete << m if process_element(m) && log_found(m)
66
+ end
67
+ ensure
68
+ missing.subtract(to_delete)
69
+ end
70
+
71
+ def process_element(element)
72
+ raise NotImplementedError
73
+ end
74
+
75
+ def log_found(element)
76
+ log(level: "info") { "#{Bundler.ui.add_color("found", :green)} #{format_element(element)}" }
77
+
78
+ true
79
+ end
80
+
81
+ def log_error(error, &block)
82
+ block ||= proc { error.message.to_s }
83
+ log(level: "warn", tags: [Bundler.ui.add_color(error.class.name, :red)], &block)
84
+ false
85
+ end
86
+
87
+ def format_element(element)
88
+ case element
89
+ when Gem::NameTuple
90
+ Bundler.ui.add_color element.full_name, :bold
91
+ when Set, Array
92
+ element.map(&method(:format_element)).join(", ")
93
+ when Hash
94
+ element.map { |k, v| "#{k} (#{format_element(v)})" }.join(", ")
95
+ when String
96
+ Bundler.ui.add_color element, :bold
97
+ else
98
+ element.inspect
99
+ end
100
+ end
101
+
102
+ def downloader
103
+ remote = Bundler::Source::Rubygems::Remote.new URI(source)
104
+ fetcher = Bundler::Fetcher.new(remote)
105
+ fetcher.send(:downloader)
106
+ end
107
+
108
+ def compact_index_client
109
+ remote = Bundler::Source::Rubygems::Remote.new URI(source)
110
+ fetcher = Bundler::Fetcher.new(remote)
111
+ client = Bundler::Fetcher::CompactIndex.new(fetcher.send(:downloader), remote,
112
+ fetcher.uri).send(:compact_index_client)
113
+ # ensure that updating info always hits the network
114
+ client.instance_variable_set(:@info_checksums_by_name, Hash.new { "" })
115
+ client
116
+ end
117
+
118
+ def index_fetcher
119
+ remote = Bundler::Source::Rubygems::Remote.new URI(source)
120
+ fetcher = Bundler::Fetcher.new(remote)
121
+ Bundler::Fetcher::Index.new(fetcher.send(:downloader), remote, fetcher.uri)
122
+ end
123
+
124
+ def self.awaiter_name
125
+ raise NotImplementedError
126
+ end
127
+
128
+ def log(level: "info", tags: nil, &)
129
+ return unless Bundler.ui.level(level)
130
+
131
+ s = Time.now.to_s << " "
132
+ case level
133
+ when "info"
134
+ s << Bundler.ui.add_color("I", :white)
135
+ when "warn"
136
+ s << Bundler.ui.add_color("W", :yellow)
137
+ when "error"
138
+ s << Bundler.ui.add_color("E", :red)
139
+ when "debug"
140
+ s << "D"
141
+ else
142
+ raise ArgumentError, "unhandled level #{level.inspect}"
143
+ end
144
+ s << " ["
145
+ s << Bundler.ui.add_color(self.class.awaiter_name.rjust(name_indent, " "), :bold, :white)
146
+ s << "] "
147
+ tags&.each do |tag|
148
+ s << Bundler.ui.add_color("[#{tag}]", :white)
149
+ s << " "
150
+ end
151
+ s << yield
152
+ Bundler.ui.info s
153
+ end
154
+
155
+ def expired?(padding = 0)
156
+ Time.now + padding > deadline
157
+ end
158
+ end
159
+
160
+ class VersionsAwaiter < Awaiter
161
+ def collection
162
+ gems.group_by(&:name)
163
+ end
164
+
165
+ def process_collection(missing)
166
+ versions = compact_index_client.versions
167
+ missing.delete_if do |name, tuples|
168
+ found = versions[name]
169
+ tuples.delete_if do |tuple|
170
+ found.include?(tuple.to_a - [nil, "", "ruby"]) && log_found(tuple)
171
+ end
172
+ tuples.empty?
173
+ end
174
+ end
175
+
176
+ def self.awaiter_name
177
+ "versions"
178
+ end
179
+ end
180
+
181
+ class NamesAwaiter < Awaiter
182
+ def collection
183
+ Set.new gems.map(&:name)
184
+ end
185
+
186
+ def process_collection(missing)
187
+ compact_index_client.names.each do |name|
188
+ log_found(name) if missing.delete?(name)
189
+ end
190
+ end
191
+
192
+ def self.awaiter_name
193
+ "names"
194
+ end
195
+ end
196
+
197
+ class InfoAwaiter < Awaiter
198
+ def collection
199
+ gems.group_by(&:name).transform_values! { Set.new(_1) }
200
+ end
201
+
202
+ def process_collection(missing)
203
+ missing.delete_if do |name, tuples|
204
+ process_element(name, tuples)
205
+ tuples.empty?
206
+ end
207
+ end
208
+
209
+ def process_element(name, tuples)
210
+ cic = compact_index_client
211
+ cic.send :update_info, name
212
+ info = cic.instance_variable_get(:@cache).dependencies(name)
213
+
214
+ info.each do |version, platform|
215
+ tuple = Gem::NameTuple.new(name, version, platform)
216
+ log_found(tuple) if tuples.delete?(tuple)
217
+ end
218
+ end
219
+
220
+ def self.awaiter_name
221
+ "info"
222
+ end
223
+ end
224
+
225
+ class GemspecsAwaiter < Awaiter
226
+ def process_element(element)
227
+ spec = element.to_a - [nil, "ruby", ""]
228
+ spec_file_name = "#{spec.join "-"}.gemspec"
229
+
230
+ uri = source_uri + "#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz"
231
+
232
+ downloader.fetch(uri)
233
+ true
234
+ rescue Bundler::Fetcher::AuthenticationForbiddenError => e
235
+ log_error(e) { "#{Bundler::URICredentialsFilter.credential_filtered_uri(uri)} not found" }
236
+ false
237
+ end
238
+
239
+ def self.awaiter_name
240
+ "gemspecs"
241
+ end
242
+ end
243
+
244
+ class GemsAwaiter < Awaiter
245
+ def process_element(element)
246
+ gem_file_name = "#{element.full_name}.gem"
247
+ src = Bundler::Source::Rubygems.new(remotes: [source])
248
+ remote_spec = Bundler::RemoteSpecification.new(element.name, element.version, element.platform, index_fetcher)
249
+ cache_dir = src.send(:download_cache_path, remote_spec) ||
250
+ src.send(:default_cache_path_for, Bundler.rubygems.gem_dir)
251
+ local_gem_path = File.join cache_dir, gem_file_name
252
+
253
+ remote_gem_path = source_uri + "gems/#{gem_file_name}"
254
+
255
+ fetcher = Bundler.rubygems.gem_remote_fetcher
256
+ Bundler::SharedHelpers.filesystem_access(local_gem_path) do
257
+ fetcher.cache_update_path remote_gem_path, local_gem_path
258
+ end
259
+ true
260
+ rescue Gem::RemoteFetcher::FetchError => e
261
+ log_error(e)
262
+ false
263
+ end
264
+
265
+ def self.awaiter_name
266
+ "gems"
267
+ end
268
+ end
269
+
270
+ class FullIndexAwaiter < Awaiter
271
+ def collection
272
+ super.delete_if { |t| /[a-z]/i.match?(t.version.to_s) }
273
+ end
274
+
275
+ def process_collection(missing)
276
+ fetcher = Bundler.rubygems.gem_remote_fetcher
277
+ path = source_uri + "specs.#{Gem.marshal_version}.gz"
278
+ contents = fetcher.fetch_path(path)
279
+ idx = Bundler.safe_load_marshal(contents)
280
+
281
+ idx.each do |found|
282
+ tuple = Gem::NameTuple.new(*found.map!(&:to_s))
283
+ log_found(tuple) if missing.delete?(tuple)
284
+ end
285
+ end
286
+
287
+ def self.awaiter_name
288
+ "full index"
289
+ end
290
+ end
291
+
292
+ class PrereleaseIndexAwaiter < Awaiter
293
+ def collection
294
+ super.keep_if { |t| /[a-z]/i.match?(t.version.to_s) }
295
+ end
296
+
297
+ def process_collection(missing)
298
+ fetcher = Bundler.rubygems.gem_remote_fetcher
299
+ path = source_uri + "prerelease_specs.#{Gem.marshal_version}.gz"
300
+ contents = fetcher.fetch_path(path)
301
+ idx = Bundler.safe_load_marshal(contents)
302
+
303
+ idx.each do |found|
304
+ tuple = Gem::NameTuple.new(*found.map!(&:to_s))
305
+ log_found(tuple) if missing.delete?(tuple)
306
+ end
307
+ end
308
+
309
+ def self.awaiter_name
310
+ "pre index"
311
+ end
312
+ end
313
+
314
+ class DependencyAPIAwaiter < Awaiter
315
+ def collection
316
+ gems.group_by(&:name).transform_values! { Set.new(_1) }
317
+ end
318
+
319
+ def process_collection(missing)
320
+ dependency_api_uri = "#{source_uri}api/v1/dependencies"
321
+ dependency_api_uri.query = URI.encode_www_form(gems: missing.keys.sort)
322
+ marshalled_deps = downloader.fetch(dependency_api_uri).body
323
+ deps = Bundler.safe_load_marshal(marshalled_deps)
324
+
325
+ deps.each do |s|
326
+ name, number, platform = s.values_at(:name, :number, :platform)
327
+ tuple = Gem::NameTuple.new(name, number, platform)
328
+ log_found(tuple) if missing[name].delete?(tuple)
329
+ end
330
+
331
+ missing.delete_if do |_name, tuples|
332
+ tuples.empty?
333
+ end
334
+ end
335
+
336
+ def self.awaiter_name
337
+ "dependency api"
338
+ end
339
+ end
340
+ end
341
+ end
@@ -0,0 +1,190 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "rubygems/local_remote_options"
5
+
6
+ module Gem
7
+ module Commands
8
+ class AwaitCommand < Gem::Command
9
+ include Gem::LocalRemoteOptions
10
+
11
+ def initialize
12
+ require "rubygems/await"
13
+
14
+ awaiters = Rubygems::Await::Awaiter.subclasses.each_with_object({}) { |a, h| h[a.awaiter_name] = a }
15
+ skip = ["dependency api"]
16
+ skip.push("versions", "names", "info") unless Bundler::SharedHelpers.md5_available?
17
+
18
+ defaults = {
19
+ timeout: 5 * 60,
20
+ awaiters:,
21
+ skip: ["dependency api"],
22
+ only: nil
23
+ }
24
+
25
+ super "await", "Await pushed gems being available",
26
+ defaults
27
+
28
+ accept_uri_http
29
+
30
+ add_option(:"Local/Remote", "-s", "--source URL", URI::HTTP,
31
+ "Append URL to list of remote gem sources") do |source, options|
32
+ options[:source] = source
33
+ end
34
+
35
+ add_option(:Timing, "-t", "--timeout DURATION", Integer,
36
+ "Wait for the given duration before failing") do |timeout, options|
37
+ options[:timeout] = timeout
38
+ end
39
+
40
+ add_option("--skip NAME", awaiters.keys,
41
+ "Skip the given awaiter") do |name, options|
42
+ options[:skip] ||= []
43
+ options[:skip] << name
44
+ end
45
+
46
+ add_option("--include NAME", awaiters.keys,
47
+ "Do not skip the given awaiter") do |name, options|
48
+ options[:skip] ||= []
49
+ options[:skip].delete(name)
50
+ end
51
+
52
+ add_option("--only NAME", awaiters.keys,
53
+ "Only run the given awaiter") do |name, options|
54
+ options[:only] ||= []
55
+ options[:only] << name
56
+ options[:skip]&.delete(name)
57
+ end
58
+ end
59
+
60
+ def execute
61
+ require "bundler"
62
+
63
+ unless defined?(Bundler::Thor::Shell::Color::UNDERLINE)
64
+ Bundler::Thor::Shell::Color.const_set(:UNDERLINE,
65
+ "\e[4m")
66
+ end
67
+
68
+ ui = Gem.ui
69
+
70
+ gems = options[:args].map do |s|
71
+ parts = s.split(":", 3)
72
+ raise Gem::CommandLineError, "Please specify a name:version[:platform], given #{s.inspect}" if parts.size < 2
73
+
74
+ unless Gem::Version.correct?(parts[1])
75
+ raise Gem::CommandLineError,
76
+ "Please specify a valid version, given #{s.inspect}"
77
+ end
78
+
79
+ Gem::NameTuple.new(*parts).freeze
80
+ end.freeze
81
+
82
+ raise Gem::CommandLineError, "Please specify at least one gem to await" if gems.empty?
83
+
84
+ source = options[:source] || Gem.default_sources.first
85
+
86
+ log do
87
+ "Awaiting #{gems.map { Bundler.ui.add_color(_1.full_name, :bold) }.join(", ")} on #{Bundler.ui.add_color(
88
+ Bundler::URICredentialsFilter.credential_filtered_uri(source), :underline
89
+ )}"
90
+ end
91
+
92
+ start = Time.now
93
+ @deadline = start + options[:timeout]
94
+
95
+ missing = awaiters.map { _1.call(gems, source, @deadline, name_indent) }.map!(&:value)
96
+ missing.reject!(&:empty?)
97
+
98
+ if missing.empty?
99
+ log do
100
+ Bundler.ui.add_color("Found #{gems.map do |tuple|
101
+ Bundler.ui.add_color(tuple.full_name, :bold, :white)
102
+ end.join(", ")}", :green, :bold)
103
+ end
104
+ else
105
+ all_missing = missing.flat_map do |m|
106
+ case m
107
+ when Set
108
+ m.to_a
109
+ when Hash
110
+ m.values.flat_map(&:to_a)
111
+ else
112
+ raise "Unexpected #{m.inspect}"
113
+ end
114
+ end
115
+ all_missing.uniq!
116
+ all_missing.map! { Bundler.ui.add_color(_1.respond_to?(:full_name) ? _1.full_name : _1.to_s, :red, :bold) }
117
+ log(level: "error") do
118
+ Bundler.ui.add_color("Timed out", :red) << " after " <<
119
+ Bundler.ui.add_color("#{Time.now.-(start).round(2)}s", :white, :bold) <<
120
+ ". Check that #{all_missing.join(", ")} are published."
121
+ end
122
+ terminate_interaction 1
123
+ end
124
+ ensure
125
+ Bundler.rubygems.ui = ui
126
+ end
127
+
128
+ def arguments
129
+ "GEMNAME:VERSION[:PLATFORM] name, version and (optional) platform of the gem to await"
130
+ end
131
+
132
+ def defaults_str
133
+ %(--timeout #{options[:timeout]} #{options[:skip].map { |a| "--skip #{a.dump}" }.join(" ")})
134
+ end
135
+
136
+ def description
137
+ <<~DESC
138
+ The await command will wait for pushed gems to be available on the given
139
+ source. It will wait for the given timeout, or 5 minutes by default.
140
+
141
+ The available awaiters are: #{options[:awaiters].keys.join(", ")}.
142
+ DESC
143
+ end
144
+
145
+ def usage
146
+ "#{program_name} [OPTIONS] GEMNAME:VERSION[:PLATFORM] ..."
147
+ end
148
+
149
+ private
150
+
151
+ def log(level: "info", tags: nil, &)
152
+ return unless Bundler.ui.level(level)
153
+
154
+ s = Time.now.to_s << " "
155
+ case level
156
+ when "info"
157
+ s << Bundler.ui.add_color("I", :white)
158
+ when "warn"
159
+ s << Bundler.ui.add_color("W", :yellow)
160
+ when "error"
161
+ s << Bundler.ui.add_color("E", :red)
162
+ when "debug"
163
+ s << "D"
164
+ else
165
+ raise ArgumentError, "unhandled level #{level.inspect}"
166
+ end
167
+ s << (" " * (name_indent + 4))
168
+ tags&.each do |tag|
169
+ s << Bundler.ui.add_color("[#{tag}]", :white)
170
+ s << " "
171
+ end
172
+ s << yield
173
+ Bundler.ui.info s
174
+ end
175
+
176
+ def awaiters
177
+ awaiters = options[:awaiters].values
178
+ if options
179
+ awaiters.select! { |a| options[:only].include?(a.awaiter_name) } if options[:only]
180
+ awaiters.reject! { |a| options[:skip].include?(a.awaiter_name) } if options[:skip]
181
+ end
182
+ awaiters
183
+ end
184
+
185
+ def name_indent
186
+ @name_indent ||= awaiters.map { _1.awaiter_name.size }.max || 0
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rubygems/command"
4
+ Gem::CommandManager.instance.register_command :await
@@ -0,0 +1,6 @@
1
+ module Rubygems
2
+ module Await
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems-await
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Giddins
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ description:
28
+ email:
29
+ - segiddins@segiddins.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rubocop.yml"
35
+ - CHANGELOG.md
36
+ - CODE_OF_CONDUCT.md
37
+ - LICENSE.txt
38
+ - README.md
39
+ - Rakefile
40
+ - lib/rubygems/await.rb
41
+ - lib/rubygems/await/version.rb
42
+ - lib/rubygems/commands/await_command.rb
43
+ - lib/rubygems_plugin.rb
44
+ - sig/rubygems/await.rbs
45
+ homepage: https://github.com/segiddins/rubygems-await
46
+ licenses:
47
+ - MIT
48
+ metadata:
49
+ allowed_push_host: https://rubygems.org/
50
+ homepage_uri: https://github.com/segiddins/rubygems-await
51
+ source_code_uri: https://github.com/seggidins/rubygems-await
52
+ rubygems_mfa_required: 'true'
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '3.4'
67
+ requirements: []
68
+ rubygems_version: 3.4.19
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: A RubyGems plugin with a command to wait until gems are available.
72
+ test_files: []