carthage_remote_cache 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 668d359528b6d3f6abf8c281b7ec00b2de532ffcab2d592dfbf7ab95cb191ccd
4
- data.tar.gz: 74bf2f1193d16661a9df78b198371fc265c83d0a7c42bd4a6a885c07d7197043
3
+ metadata.gz: db51bc926af285ff03bc266988ab005c5f7ab4e7131aec89d12a99b1d14ea0f1
4
+ data.tar.gz: 6d41c8d5b3c6b08369fe595169f53ca8c8cfbc22614726227687625efae341b4
5
5
  SHA512:
6
- metadata.gz: b9b56271263ff4cd50107f54d4faeab89f4ae15a17cb3468672af1a262c0c67e885ce5ddceb6c19966d27fe8545008062878f8984cf70689e5218b85a6e23d95
7
- data.tar.gz: d4fcc47328b5f228d3c1b2d9eac42b4066eeefd3415c9f8415613fa38986fd79d016a30577c642e630d81bf9b43cf8f2ae2ed07eb1e11f6211a437b3dc2fe8e6
6
+ metadata.gz: 2fc9aa022853786a525dc61f4bbb23f1c53ff5458b05466bdf0041ac664703118391fa1cf82671c32e39012eefa1f01f664a903b35a85142e8b18ff6ae450a1f
7
+ data.tar.gz: ce992ab16d4281d7d348e3b04ef405de51a66fb1036282ae6a17055c7a0ab958aa1c7bb6b3e24a7adad2f04c6fc727938624e493fe31b3bdd4c2474cbd1b1540
data/Dockerfile ADDED
@@ -0,0 +1,7 @@
1
+ FROM ruby:2.7.1-alpine3.12
2
+
3
+ RUN apk add --no-cache g++ make
4
+ RUN gem install carthage_remote_cache
5
+
6
+ EXPOSE 9292
7
+ CMD ["carthagerc", "server"]
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- carthage_remote_cache (0.0.9)
4
+ carthage_remote_cache (0.0.10)
5
5
  concurrent-ruby (~> 1.0.5)
6
- rack (~> 2.0.6)
6
+ rack (>= 2.0.6, < 2.3.0)
7
7
  rest-client (~> 2.0.2)
8
8
  sinatra (~> 2.0.4)
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- coderay (1.1.2)
13
+ coderay (1.1.3)
14
14
  concurrent-ruby (1.0.5)
15
15
  domain_name (0.5.20190701)
16
16
  unf (>= 0.0.5, < 1.0.0)
17
- ffi (1.11.1)
17
+ ffi (1.15.0)
18
18
  formatador (0.2.5)
19
19
  guard (2.14.2)
20
20
  formatador (>= 0.2.4)
@@ -31,70 +31,70 @@ GEM
31
31
  test-unit (~> 3.0)
32
32
  http-cookie (1.0.3)
33
33
  domain_name (~> 0.5)
34
- listen (3.1.5)
35
- rb-fsevent (~> 0.9, >= 0.9.4)
36
- rb-inotify (~> 0.9, >= 0.9.7)
37
- ruby_dep (~> 1.2)
38
- lumberjack (1.0.13)
34
+ listen (3.5.1)
35
+ rb-fsevent (~> 0.10, >= 0.10.3)
36
+ rb-inotify (~> 0.9, >= 0.9.10)
37
+ lumberjack (1.2.8)
39
38
  metaclass (0.0.4)
40
- method_source (0.9.2)
41
- mime-types (3.2.2)
39
+ method_source (1.0.0)
40
+ mime-types (3.3.1)
42
41
  mime-types-data (~> 3.2015)
43
- mime-types-data (3.2019.0331)
42
+ mime-types-data (3.2021.0225)
44
43
  mocha (1.3.0)
45
44
  metaclass (~> 0.0.1)
46
- mustermann (1.0.3)
45
+ mustermann (1.1.1)
46
+ ruby2_keywords (~> 0.0.1)
47
47
  nenv (0.3.0)
48
48
  netrc (0.11.0)
49
- notiffany (0.1.1)
49
+ notiffany (0.1.3)
50
50
  nenv (~> 0.1)
51
51
  shellany (~> 0.0)
52
- power_assert (1.1.4)
53
- pry (0.12.2)
54
- coderay (~> 1.1.0)
55
- method_source (~> 0.9.0)
56
- rack (2.0.7)
57
- rack-protection (2.0.5)
52
+ power_assert (2.0.0)
53
+ pry (0.14.1)
54
+ coderay (~> 1.1)
55
+ method_source (~> 1.0)
56
+ rack (2.2.3)
57
+ rack-protection (2.0.8.1)
58
58
  rack
59
- rake (10.5.0)
60
- rb-fsevent (0.10.3)
61
- rb-inotify (0.10.0)
59
+ rake (13.0.3)
60
+ rb-fsevent (0.11.0)
61
+ rb-inotify (0.10.1)
62
62
  ffi (~> 1.0)
63
- rerun (0.13.0)
63
+ rerun (0.13.1)
64
64
  listen (~> 3.0)
65
65
  rest-client (2.0.2)
66
66
  http-cookie (>= 1.0.2, < 2.0)
67
67
  mime-types (>= 1.16, < 4.0)
68
68
  netrc (~> 0.8)
69
- ruby_dep (1.5.0)
70
- rufo (0.5.1)
69
+ ruby2_keywords (0.0.4)
70
+ rufo (0.13.0)
71
71
  shellany (0.0.1)
72
- sinatra (2.0.5)
72
+ sinatra (2.0.8.1)
73
73
  mustermann (~> 1.0)
74
74
  rack (~> 2.0)
75
- rack-protection (= 2.0.5)
75
+ rack-protection (= 2.0.8.1)
76
76
  tilt (~> 2.0)
