fastlane-plugin-wpmreleasetoolkit 6.0.0 → 6.1.0

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: c16be217cbd668e4fbd9da107edcdba4b5be149f0d64d4dadb6a0d5697cde006
4
- data.tar.gz: e736842ca7df0e1ff50fc0a7114e39555570c03c8e58b41fa265999f267f0ec2
3
+ metadata.gz: a5ccc5cff47b793af8f4ab760dae506824b97736743751874e6ffe05da49c6d6
4
+ data.tar.gz: b505f57985fa018c5845437e38b9d62a82db73252fca4990d30bf2e5b8b6455e
5
5
  SHA512:
6
- metadata.gz: 739938930d2cfd9238590f6b58b7031923f5f6b325c53246058f77dc47c7e302180f2d088b8c764106d50e45f7bca265d915a3d671bbf09c6a45e9309fcb1e3e
7
- data.tar.gz: 0741aeff083cab3060b8b4f46259ad091217eef34fd013370fca26289b5c2279c325632dd7935699772e293e81e87ffcbd71bc7b8905da5fffbb4e04543f61e5
6
+ metadata.gz: ef7e10048e6a7bd1795667f06e59ff4af01638ea2a3f47bb2742f3ea50bd1d52ae1c8b747e4fc8d2422599f216e9dc03ba334ace07f9a90dfa785630f937c9d7
7
+ data.tar.gz: 559bee78785335bcc564e04cafc52af9d5514f2d979598ce05c5837ba97b6378c70f0d919809fc6f4db5ca4e5f64db47ac90e430b058d5cd6d777ebf81cc54dc
@@ -3,8 +3,9 @@ require 'securerandom'
3
3
  module Fastlane
4
4
  module Actions
5
5
  module SharedValues
6
- FIREBASE_TEST_RESULT = :FIREBASE_TEST_LOG_FILE
6
+ FIREBASE_TEST_RESULT = :FIREBASE_TEST_LOG_FILE # FirebaseTestLabResult object, for internal consumption
7
7
  FIREBASE_TEST_LOG_FILE_PATH = :FIREBASE_TEST_LOG_FILE_PATH
8
+ FIREBASE_TEST_MORE_DETAILS_URL = :FIREBASE_TEST_MORE_DETAILS_URL
8
9
  end
9
10
 
10
11
  class AndroidFirebaseTestAction < Action
@@ -45,13 +46,20 @@ module Fastlane
45
46
  key_file_path: params[:key_file]
46
47
  )
47
48
 
48
- FastlaneCore::UI.test_failure! "Firebase Tests failed – more information can be found at #{result.more_details_url}" unless result.success?
49
+ Fastlane::Actions.lane_context[SharedValues::FIREBASE_TEST_MORE_DETAILS_URL] = result.more_details_url
49
50
 
50
- UI.success 'Firebase Tests Complete'
51
+ if result.success?
52
+ UI.success 'Firebase Tests Complete'
53
+ return true
54
+ else
55
+ ui_method = params[:crash_on_test_failure] ? :test_failure! : :error
56
+ FastlaneCore::UI.send(ui_method, "Firebase Tests failed – more information can be found at #{result.more_details_url}")
57
+ return false
58
+ end
51
59
  end
52
60
 
53
61
  # Fastlane doesn't eagerly validate options for us, so we'll do it first to have control over
54
- # when they're evalutated.
62
+ # when they're evaluated.
55
63
  def self.validate_options(params)
56
64
  available_options
57
65
  .reject { |opt| opt.optional || !opt.default_value.nil? }
@@ -180,9 +188,28 @@ module Fastlane
180
188
  optional: true,
181
189
  type: String
182
190
  ),
191
+ FastlaneCore::ConfigItem.new(
192
+ key: :crash_on_test_failure,
193
+ description: 'If set to `true` (the default), will stop fastlane with `test_failure!`. ' \
194
+ + 'If `false`, the action will return the test status, without interrupting the rest of your Fastlane run on failure, letting the caller handle the failure on their side',
195
+ optional: true,
196
+ type: Boolean,
197
+ default_value: true
198
+ ),
183
199
  ]
