File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
lib/fastlane/plugin/wpmreleasetoolkit/actions/common Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,15 @@ def self.run(params)
20
20
key = [ file_name_hash , key ] . join ( '/' )
21
21
end
22
22
23
- UI . user_error! ( "File already exists in S3 bucket #{ bucket } at #{ key } " ) if file_is_already_uploaded? ( bucket , key )
23
+ if file_is_already_uploaded? ( bucket , key )
24
+ message = "File already exists in S3 bucket #{ bucket } at #{ key } "
25
+ if params [ :skip_if_exists ]
26
+ UI . important ( "#{ message } . Skipping upload." )
27
+ else
28
+ UI . user_error! ( message )
29
+ end
30
+ return
31
+ end
24
32
25
33
UI . message ( "Uploading #{ file_path } to: #{ key } " )
26
34
@@ -101,6 +109,13 @@ def self.available_options
101
109
default_value : true ,
102
110
type : Boolean
103
111
) ,
112
+ FastlaneCore ::ConfigItem . new (
113
+ key : :skip_if_exists ,
114
+ description : 'If the file already exists in the S3 bucket, just log the error instead of failing with `user_error!`' ,
115
+ optional : true ,
116
+ default_value : false ,
117
+ type : Boolean
118
+ ) ,
104
119
]
105
120
end
106
121
Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ def stub_s3_response_for_file(key, exists: true)
144
144
end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , 'Path `this-file-does-not-exist.txt` does not exist.' )
145
145
end
146
146
147
- it 'fails if the file already exists on S3' do
147
+ it 'fails if the file already exists on S3 and skip_if_exists:false ' do
148
148
expected_key = 'a62f2225bf70bfaccbc7f1ef2a397836717377de/key'
149
149
stub_s3_response_for_file ( expected_key )
150
150
@@ -158,5 +158,23 @@ def stub_s3_response_for_file(key, exists: true)
158
158
end . to raise_error ( FastlaneCore ::Interface ::FastlaneError , "File already exists in S3 bucket #{ test_bucket } at #{ expected_key } " )
159
159
end
160
160
end
161
+
162
+ it 'just logs if the file already exists on S3 and skip_if_exists:true' do
163
+ expected_key = 'a62f2225bf70bfaccbc7f1ef2a397836717377de/key'
164
+ stub_s3_response_for_file ( expected_key )
165
+
166
+ warnings = [ ]
167
+ allow ( FastlaneCore ::UI ) . to receive ( :important ) { |message | warnings << message }
168
+
169
+ with_tmp_file ( named : 'key' ) do |file_path |
170
+ run_described_fastlane_action (
171
+ bucket : test_bucket ,
172
+ key : 'key' ,
173
+ file : file_path ,
174
+ skip_if_exists : true
175
+ )
176
+ expect ( warnings ) . to eq [ "File already exists in S3 bucket #{ test_bucket } at #{ expected_key } . Skipping upload." ]
177
+ end
178
+ end
161
179
end
162
180
end
You can’t perform that action at this time.
0 commit comments