77
77
  test-unit (3.2.9)
78
78
  power_assert
79
- thor (0.20.3)
80
- tilt (2.0.9)
79
+ thor (1.1.0)
80
+ tilt (2.0.10)
81
81
  unf (0.1.4)
82
82
  unf_ext
83
- unf_ext (0.0.7.6)
83
+ unf_ext (0.0.7.7)
84
84
 
85
85
  PLATFORMS
86
86
  ruby
87
87
 
88
88
  DEPENDENCIES
89
- bundler (~> 1.16)
89
+ bundler
90
90
  carthage_remote_cache!
91
91
  guard (~> 2.14.2)
92
92
  guard-test (~> 2.0.8)
93
93
  mocha (~> 1.3.0)
94
- rake (~> 10.0)
94
+ rake (~> 13.0)
95
95
  rerun
96
96
  rufo
97
97
  test-unit (~> 3.2.7)
98
98
 
99
99
  BUNDLED WITH
100
- 1.16.6
100
+ 2.2.11
data/Guardfile CHANGED
@@ -1,6 +1,6 @@
1
1
  guard :test do
2
2
  watch(%r{^test/.+_tests\.rb$})
3
- watch('test/test_helper.rb') { 'test' }
4
- watch('test/fixtures.rb') { 'test' }
3
+ watch("test/test_helper.rb") { "test" }
4
+ watch("test/fixtures.rb") { "test" }
5
5
  watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_tests.rb" }
6
6
  end
data/README.md CHANGED
@@ -68,22 +68,29 @@ It is recommended to always perform the upload workflow after upgrading Xcode an
68
68
 
69
69
  ### Download Workflow
70
70
 
71
- Once cache server has been populated with framework binaries, it's time to fetch frameworks from a different machine. Make sure to pull in `Cartrcfile` from respository before executing:
71
+ Once the cache server has been populated with framework binaries, it's time to fetch frameworks from a different machine. Make sure to pull in `Cartrcfile` from the repository before executing:
72
72
 
73
73
  $ carthagerc download
74
74
 
75
- You should expect to see following output on a machine with empty `Carthage` folder:
75
+ You should expect to see the following output on a machine with empty `Carthage` folder:
76
76
 
77
77
  Downloaded and extracted 53 archives (97.2 MB), skipped 0 archives.
78
78
 
79
79
  Your project should be ready for building.
80
80
 
81
- #### Overwriting Local Carthage Folder
81
+ #### Overwrite Local Carthage Folder
82
82
 
83
83
  In case you happen to change a file in `Carthage/Build` by accident, it's possible to force download all frameworks again with:
84
84
 
85
85
  $ carthagerc download --force
86
86
 
87
+ #### Download Only Some Platforms
88
+
89
+ The example above downloaded all frameworks for all platforms (iOS, macOS, tvOS, watchOS). If large dependencies or network speed are an issue, you can download only a subset of the platforms by using the `--platform` argument:
90
+
91
+ $ carthagerc download --platform iOS,macOS,tvOS,watchOS
92
+
93
+ Please note, that invoking the `download` command multiple times with different platform arguments is not supported. The `.version` file will "forget" that `carthagerc` already downloaded the platform specified before the last download. If you need multiple platforms, specify them in a single `download` command once, delimited with a comma.
87
94
 
88
95
  ### Config
89
96
 
@@ -205,6 +212,30 @@ If you want to stop the agent, run:
205
212
 