184
200
  end
185
201
 
202
+ def self.output
203
+ [
204
+ ['FIREBASE_TEST_LOG_FILE_PATH', 'Path to the `output.log` file containing the logs or invoking the tests'],
205
+ ['FIREBASE_TEST_MORE_DETAILS_URL', 'URL to the Firebase Console dashboard showing the details of the test run (and failures, if any)'],
206
+ ]
207
+ end
208
+
209
+ def self.return_value
210
+ 'True if the test succeeded, false if they failed'
211
+ end
212
+
186
213
  def self.authors
187
214
  ['Automattic']
188
215
  end
@@ -11,7 +11,9 @@ module Fastlane
11
11
  UI.message "#{self.check_path(params[:orig_folder])} Original Screenshot Source: #{params[:orig_folder]}"
12
12
  UI.message "#{self.check_path(params[:metadata_folder])} Translation source: #{params[:metadata_folder]}"
13
13
 
14
- config = helper.read_json(params[:config_file])
14
+ config = helper.read_config(params[:config_file])
15
+
16
+ helper.check_fonts_installed!(config: config) unless params[:skip_font_check]
15
17
 
16
18
  translationDirectories = subdirectories_for_path(params[:metadata_folder])
17
19
  imageDirectories = subdirectories_for_path(params[:orig_folder])
@@ -141,31 +143,34 @@ module Fastlane
141
143
  env_name: 'PROMOSS_ORIG',
142
144
  description: 'The directory containing the original screenshots',
143
145
  optional: false,
144
- is_string: true),
146
+ type: String),
145
147
  FastlaneCore::ConfigItem.new(key: :output_folder,
146
148
  env_name: 'PROMOSS_OUTPUT',
147
149
  description: 'The path of the folder to save the promo screenshots',
148
150
  optional: false,
149
- is_string: true),
150
-
151
+ type: String),
151
152
  FastlaneCore::ConfigItem.new(key: :metadata_folder,
152
153
  env_name: 'PROMOSS_METADATA_FOLDER',
153
154
  description: 'The directory containing the translation data',
154
155
  optional: false,
155
- is_string: true),
156
-
156
+ type: String),
157
157
  FastlaneCore::ConfigItem.new(key: :config_file,
158
158
  env_name: 'PROMOSS_CONFIG_FILE',
159
159
  description: 'The path to the file containing the promo screenshot configuration',
160
160
  optional: true,
161
- is_string: true,
161
+ type: String,
162
162
  default_value: 'screenshots.json'),
163
-
164
163
  FastlaneCore::ConfigItem.new(key: :force,
165
164
  env_name: 'PROMOSS_FORCE_CREATION',
166
165
  description: 'Overwrite existing promo screenshots without asking first?',
167
166
  optional: true,
168
- is_string: false,
167
+ type: Boolean,
168
+ default_value: false),
169
+ FastlaneCore::ConfigItem.new(key: :skip_font_check,
170
+ env_name: 'PROMOSS_SKIP_FONT_CHECK',
171
+ description: 'Skip the check verifying that needed fonts are installed and active',
172
+ optional: true,
173
+ type: Boolean,
169
174
  default_value: false),
170
175
  ]
171
176
  end
@@ -7,11 +7,11 @@ rescue LoadError
7
7
  end
8
8
  require 'json'
9
9
  require 'tempfile'
10
+ require 'open3'
10
11
  require 'optparse'
11
12
  require 'pathname'
12
13
  require 'progress_bar'
13
14
  require 'parallel'
14
- require 'jsonlint'
15
15
  require 'chroma'
16
16
  require 'securerandom'
17
17
 
@@ -32,17 +32,65 @@ module Fastlane
32
32
  UI.user_error!('`drawText` not found – install it using `brew install automattic/build-tools/drawText`.') unless system('command -v drawText')
33
33
  end
34
34
 
35
- def read_json(configFilePath)
35
+ def read_config(configFilePath)
36
36
  configFilePath = resolve_path(configFilePath)
37
37
 
38
38
  begin
39
- return JSON.parse(open(configFilePath).read)
40
- rescue
41
- linter = JsonLint::Linter.new
42
- linter.check(configFilePath)
43
- linter.display_errors
39
+ # NOTE: While JSON is a subset of YAML and thus YAML.load_file would technically cover both cases at once, in practice
40
+ # `JSON.parse` is more lenient with JSON files than `YAML.load_file` is — especially, it accepts `// comments` in the
41
+ # JSON file, despite this not being allowed in the spec — hence why we still try with `JSON.parse` for `.json` files.
42
+ return File.extname(configFilePath) == '.json' ? JSON.parse(File.read(configFilePath)) : YAML.load_file(configFilePath)
43
+ rescue StandardError => e
44
+ UI.error(e)
45
+ UI.user_error!('Invalid JSON/YAML configuration. Please lint your config file to check for syntax errors.')
46
+ end
47
+ end
44
48
 
45
- UI.user_error!('Invalid JSON configuration. See errors in log.')
49
+ # Checks that all required fonts are installed
50
+ # - Visits the JSON config to find all the stylesheets referenced in it
51
+ # - For each stylesheet, extract the first font of each `font-family` attribute found
52
+ # - Finally, for each of those fonts, check that they exist and are activated.
53
+ #
54
+ # @param [Hash] config The promo screenshots configuration, as returned by #read_config
55
+ # @raise [UserError] Raises if at least one font is missing.
56
+ #
57
+ def check_fonts_installed!(config:)
58
+ # Find all stylesheets in the config
59
+ all_stylesheets = ([config['stylesheet']] + config['entries'].flat_map do |entry|
60
+ entry['attachments']&.map { |att| att['stylesheet'] }
61
+ end).compact.uniq
62
+
63
+ # Parse the first font in each `font-family` attribute found in all found CSS files.
64
+ # Only the first in each `font-family` font list matters, as others are fallbacks we don't want to use anyway.
65
+ font_families = all_stylesheets.flat_map do |s|
66
+ File.readlines(s).flat_map do |line|
67
+ attr = line.match(/font-family: (.*);/)&.captures&.first
68
+ attr.split(',').first.strip.gsub(/'(.*)'/, '\1').gsub(/"(.*)"/, '\1') unless attr.nil?
69
+ end
70
+ end.compact.uniq
71
+
72
+ # Verify that all fonts exists and are active—using a small swift script as there's no nice CLI for that
73
+ swift_script = <<~SWIFT
74
+ import AppKit
75
+
76
+ var exitCode: Int32 = 0
77
+ for fontName in CommandLine.arguments.dropFirst() {
78
+ if NSFont(name: fontName, size: NSFont.systemFontSize) != nil {
79
+ print(" ✅ Font \\"\\(fontName)\\" found and active")
80
+ } else {
81
+ print(" ❌ Font \\"\\(fontName)\\" not found, it is either not installed or disabled. Please install it using FontBook first.")
82
+ exitCode = 1
83
+ }
84
+ }
85
+ exit(exitCode)
86
+ SWIFT
87
+
88
+ Tempfile.create(['fonts-check-', '.swift']) do |f|
89
+ f.write(swift_script)
90
+ f.close
91
+ oe, s = Open3.capture2e('/usr/bin/env', 'xcrun', 'swift', f.path, *font_families)
92
+ UI.command_output(oe)
93
+ UI.user_error!('Some fonts required by your stylesheets are missing. Please install them and try again.') unless s.success?
46
94
  end
47
95
  end
48
96
 
@@ -343,8 +391,8 @@ module Fastlane
343
391
  def open_image(path)
344
392
  path = resolve_path(path)
345
393
 
346
- Magick::Image.read(path) do
347
- self.background_color = 'transparent'
394
+ Magick::Image.read(path) do |image|
395
+ image.background_color = 'transparent'
348
396
  end.first
349
397
  end
350
398
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Wpmreleasetoolkit
3
- VERSION = '6.0.0'
3
+ VERSION = '6.1.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-wpmreleasetoolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Automattic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-17 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.3'
83
- - !ruby/object:Gem::Dependency
84
- name: jsonlint
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.3'
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.3'
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: nokogiri
99
85
  requirement: !ruby/object:Gem::Requirement