206
213
  Check out official documentation on [Launch Agents](https://developer.apple.com/library/content/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html) for more info.
207
214
 
215
+ #### Docker
216
+
217
+ To build an image based on the latest released gem, run
218
+
219
+ $ docker build -t carthagerc .
220
+
221
+ Afterwards you can run the image in a container using
222
+
223
+ $ docker run -d --publish 9292:9292 --name carthagerc carthagerc:latest
224
+
225
+ The server will now be available on port 9292 on `localhost`. Note that the command above will cause any data added to `~/.carthagerc_server` to be written into the container layer. While this works, it's generally discouraged due to decreased performance and portability. To avoid this, you can use a volume.
226
+
227
+ $ docker run -d --publish 9292:9292 --mount "source=carthagerc,target=/root/.carthagerc_server" --name carthagerc carthagerc:latest
228
+
229
+ We also recommend adding the `--log-opt` option to limit the size of logs, e.g. `--log-opt max-size=50m`.
230
+
231
+ To inspect the logs after running, use
232
+
233
+ $ docker logs carthagerc
234
+
235
+ To stop the container, run
236
+
237
+ $ docker container stop carthagerc
238
+
208
239
  ### Version
209
240
 
210
241
  $ carthagerc version
@@ -221,7 +252,7 @@ Documentation is also available when running `carthagerc` or `carthagerc --help`
221
252
  config
222
253
  print environment information and Cartrcfile configuration
223
254
 
224
- download [-f|--force] [-v|--verbose]
255
+ download [-f|--force] [-v|--verbose] [-mPLATFORM|--platform=PLATFORM]
225
256
  fetch missing frameworks into Carthage/Build
226
257
 
227
258
  init
@@ -242,6 +273,8 @@ Documentation is also available when running `carthagerc` or `carthagerc --help`
242
273
  OPTIONS
243
274
  -f, --force Force upload/download of framework archives even if local and server .version files match
244
275
  -h, --help Show help
276
+ -m, --platform=PLATFORM Comma delimited list of platforms which should be downloaded from the server; e.g. `--platform iOS,macOS`; Supported values: iOS, macOS, tvOS, watchOS
277
+ -n, --no-retry Don't retry download or upload on network failures
245
278
  -p, --port=PORT Server application port used when starting server, default port is 9292
246
279
  -v, --verbose Show extra runtime information
247
280
 
data/Rakefile CHANGED
@@ -5,10 +5,10 @@ task :default => :spec
5
5
 
6
6
  Rake::TestTask.new do |t|
7
7
  t.libs << "test"
8
- t.test_files = FileList['test/*_tests.rb']
8
+ t.test_files = FileList["test/*_tests.rb"]
9
9
  t.verbose = true
10
10
  end
11
11
 
12
12
  task :format do
13
- system('rufo bin/carthagerc lib test Gemfile Guardfile Rakefile carthage_remote_cache.gemspec')
13
+ system("bundle exec rufo bin/carthagerc lib test Gemfile Guardfile Rakefile carthage_remote_cache.gemspec")
14
14
  end
data/bin/carthagerc CHANGED
@@ -2,13 +2,15 @@
2
2
 
3
3
  $LOAD_PATH.push File.expand_path("../../lib", __FILE__)
4
4
 
5
- require 'optparse'
6
- require 'carthage_remote_cache'
7
- require 'commands'
5
+ require "optparse"
6
+ require "carthage_remote_cache"
7
+ require "commands"
8
8
 
9
- ARGV << '-h' if ARGV.empty?
9
+ ARGV << "-h" if ARGV.empty?
10
+ command = ARGV[0]
10
11
  options = {
11
12
  :force => false,
13
+ :is_retry_enabled => true,
12
14
  :server_port => SERVER_DEFAULT_PORT,
13
15
  :verbose => false,
14
16
  }
@@ -30,7 +32,7 @@ opt_parser = OptionParser.new do |opt|
30
32
  opt.separator " config"
31
33
  opt.separator " print environment information and #{CARTRCFILE} configuration"
32
34
  opt.separator ""
33
- opt.separator " download [-f|--force] [-v|--verbose]"
35
+ opt.separator " download [-f|--force] [-v|--verbose] [-mPLATFORM|--platform=PLATFORM]"
34
36
  opt.separator " fetch missing frameworks into Carthage/Build"
35
37
  opt.separator ""
36
38
  opt.separator " init"
@@ -59,6 +61,15 @@ opt_parser = OptionParser.new do |opt|
59
61
  exit
60
62
  end
61
63
 
64
+ opt.on("-m", "--platform=PLATFORM", "Comma delimited list of platforms which should be downloaded from the server; e.g. `--platform iOS,macOS`; Supported values: #{PLATFORMS.map(&:to_s).join(", ")}") do |platform|
65
+ raise AppError.new("[-p|--platform] is only supported for the 'download' command") if command != "download"
66
+ options[:platforms] = platform_to_symbols(platform)
67
+ end
68
+
69
+ opt.on("-n", "--no-retry", "Don't retry download or upload on network failures") do
70
+ options[:is_retry_enabled] = false
71
+ end
72
+
62
73
  opt.on("-pPORT", "--port=PORT", "Server application port used when starting server, default port is #{SERVER_DEFAULT_PORT}") do |port|
63
74
  options[:server_port] = port
64
75
  end
@@ -68,10 +79,9 @@ opt_parser = OptionParser.new do |opt|
68
79
  end
69
80
  end
70
81
 
71
- opt_parser.parse!
72
-
73
82
  begin
74
- command = ARGV[0]
83
+ opt_parser.parse!
84
+
75
85
  case command
76
86
  when "config"
77
87
  puts Configuration.new_with_defaults
@@ -20,17 +20,17 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.16"
23
+ spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "guard", "~> 2.14.2"
25
25
  spec.add_development_dependency "guard-test", "~> 2.0.8"
26
26
  spec.add_development_dependency "mocha", "~> 1.3.0"
27
- spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
28
  spec.add_development_dependency "rerun"
29
29
  spec.add_development_dependency "rufo"
30
30
  spec.add_development_dependency "test-unit", "~> 3.2.7"
31
31
 
32
32
  spec.add_runtime_dependency "concurrent-ruby", "~> 1.0.5"
33
- spec.add_runtime_dependency "rack", "~> 2.0.6"
33
+ spec.add_runtime_dependency "rack", ">= 2.0.6", "< 2.3.0"
34
34
  spec.add_runtime_dependency "rest-client", "~> 2.0.2"
35
35
  spec.add_runtime_dependency "sinatra", "~> 2.0.4"
36
36
  end
data/dev/start_server CHANGED
@@ -3,6 +3,6 @@
3
3
  DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4
4
  pushd "$DIR/../lib/server"
5
5
 
6
- rerun --no-notify rackup
6
+ bundle exec rerun --no-notify rackup
7
7
 
8
8
  popd
data/lib/api.rb CHANGED
@@ -23,7 +23,7 @@ class API
23
23
  rescue VersionFileDoesNotExistError => e
24
24
  errors << OutdatedFrameworkBuildError.new(
25
25
  carthage_dependency.guessed_framework_basename,
26
- '-',
26
+ "-",
27
27
  carthage_dependency.version
28
28
  )
29
29
  rescue OutdatedFrameworkBuildError => e
@@ -35,11 +35,11 @@ class API
35
35
  end
36
36
  end
37
37
 
38
- def version_file_matches_server?(carthage_dependency, version_file)
38
+ def version_file_matches_server?(carthage_dependency, version_file, platforms)
39
39
  if @options[:force]
40
40
  false
41
41
  else
42
- server_version_file = @networking.download_version_file(carthage_dependency)
42
+ server_version_file = @networking.download_version_file(carthage_dependency, platforms)
43
43
  result = version_file.same_content?(server_version_file)
44
44
  server_version_file.remove unless server_version_file.nil?
45
45
  result
@@ -1,4 +1,4 @@
1
- require 'fileutils'
1
+ require "fileutils"
2
2
 
3
3
  class CarthageArchive
4
4
  attr_reader :archive_filename, :archive_path
@@ -1,17 +1,17 @@
1
1
  lib = File.expand_path("..", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
- require 'api'
5
- require 'carthage_archive'
6
- require 'carthage_dependency'
7
- require 'constants'
8
- require 'configuration'
9
- require 'crc32'
10
- require 'errors'
11
- require 'log'
12
- require 'networking'
13
- require 'shell_wrapper'
14
- require 'table'
15
- require 'utils'
16
- require 'version'
17
- require 'version_file'
4
+ require "api"
5
+ require "carthage_archive"
6
+ require "carthage_dependency"
7
+ require "constants"
8
+ require "configuration"
9
+ require "crc32"
10
+ require "errors"
11
+ require "log"
12
+ require "networking"
13
+ require "shell_wrapper"
14
+ require "table"
15
+ require "utils"
16
+ require "version"
17
+ require "version_file"
data/lib/commands.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  lib = File.expand_path("..", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
- require 'commands/download_command'
5
- require 'commands/init_command'
6
- require 'commands/server_command'
7
- require 'commands/upload_command'
8
- require 'commands/verify_command'
4
+ require "commands/download_command"
5
+ require "commands/init_command"
6
+ require "commands/server_command"
7
+ require "commands/upload_command"
8
+ require "commands/verify_command"
@@ -1,16 +1,17 @@
1
- require 'concurrent'
1
+ require "concurrent"
2
2
 
3
3
  class DownloadCommand
4
4
  def self.new_with_defaults(options)
5
5
  shell = ShellWrapper.new
6
6
  config = Configuration.new(shell)
7
- networking = Networking.new(config)
7
+ networking = Networking.new(config, options[:is_retry_enabled])
8
8
  api = API.new(shell, config, networking, options)
9
9
 
10
10
  DownloadCommand.new(
11
11
  config: config,
12
12
  networking: networking,
13
13
  api: api,
14
+ platforms: options[:platforms],
14
15
  )
15
16
  end
16
17
 
@@ -18,6 +19,7 @@ class DownloadCommand
18
19
  @config = args[:config]
19
20
  @networking = args[:networking]
20
21
  @api = args[:api]
22
+ @platforms = args[:platforms]
21
23
  end
22
24
 
23
25
  def run
@@ -57,14 +59,13 @@ class DownloadCommand
57
59
  private
58
60
 
59
61
  def download(carthage_dependency)
60
- local_version_file =
61
- if File.exist?(carthage_dependency.version_filepath)
62
+ local_version_file = if File.exist?(carthage_dependency.version_filepath)
62
63
  carthage_dependency.new_version_file
63
64
  else
64
65
  nil
65
66
  end
66
67
 
67
- if !local_version_file.nil? && @api.version_file_matches_server?(carthage_dependency, local_version_file)
68
+ if !local_version_file.nil? && @api.version_file_matches_server?(carthage_dependency, local_version_file, @platforms)
68
69
  $LOG.debug("Version file #{local_version_file.path} matches server version, skipping download")
69
70
  @mutex.synchronize do
70
71
  @number_of_skipped_archives += local_version_file.number_of_frameworks
@@ -72,7 +73,7 @@ class DownloadCommand
72
73
  return
73
74
  end
74
75
 
75
- version_file = @networking.download_version_file(carthage_dependency)
76
+ version_file = @networking.download_version_file(carthage_dependency, @platforms)
76
77
  raise AppError.new, "Version file #{carthage_dependency.version_filename} is not present on the server, please run `carthagerc upload` first" if version_file.nil?
77
78
 
78
79
  version_file.frameworks_by_platform.each do |platform, framework_names|
@@ -4,8 +4,8 @@ class ServerCommand
4
4
  end
5
5
 
6
6
  def run
7
- ENV['RACK_ENV'] = 'production'
8
- require 'server/server_app'
7
+ ENV["RACK_ENV"] = "production"
8
+ require "server/server_app"
9
9
  Rack::Handler::WEBrick.run(
10
10
  Sinatra::Application,
11
11
  :Port => @options[:server_port],
@@ -1,10 +1,10 @@
1
- require 'concurrent'
1
+ require "concurrent"
2
2
 
3
3
  class UploadCommand
4
4
  def self.new_with_defaults(options)
5
5
  shell = ShellWrapper.new
6
6
  config = Configuration.new(shell)
7
- networking = Networking.new(config)
7
+ networking = Networking.new(config, options[:is_retry_enabled])
8
8
  api = API.new(shell, config, networking, options)
9
9
 
10
10
  UploadCommand.new(
@@ -62,7 +62,7 @@ class UploadCommand
62
62
  def upload(carthage_dependency)
63
63
  version_file = carthage_dependency.new_version_file
64
64
 
65
- if @api.version_file_matches_server?(carthage_dependency, version_file)
65
+ if @api.version_file_matches_server?(carthage_dependency, version_file, nil)
66
66
  $LOG.debug("Version file #{version_file.path} matches server version, skipping upload")
67
67
  @mutex.synchronize do
68
68
  @number_of_skipped_archives += version_file.number_of_frameworks
@@ -2,7 +2,7 @@ class VerifyCommand
2
2
  def self.new_with_defaults(options)
3
3
  shell = ShellWrapper.new
4
4
  config = Configuration.new(shell)
5
- networking = Networking.new(config)
5
+ networking = Networking.new(config, options[:is_retry_enabled])
6
6
  api = API.new(shell, config, networking, options)
7
7
 
8
8
  VerifyCommand.new(api: api)
data/lib/configuration.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'uri'
1
+ require "uri"
2
2
 
3
3
  class Configuration
4
4
  class UserConfig
data/lib/constants.rb CHANGED
@@ -1,12 +1,14 @@
1
- CARTHAGE_DIR = 'Carthage'
2
- CARTHAGE_BUILD_DIR = File.join(CARTHAGE_DIR, 'Build')
3
- CARTFILE_RESOLVED = 'Cartfile.resolved'
4
- CARTRCFILE = 'Cartrcfile'
1
+ CARTHAGE_DIR = "Carthage"
2
+ CARTHAGE_BUILD_DIR = File.join(CARTHAGE_DIR, "Build")
3
+ CARTFILE_RESOLVED = "Cartfile.resolved"
4
+ CARTRCFILE = "Cartrcfile"
5
5
  THREAD_POOL_SIZE = 8
6
6
 
7
7
  SERVER_DEFAULT_PORT = 9292
8
- SERVER_CACHE_DIR = File.join(Dir.home, '.carthagerc_server')
8
+ SERVER_CACHE_DIR = File.join(Dir.home, ".carthagerc_server")
9
9
 
10
10
  ARCHIVE_CHECKSUM_HEADER_REST_CLIENT = :archive_checksum
11
- ARCHIVE_CHECKSUM_HEADER_SINATRA_IN = 'HTTP_ARCHIVE_CHECKSUM'
12
- ARCHIVE_CHECKSUM_HEADER_SINATRA_OUT = 'Archive-Checksum'
11
+ ARCHIVE_CHECKSUM_HEADER_SINATRA_IN = "HTTP_ARCHIVE_CHECKSUM"
12
+ ARCHIVE_CHECKSUM_HEADER_SINATRA_OUT = "Archive-Checksum"
13
+
14
+ PLATFORMS = [:iOS, :macOS, :tvOS, :watchOS]
data/lib/crc32.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'digest'
2
- require 'zlib'
1
+ require "digest"
2
+ require "zlib"
3
3
 
4
4
  class Digest::CRC32 < Digest::Class
5
5
  include Digest::Instance
@@ -17,6 +17,6 @@ class Digest::CRC32 < Digest::Class
17
17
  end
18
18
 
19
19
  def finish
20
- [@crc32].pack('N')
20
+ [@crc32].pack("N")
21
21
  end
22
22
  end
data/lib/errors.rb CHANGED
@@ -51,7 +51,7 @@ class FrameworkValidationError < AppError
51
51
  end
52
52
 
53
53
  def to_s
54
- header = ['Framework', CARTHAGE_BUILD_DIR, CARTFILE_RESOLVED]
54
+ header = ["Framework", CARTHAGE_BUILD_DIR, CARTFILE_RESOLVED]
55
55
  rows = @errors.map { |e| [e.framework_name, e.build_version, e.cartfile_resolved_version] }
56
56
  table = Table.new(header, rows)
57
57
  <<~EOS
@@ -69,3 +69,14 @@ end
69
69
  class MissingFrameworkDirectoryError < AppError; end
70
70
 
71
71
  class ServerVersionMismatchError < AppError; end
72
+
73
+ class PlatformMismatchError < AppError
74
+ def initialize(platform)
75
+ @platform = platform
76
+ end
77
+
78
+ def to_s
79
+ platforms = PLATFORMS.map(&:to_s).join(", ")
80
+ "Platform '#{@platform}' doesn't match any of: #{platforms}"
81
+ end
82
+ end
data/lib/log.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'logger'
1
+ require "logger"
2
2
 
3
3
  $LOG = Logger.new(STDOUT)
4
4
  $LOG.level = Logger::INFO
data/lib/networking.rb CHANGED
@@ -1,9 +1,10 @@
1
- require 'rest-client'
2
- require 'uri'
1
+ require "rest-client"
2
+ require "uri"
3
3
 
4
4
  class Networking
5
- def initialize(config)
5
+ def initialize(config, is_retry_enabled)
6
6
  @config = config
7
+ @is_retry_enabled = is_retry_enabled
7
8
  end
8
9
 
9
10
  # Version
@@ -11,11 +12,13 @@ class Networking
11
12
  def get_server_version
12
13
  url = new_version_url
13
14
  $LOG.debug("Fetching server version from #{url}")
14
- server_version = RestClient.get(url) do |response, request, result|
15
- if response.code == 200
16
- response.strip
17
- else
18
- raise AppError.new, "Failed to read server version from #{url}, response:\n #{response[0...300]}"
15
+ server_version = perform_network_request do
16
+ RestClient.get(url) do |response, request, result|
17
+ if response.code == 200
18
+ response.strip
19
+ else
20
+ raise AppError.new, "Failed to read server version from #{url}, response:\n #{response[0...300]}"
21
+ end
19
22
  end
20
23
  end
21
24
  server_version
@@ -24,15 +27,22 @@ class Networking
24
27
  # Version Files
25
28
 
26
29
  # @return VersionFile or nil
27
- def download_version_file(carthage_dependency)
30
+ def download_version_file(carthage_dependency, platforms)
28
31
  url = new_version_file_url(carthage_dependency)
29
- $LOG.debug("Downloading version file from #{url}")
30
- version_file = RestClient.get(url) do |response, request, result|
31
- if response.code == 200
32
- File.write(carthage_dependency.version_filename, response.to_s)
33
- VersionFile.new(carthage_dependency.version_filename)
34
- else
35
- nil
32
+ params = {}
33
+ unless platforms.nil?
34
+ params[:platform] = platforms.map(&:to_s).join(",")
35
+ end
36
+
37
+ version_file = perform_network_request do
38
+ $LOG.debug("Downloading version file from #{url}, params: #{params}")
39
+ RestClient.get(url, { params: params }) do |response, request, result|
40
+ if response.code == 200
41
+ File.write(carthage_dependency.version_filename, response.to_s)
42
+ VersionFile.new(carthage_dependency.version_filename)
43
+ else
44
+ nil
45
+ end
36
46
  end
37
47
  end
38
48
  version_file
@@ -41,10 +51,12 @@ class Networking
41
51
  # @raise AppError on upload failure
42
52
  def upload_version_file(carthage_dependency)
43
53
  url = new_version_file_url(carthage_dependency)
44
- $LOG.debug("Uploading #{carthage_dependency.version_filename}")
45
- RestClient.post(url, :version_file => File.new(carthage_dependency.version_filepath)) do |response, request, result|
46
- unless response.code == 200
47
- raise AppError.new, "Version file upload #{carthage_dependency.version_filename} failed, response:\n #{response[0..300]}"
54
+ perform_network_request do
55
+ $LOG.debug("Uploading #{carthage_dependency.version_filename}")
56
+ RestClient.post(url, :version_file => File.new(carthage_dependency.version_filepath)) do |response, request, result|
57
+ unless response.code == 200
58
+ raise AppError.new, "Version file upload #{carthage_dependency.version_filename} failed, response:\n #{response[0..300]}"
59
+ end
48
60
  end
49
61
  end
50
62
  end
@@ -54,14 +66,16 @@ class Networking
54
66
  # @return Hash with CarthageArchive and checksum or nil
55
67
  def download_framework_archive(carthage_dependency, framework_name, platform)
56
68
  url = new_framework_url(carthage_dependency, framework_name, platform)
57
- $LOG.debug("Downloading framework from #{url}")
58
- archive = RestClient.get(url) do |response, request, result|
59
- if response.code == 200
60
- archive = CarthageArchive.new(framework_name, platform)
61
- File.write(archive.archive_path, response.to_s)
62
- {:archive => archive, :checksum => response.headers[ARCHIVE_CHECKSUM_HEADER_REST_CLIENT]}
63
- else
64
- nil
69
+ archive = perform_network_request do
70
+ $LOG.debug("Downloading framework from #{url}")
71
+ RestClient.get(url) do |response, request, result|
72
+ if response.code == 200
73
+ archive = CarthageArchive.new(framework_name, platform)
74
+ File.write(archive.archive_path, response.to_s)
75
+ { :archive => archive, :checksum => response.headers[ARCHIVE_CHECKSUM_HEADER_REST_CLIENT] }
76
+ else
77
+ nil
78
+ end
65
79
  end
66
80
  end
67
81
  archive
@@ -70,12 +84,14 @@ class Networking
70
84
  # @raise AppError when upload fails
71
85
  def upload_framework_archive(zipfile_name, carthage_dependency, framework_name, platform, checksum)
72
86
  url = new_framework_url(carthage_dependency, framework_name, platform)
73
- params = {:framework_file => File.new(zipfile_name)}
74
- headers = {ARCHIVE_CHECKSUM_HEADER_REST_CLIENT => checksum}
75
- $LOG.debug("Uploading framework to #{url}, headers: #{headers}")
76
- RestClient.post(url, params, headers) do |response, request, result|
77
- unless response.code == 200
78
- raise AppError.new, "Framework upload #{zipfile_name} failed, response:\n #{response[0..300]}"
87
+ params = { :framework_file => File.new(zipfile_name) }
88
+ headers = { ARCHIVE_CHECKSUM_HEADER_REST_CLIENT => checksum }
89
+ perform_network_request do
90
+ $LOG.debug("Uploading framework to #{url}, headers: #{headers}")
91
+ RestClient.post(url, params, headers) do |response, request, result|
92
+ unless response.code == 200
93
+ raise AppError.new, "Framework upload #{zipfile_name} failed, response:\n #{response[0..300]}"
94
+ end
79
95
  end
80
96
  end
81
97
  end
@@ -83,12 +99,12 @@ class Networking
83
99
  private
84
100
 
85
101
  def new_version_url
86
- new_server_url(['version'])
102
+ new_server_url(["version"])
87
103
  end
88
104
 
89
105
  def new_version_file_url(carthage_dependency)
90
106
  new_server_url([
91
- 'versions',
107
+ "versions",
92
108
  @config.xcodebuild_version,
93
109
  @config.swift_version,
94
110
  carthage_dependency.guessed_framework_basename,
@@ -99,7 +115,7 @@ class Networking
99
115
 
100
116
  def new_framework_url(carthage_dependency, framework_name, platform)
101
117
  new_server_url([
102
- 'frameworks',
118
+ "frameworks",
103
119
  @config.xcodebuild_version,
104
120
  @config.swift_version,
105
121
  carthage_dependency.guessed_framework_basename,
@@ -115,13 +131,37 @@ class Networking
115
131
  :scheme => @config.server_uri.scheme,
116
132
  :host => @config.server_uri.host,
117
133
  :port => @config.server_uri.port,
118
- :path => '/' + sanitized_path_slices.join('/'),
134
+ :path => "/" + sanitized_path_slices.join("/"),
119
135
  )
120
136
  uri.to_s
121
137
  end
122
138
 
123
139
  # Mangle identifiers for URL paths.
124
140
  def sanitized(input)
125
- input.gsub(/\//, '_')
141
+ input.gsub(/\//, "_")
142
+ end
143
+
144
+ def perform_network_request
145
+ if @is_retry_enabled
146
+ retries_remaining = 3
147
+ sleep_time_seconds = 5
148
+ begin
149
+ result = yield
150
+ rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
151
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
152
+ if retries_remaining > 0
153
+ $LOG.warn("Network request failed - remaining retries: #{retries_remaining}, sleeping for: #{sleep_time_seconds}s, error: #{e.message}")
154
+ sleep(sleep_time_seconds)
155
+ retries_remaining -= 1
156
+ sleep_time_seconds *= 3
157
+ retry
158
+ else
159
+ raise e
160
+ end
161
+ end
162
+ result
163
+ else
164
+ yield
165
+ end
126
166
  end
127
167
  end
data/lib/server/config.ru CHANGED
@@ -1,6 +1,6 @@
1
- require 'rubygems'
2
- require 'bundler'
1
+ require "rubygems"
2
+ require "bundler"
3
3
  Bundler.require
4
4
 
5
- require './server_app.rb'
5
+ require "./server_app.rb"
6
6
  run Sinatra::Application
@@ -1,14 +1,15 @@
1
- require 'sinatra'
2
- require 'fileutils'
3
- require 'carthage_remote_cache'
1
+ require "json"
2
+ require "sinatra"
3
+ require "fileutils"
4
+ require "carthage_remote_cache"
4
5
 
5
- get '/' do
6
+ get "/" do
6
7
  "Welcome to carthage_remote_cache"
7
8
  end
8
9
 
9
- version_path = '/version'
10
- versions_path = '/versions/:xcodebuild_version/:swift_version/:dependency_name/:version/:version_filename'
11
- frameworks_path = '/frameworks/:xcodebuild_version/:swift_version/:dependency_name/:version/:framework_name/:platform'
10
+ version_path = "/version"
11
+ versions_path = "/versions/:xcodebuild_version/:swift_version/:dependency_name/:version/:version_filename"
12
+ frameworks_path = "/frameworks/:xcodebuild_version/:swift_version/:dependency_name/:version/:framework_name/:platform"
12
13
 
13
14
  get version_path do
14
15
  status(200)
@@ -16,13 +17,25 @@ get version_path do
16
17
  end
17
18
 
18
19
  get versions_path do
20
+ if params.key?(:platform)
21
+ begin
22
+ platforms = platform_to_symbols(params[:platform])
23
+ rescue AppError => e
24
+ status(400)
25
+ return JSON.pretty_generate({ "error" => e.message })
26
+ end
27
+ else
28
+ platforms = PLATFORMS
29
+ end
30
+
19
31
  dirname = params_to_framework_dir(params)
20
32
  filename = params[:version_filename]
21
33
  filepath = File.join(dirname, filename)
22
34
 
23
35
  if File.exist?(filepath)
24
36
  status(200)
25
- send_file(filepath)
37
+ version_file = VersionFile.new(filepath, platforms)
38
+ JSON.pretty_generate(version_file.json)
26
39
  else
27
40
  status(404)
28
41
  end
@@ -39,7 +52,7 @@ post versions_path do
39
52
  File.delete(target_filename) if File.exist?(target_filename)
40
53
 
41
54
  $LOG.info("Writing: #{target_filename}")
42
- File.open(target_filename, 'wb') do |target_file|
55
+ File.open(target_filename, "wb") do |target_file|
43
56
  target_file.write(source_file.read)
44
57
  end
45
58
 
@@ -75,7 +88,7 @@ post frameworks_path do
75
88
  File.delete(target_filename) if File.exist?(target_filename)
76
89
 
77
90
  $LOG.info("Writing: #{target_filename}")
78
- File.open(target_filename, 'wb') do |target_file|
91
+ File.open(target_filename, "wb") do |target_file|
79
92
  target_file.write(source_file.read)
80
93
  end
81
94
 
data/lib/shell_wrapper.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'open3'
1
+ require "open3"
2
2
 
3
3
  class ShellWrapper
4
4
  # @return
data/lib/table.rb CHANGED
@@ -32,8 +32,8 @@ class Table
32
32
  end
33
33
 
34
34
  def separator_line
35
- dashes = @column_sizes.map { |size| '-' * size }
36
- '+' + dashes.join('+') + '+'
35
+ dashes = @column_sizes.map { |size| "-" * size }
36
+ "+" + dashes.join("+") + "+"
37
37
  end
38
38
 
39
39
  def header_line
@@ -41,7 +41,7 @@ class Table
41
41
  column_size = @column_sizes[index] - 1
42
42
  " %-#{column_size}.#{column_size}s" % column
43
43
  end
44
- '|' + columns.join('|') + '|'
44
+ "|" + columns.join("|") + "|"
45
45
  end
46
46
 
47
47
  def row_line(row)
@@ -53,6 +53,6 @@ class Table
53
53
  "%#{column_size}.#{column_size}s " % column
54
54
  end
55
55
  end
56
- '|' + columns.join('|') + '|'
56
+ "|" + columns.join("|") + "|"
57
57
  end
58
58
  end
data/lib/utils.rb CHANGED
@@ -15,7 +15,7 @@ end
15
15
  def quote(input)
16
16
  if input.is_a? String
17
17
  if input.empty?
18
- ''
18
+ ""
19
19
  else
20
20
  '"' + input + '"'
21
21
  end
@@ -23,7 +23,7 @@ def quote(input)
23
23
  input
24
24
  .map { |e| quote(e) }
25
25
  .select { |e| !e.empty? }
26
- .join(' ')
26
+ .join(" ")
27
27
  else
28
28
  raise AppError.new, "Unsupported type #{input}"
29
29
  end
@@ -32,13 +32,13 @@ end
32
32
  def platform_to_api_string(platform)
33
33
  case platform
34
34
  when :iOS
35
- 'iOS'
35
+ "iOS"
36
36
  when :macOS
37
- 'macOS'
37
+ "macOS"
38
38
  when :tvOS
39
- 'tvOS'
39
+ "tvOS"
40
40
  when :watchOS
41
- 'watchOS'
41
+ "watchOS"
42
42
  else
43
43
  raise AppError.new, "Unrecognized platform #{platform.inspect}"
44
44
  end
@@ -47,18 +47,28 @@ end
47
47
  def platform_to_carthage_dir_string(platform)
48
48
  case platform
49
49
  when :iOS
50
- 'iOS'
50
+ "iOS"
51
51
  when :macOS
52
- 'Mac'
52
+ "Mac"
53
53
  when :tvOS
54
- 'tvOS'
54
+ "tvOS"
55
55
  when :watchOS
56
- 'watchOS'
56
+ "watchOS"
57
57
  else
58
58
  raise AppError.new, "Unrecognized platform #{platform.inspect}"
59
59
  end
60
60
  end
61
61
 
62
+ def platform_to_symbols(string)
63
+ platforms = string.split(",").map(&:to_sym)
64
+ for platform in platforms
65
+ if !PLATFORMS.include?(platform)
66
+ raise PlatformMismatchError.new(platform)
67
+ end
68
+ end
69
+ platforms
70
+ end
71
+
62
72
  # @return string in "x.y MB" format
63
73
  def format_file_size(bytes)
64
74
  megabytes = bytes / 1000.0 / 1000.0
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- VERSION = '0.0.9'
1
+ VERSION = "0.0.10"
data/lib/version_file.rb CHANGED
@@ -1,13 +1,14 @@
1
- require 'json'
2
- require 'fileutils'
1
+ require "json"
2
+ require "fileutils"
3
3
 
4
4
  # .version file representation, see Carthage documentation on them:
5
5
  # https://github.com/Carthage/Carthage/blob/master/Documentation/VersionFile.md
6
6
  class VersionFile
7
- attr_reader :path, :version, :frameworks_by_platform
7
+ attr_reader :path, :platforms, :json, :version, :frameworks_by_platform
8
8
 
9
- def initialize(path)
9
+ def initialize(path, platforms = PLATFORMS)
10
10
  @path = path
11
+ @platforms = platforms
11
12
  parse
12
13
  end
13
14
 
@@ -55,7 +56,7 @@ class VersionFile
55
56
  if other_version_file.nil?
56
57
  false
57
58
  else
58
- FileUtils.compare_file(@path, other_version_file.path)
59
+ @json == other_version_file.json
59
60
  end
60
61
  end
61
62
 
@@ -64,23 +65,36 @@ class VersionFile
64
65
  def parse
65
66
  raise VersionFileDoesNotExistError.new, "File #{path} doesn't exist, has carthage been bootstrapped?" unless File.exist?(@path)
66
67
 
68
+ @json = read_json
69
+
70
+ @version = @json["commitish"]
71
+ raise AppError.new, "Version is missing in #{@path}:\n\n#{@json}" if @version.nil? || @version.empty?
72
+
73
+ @frameworks_by_platform = PLATFORMS.to_h { |platform| [platform, parse_platform(platform)] }
74
+ end
75
+
76
+ # Reads json from `@path` and cleans up entries, tha are not defined in `@platforms`.
77
+ def read_json
67
78
  file = File.read(@path)
68
79
  json = JSON.parse(file)
80
+ stripped_json = strip_platforms(json)
81
+ stripped_json
82
+ end
69
83
 
70
- @version = json['commitish']
71
- raise AppError.new, "Version is missing in #{@path}" if @version.nil? || @version.empty?
72
-
73
- @frameworks_by_platform = {
74
- :iOS => parse_platform_array(json['iOS']),
75
- :macOS => parse_platform_array(json['Mac']),
76
- :tvOS => parse_platform_array(json['tvOS']),
77
- :watchOS => parse_platform_array(json['watchOS']),
78
- }
84
+ def strip_platforms(json)
85
+ for platform in PLATFORMS
86
+ if !@platforms.include?(platform)
87
+ json[platform_to_carthage_dir_string(platform)] = []
88
+ end
89
+ end
90
+ json
79
91
  end
80
92
 
81
- def parse_platform_array(array)
93
+ def parse_platform(platform)
94
+ carthage_platform_name = platform_to_carthage_dir_string(platform)
95
+ array = @json[carthage_platform_name]
82
96
  if array.kind_of?(Array)
83
- array.map { |entry| entry['name'] }
97
+ array.map { |entry| entry["name"] }
84
98
  else
85
99
  []
86
100
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carthage_remote_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juraj Blahunka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-10 00:00:00.000000000 Z
11
+ date: 2021-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.16'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: guard
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '13.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '10.0'
82
+ version: '13.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rerun
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +140,22 @@ dependencies:
140
140
  name: rack
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
145
  version: 2.0.6
146
+ - - "<"
147
+ - !ruby/object:Gem::Version
148
+ version: 2.3.0
146
149
  type: :runtime
147
150
  prerelease: false
148
151
  version_requirements: !ruby/object:Gem::Requirement
149
152
  requirements:
150
- - - "~>"
153
+ - - ">="
151
154
  - !ruby/object:Gem::Version
152
155
  version: 2.0.6
156
+ - - "<"
157
+ - !ruby/object:Gem::Version
158
+ version: 2.3.0
153
159
  - !ruby/object:Gem::Dependency
154
160
  name: rest-client
155
161
  requirement: !ruby/object:Gem::Requirement
@@ -189,6 +195,7 @@ extra_rdoc_files: []
189
195
  files:
190
196
  - ".gitignore"
191
197
  - ".travis.yml"
198
+ - Dockerfile
192
199
  - Gemfile
193
200
  - Gemfile.lock
194
201
  - Guardfile
@@ -227,7 +234,7 @@ homepage: https://github.com/kayak/carthage_remote_cache
227
234
  licenses:
228
235
  - Apache-2.0
229
236
  metadata: {}
230
- post_install_message:
237
+ post_install_message:
231
238
  rdoc_options: []
232
239
  require_paths:
233
240
  - lib
@@ -242,9 +249,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
249
  - !ruby/object:Gem::Version
243
250
  version: '0'
244
251
  requirements: []
245
- rubyforge_project:
246
- rubygems_version: 2.7.9
247
- signing_key:
252
+ rubygems_version: 3.2.4
253
+ signing_key:
248
254
  specification_version: 4
249
255
  summary: Centralized cache to serve carthage frameworks. Useful for distributed CI
250
256
  setup with several build machines.