fastlane-plugin-google_drive 0.8.0 → 0.10.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: 6de403d0e5f2266e62059e359322a6babbb1d88905e3708130bae977d7078167
4
- data.tar.gz: 4e94204d3832150ed389197b2fa3316c3cc2c44bc29ad5a9ca67fdb599831d64
3
+ metadata.gz: 95915a684767c4d65c40e26820aad4d29579adca45710cab0a5ff555cf1c7624
4
+ data.tar.gz: 2dd1a39283b55295292112371d91f1c9a4e8e0450226e15f9492f8af4a4078a6
5
5
  SHA512:
6
- metadata.gz: 00f9a29bca7b319178aae13706bde63808e25fca4613fa5d626067966f5721bb2b39045bd4103c55bb57aa088b1dec88dc731a280268ad12f9ea8c0fe72dc4ef
7
- data.tar.gz: 357df4c4b4bfdc0bd07c5fafa588533d98e5c11f02ae193d10e800de0330f58623d5fcab1f48326a019011eb0b91fa01e57e5f62faa4fc4031e027e1c56bf36e
6
+ metadata.gz: a285dd2f1557c1e847c190e546b2ebdacb91ff725829d66c074299b205fadea6b419ecc2762a9307731367823256e1d4d5c122cce2be314611fae37b61916851
7
+ data.tar.gz: ff88fbe7ea37e1561f383c15385b00ced9f956b11b590a72aa66768dc2675e7460497bc9f255db168453e9cca1354a05264288520b95963297974f86a33451ee
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # google_drive `fastlane` plugin
2
2
 
3
3
  [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-google_drive)
4
- [![Gem Version Badge](https://badge.fury.io/rb/fastlane-plugin-google_drive.svg)](https://badge.fury.io/rb/fastlane-plugin-google_drive)
5
- [![Build Status](https://travis-ci.com/bskim45/fastlane-plugin-google_drive.svg?branch=master)](https://travis-ci.com/bskim45/fastlane-plugin-google_drive)
4
+ [![Gem Version](https://badge.fury.io/rb/fastlane-plugin-google_drive.svg)](https://badge.fury.io/rb/fastlane-plugin-google_drive)
5
+ ![Build Status](https://github.com/bskim45/fastlane-plugin-google_drive/actions/workflows/rubygems.yml/badge.svg)
6
6
  [![Test Coverage](https://api.codeclimate.com/v1/badges/681ab1f5c19ca029dff4/test_coverage)](https://codeclimate.com/github/bskim45/fastlane-plugin-google_drive/test_coverage)
7
- [![security](https://hakiri.io/github/bskim45/fastlane-plugin-google_drive/master.svg)](https://hakiri.io/github/bskim45/fastlane-plugin-google_drive/master)
8
7
 
9
8
  ## Getting Started
10
9
 
@@ -16,14 +15,15 @@ fastlane add_plugin google_drive
16
15
 
17
16
  ## About google_drive
18
17
 
19
- > Please refer to [this guide](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md) to create an Google Drive credential.
18
+ > Please refer to [this guide](https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md) to create a Google Drive credential.
20
19
 
21
20
  Upload files to Google Drive folder.
22
- > Aliases for this action - `google_drive_upload` and `upload_google_drive` are both removed in `v0.6.0`.
23
21
 
24
22
  ```ruby
25
23
  upload_to_google_drive(
26
24
  drive_keyfile: 'drive_key.json',
25
+ # or you can provide the content of JSON keyfile directly as an argument
26
+ # drive_key_json: __KEYFILE_CONTENT__,
27
27
  service_account: true,
28
28
  folder_id: 'folder_id',
29
29
  upload_files: ['file_to_upload', 'another_file_to_upload']
@@ -50,6 +50,23 @@ update_google_drive_file(
50
50
  )
51
51
  ```
52
52
 
53
+ Find the existing file or folder:
54
+
55
+ ```ruby
56
+ # find the file or folder by ID
57
+ find_google_drive_file_by_id(
58
+ drive_keyfile: 'drive_key.json',
59
+ file_id: 'file_or_folder_id'
60
+ )
61
+
62
+ # find the file or folder by title
63
+ find_google_drive_file_by_title(
64
+ drive_keyfile: 'drive_key.json',
65
+ parent_folder_id: 'parent_folder_id',
66
+ file_title: 'file_or_folder_title'
67
+ )
68
+ ```
69
+
53
70
  Download feature is not implemented yet. PR is always welcome.
54
71
 
55
72
  ## Example
@@ -90,4 +107,4 @@ _fastlane_ is the easiest way to automate beta deployments and releases for your
90
107
 
91
108
  The MIT License (MIT)
92
109
 
93
- Copyright (c) 2019 Bumsoo Kim (<https://bsk.im>)
110
+ Copyright (c) 2022 Bumsoo Kim (<https://bsk.im>)
@@ -7,12 +7,16 @@ module Fastlane
7
7
  GDRIVE_CREATED_FOLDER_ID = :GDRIVE_CREATED_FOLDER_ID
8
8
  GDRIVE_CREATED_FOLDER_URL = :GDRIVE_CREATED_FOLDER_URL
9
9
  end
10
+
10
11
  class CreateGoogleDriveFolderAction < Action
11
12
  def self.run(params)
12
- UI.message("Using config file: #{params[:drive_keyfile]}")
13
+ unless params[:drive_keyfile].nil?
14
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
15
+ end
13
16
 
14
17
  session = Helper::GoogleDriveHelper.setup(
15
18
  keyfile: params[:drive_keyfile],
19
+ key_json: params[:drive_key_json],
16
20
  service_account: params[:service_account]
17
21
  )
18
22
 
@@ -47,36 +51,62 @@ module Fastlane
47
51
 
48
52
  def self.available_options
49
53
  [
50
- FastlaneCore::ConfigItem.new(key: :drive_keyfile,
51
- env_name: 'GDRIVE_KEY_FILE',
52
- description: 'Json config file',
53
- type: String,
54
- default_value: 'drive_key.json',
55
- verify_block: proc do |value|
56
- UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
57
- end),
58
- FastlaneCore::ConfigItem.new(key: :service_account,
59
- env_name: 'GDRIVE_SERVICE_ACCOUNT',
60
- description: 'Credential is service account',
61
- optional: true,
62
- is_string: false,
63
- default_value: false),
64
- FastlaneCore::ConfigItem.new(key: :folder_id,
65
- env_name: "GDRIVE_UPLOAD_FOLDER_ID",
66
- description: "Upload target folder id",
67
- optional: false,
68
- type: String,
69
- verify_block: proc do |value|
70
- UI.user_error!("No target folder_id given, pass using `folder_id: 'some_id'`") unless value and !value.empty?
71
- end),
72
- FastlaneCore::ConfigItem.new(key: :folder_title,
73
- env_name: "GDRIVE_FOLDER_NAME",
74
- description: "Folder title of new one",
75
- optional: false,
76
- type: String,
77
- verify_block: proc do |value|
78
- UI.user_error!("No folder title given") if value.nil? || value.empty?
79
- end)
54
+ FastlaneCore::ConfigItem.new(
55
+ key: :drive_keyfile,
56
+ env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
57
+ description: 'Path to the JSON keyfile',
58
+ conflicting_options: [:drive_key_json],
59
+ type: String,
60
+ optional: true,
61
+ verify_block: proc do |value|
62
+ UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
63
+ UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
64
+ end
65
+ ),
66
+ FastlaneCore::ConfigItem.new(
67
+ key: :drive_key_json,
68
+ env_name: 'GDRIVE_KEY_JSON',
69
+ description: 'Credential key in stringified JSON format',
70
+ optional: true,
71
+ conflicting_options: [:drive_keyfile],
72
+ type: String,
73
+ sensitive: true,
74
+ verify_block: proc do |value|
75
+ begin
76
+ JSON.parse(value)
77
+ rescue JSON::ParserError
78
+ UI.user_error!("Provided credential key is not a valid JSON")
79
+ end
80
+ end
81
+ ),
82
+ FastlaneCore::ConfigItem.new(
83
+ key: :service_account,
84
+ env_name: 'GDRIVE_SERVICE_ACCOUNT',
85
+ description: 'true if the credential is for a service account, false otherwise',
86
+ optional: true,
87
+ is_string: false,
88
+ default_value: false
89
+ ),
90
+ FastlaneCore::ConfigItem.new(
91
+ key: :folder_id,
92
+ env_name: "GDRIVE_UPLOAD_FOLDER_ID",
93
+ description: "Upload target folder id",
94
+ optional: false,
95
+ type: String,
96
+ verify_block: proc do |value|
97
+ UI.user_error!("No target `folder_id` was provided. Pass it using `folder_id: 'some_id'`") unless value and !value.empty?
98
+ end
99
+ ),
100
+ FastlaneCore::ConfigItem.new(
101
+ key: :folder_title,
102
+ env_name: "GDRIVE_FOLDER_NAME",
103
+ description: "Folder title of new one",
104
+ optional: false,
105
+ type: String,
106
+ verify_block: proc do |value|
107
+ UI.user_error!("No folder title given") if value.nil? || value.empty?
108
+ end
109
+ )
80
110
  ]
81
111
  end
82
112
 
@@ -92,7 +122,7 @@ module Fastlane
92
122
  end
93
123
 
94
124
  def self.authors
95
- ['Kohki Miki (@giginet)']
125
+ ['Bumsoo Kim (@bskim45)', 'Kohki Miki (@giginet)']
96
126
  end
97
127
 
98
128
  def self.is_supported?(platform)
@@ -0,0 +1,127 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/google_drive_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ GDRIVE_FILE_ID = :GDRIVE_FILE_ID
8
+ GDRIVE_FILE_TITLE = :GDRIVE_FILE_TITLE
9
+ GDRIVE_FILE_URL = :GDRIVE_FILE_URL
10
+ end
11
+
12
+ class FindGoogleDriveFileByIdAction < Action
13
+ def self.run(params)
14
+ unless params[:drive_keyfile].nil?
15
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
16
+ end
17
+
18
+ session = Helper::GoogleDriveHelper.setup(
19
+ keyfile: params[:drive_keyfile],
20
+ key_json: params[:drive_key_json],
21
+ service_account: params[:service_account]
22
+ )
23
+
24
+ # parameter validation
25
+ target_file_id = params[:file_id]
26
+
27
+ begin
28
+ file = Helper::GoogleDriveHelper.file_by_id(
29
+ session: session, fid: target_file_id
30
+ )
31
+ rescue FastlaneCore::Interface::FastlaneError
32
+ file = nil
33
+ end
34
+
35
+ if file.nil?
36
+ UI.error("No file or folder was found.")
37
+ else
38
+ Actions.lane_context[SharedValues::GDRIVE_FILE_ID] = file.resource_id.split(':').last
39
+ Actions.lane_context[SharedValues::GDRIVE_FILE_TITLE] = file.title
40
+ Actions.lane_context[SharedValues::GDRIVE_FILE_URL] = file.human_url
41
+ end
42
+ end
43
+
44
+ def self.description
45
+ 'Find a Google Drive file or folder by ID'
46
+ end
47
+
48
+ def self.details
49
+ [
50
+ 'Find a Google Drive file or folder by ID',
51
+ 'See https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md to get a keyfile'
52
+ ].join("\n")
53
+ end
54
+
55
+ def self.available_options
56
+ [
57
+ FastlaneCore::ConfigItem.new(
58
+ key: :drive_keyfile,
59
+ env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
60
+ description: 'Path to the JSON keyfile',
61
+ conflicting_options: [:drive_key_json],
62
+ type: String,
63
+ optional: true,
64
+ verify_block: proc do |value|
65
+ UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
66
+ UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
67
+ end
68
+ ),
69
+ FastlaneCore::ConfigItem.new(
70
+ key: :drive_key_json,
71
+ env_name: 'GDRIVE_KEY_JSON',
72
+ description: 'Credential key in stringified JSON format',
73
+ optional: true,
74
+ conflicting_options: [:drive_keyfile],
75
+ type: String,
76
+ sensitive: true,
77
+ verify_block: proc do |value|
78
+ begin
79
+ JSON.parse(value)
80
+ rescue JSON::ParserError
81
+ UI.user_error!("Provided credential key is not a valid JSON")
82
+ end
83
+ end
84
+ ),
85
+ FastlaneCore::ConfigItem.new(
86
+ key: :service_account,
87
+ env_name: 'GDRIVE_SERVICE_ACCOUNT',
88
+ description: 'true if the credential is for a service account, false otherwise',
89
+ optional: true,
90
+ is_string: false,
91
+ default_value: false
92
+ ),
93
+ FastlaneCore::ConfigItem.new(
94
+ key: :file_id,
95
+ env_name: 'GDRIVE_TARGET_FILE_ID',
96
+ description: 'Target file or folder ID to check the existence',
97
+ optional: false,
98
+ type: String,
99
+ verify_block: proc do |value|
100
+ UI.user_error!("No `file_id` was given. Pass it using `file_id: 'some_id'`") if value.nil? || value.empty?
101
+ end
102
+ )
103
+ ]
104
+ end
105
+
106
+ def self.output
107
+ [
108
+ ['GDRIVE_FILE_ID', 'The file ID of the file or folder.'],
109
+ ['GDRIVE_FILE_TITLE', 'The title of the file or folder.'],
110
+ ['GDRIVE_FILE_URL', 'The link to the file or folder.']
111
+ ]
112
+ end
113
+
114
+ def self.return_value
115
+ # nothing
116
+ end
117
+
118
+ def self.authors
119
+ ['Bumsoo Kim (@bskim45)']
120
+ end
121
+
122
+ def self.is_supported?(platform)
123
+ true
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,141 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/google_drive_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ module SharedValues
7
+ end
8
+
9
+ class FindGoogleDriveFileByTitleAction < Action
10
+ def self.run(params)
11
+ unless params[:drive_keyfile].nil?
12
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
13
+ end
14
+
15
+ session = Helper::GoogleDriveHelper.setup(
16
+ keyfile: params[:drive_keyfile],
17
+ key_json: params[:drive_key_json],
18
+ service_account: params[:service_account]
19
+ )
20
+
21
+ # parameter validation
22
+ parent_folder_id = params[:parent_folder_id]
23
+ file_title = params[:file_title]
24
+
25
+ parent_folder = Helper::GoogleDriveHelper.file_by_id(
26
+ session: session, fid: parent_folder_id
27
+ )
28
+
29
+ UI.abort_with_message!('The parent folder was not found.') if parent_folder.nil?
30
+
31
+ begin
32
+ file = Helper::GoogleDriveHelper.file_by_title(
33
+ root_folder: parent_folder, title: file_title
34
+ )
35
+ rescue FastlaneCore::Interface::FastlaneError
36
+ file = nil
37
+ end
38
+
39
+ if file.nil?
40
+ UI.error('No file or folder was found.')
41
+ else
42
+ Actions.lane_context[SharedValues::GDRIVE_FILE_ID] = file.resource_id.split(':').last
43
+ Actions.lane_context[SharedValues::GDRIVE_FILE_TITLE] = file.title
44
+ Actions.lane_context[SharedValues::GDRIVE_FILE_URL] = file.human_url
45
+ end
46
+ end
47
+
48
+ def self.description
49
+ 'Find a Google Drive file or folder by title'
50
+ end
51
+
52
+ def self.details
53
+ [
54
+ 'Find a Google Drive file or folder by title',
55
+ 'See https://github.com/gimite/google-drive-ruby/blob/master/doc/authorization.md to get a keyfile'
56
+ ].join("\n")
57
+ end
58
+
59
+ def self.available_options
60
+ [
61
+ FastlaneCore::ConfigItem.new(
62
+ key: :drive_keyfile,
63
+ env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
64
+ description: 'Path to the JSON keyfile',
65
+ conflicting_options: [:drive_key_json],
66
+ type: String,
67
+ optional: true,
68
+ verify_block: proc do |value|
69
+ UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
70
+ UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
71
+ end
72
+ ),
73
+ FastlaneCore::ConfigItem.new(
74
+ key: :drive_key_json,
75
+ env_name: 'GDRIVE_KEY_JSON',
76
+ description: 'Credential key in stringified JSON format',
77
+ optional: true,
78
+ conflicting_options: [:drive_keyfile],
79
+ type: String,
80
+ sensitive: true,
81
+ verify_block: proc do |value|
82
+ begin
83
+ JSON.parse(value)
84
+ rescue JSON::ParserError
85
+ UI.user_error!("Provided credential key is not a valid JSON")
86
+ end
87
+ end
88
+ ),
89
+ FastlaneCore::ConfigItem.new(
90
+ key: :service_account,
91
+ env_name: 'GDRIVE_SERVICE_ACCOUNT',
92
+ description: 'true if the credential is for a service account, false otherwise',
93
+ optional: true,
94
+ is_string: false,
95
+ default_value: false
96
+ ),
97
+ FastlaneCore::ConfigItem.new(
98
+ key: :parent_folder_id,
99
+ env_name: 'GDRIVE_PARENT_FOLDER_ID',
100
+ description: 'The parent folder ID of the target file or folder to check the existence',
101
+ optional: false,
102
+ type: String,
103
+ verify_block: proc do |value|
104
+ UI.user_error!("No `parent_folder_id` was given. Pass it using `parent_folder_id: 'some_id'`") unless value and !value.empty?
105
+ end
106
+ ),
107
+ FastlaneCore::ConfigItem.new(
108
+ key: :file_title,
109
+ env_name: 'GDRIVE_TARGET_FILE_TITLE',
110
+ description: 'Target file or folder title to check the existence',
111
+ optional: false,
112
+ type: String,
113
+ verify_block: proc do |value|
114
+ UI.user_error!("No `file_title` was given. Pass it using `file_title: 'some_title'`") unless value and !value.empty?
115
+ end
116
+ ),
117
+ ]
118
+ end
119
+
120
+ def self.output
121
+ [
122
+ ['GDRIVE_FILE_ID', 'The file title of the file or folder'],
123
+ ['GDRIVE_FILE_TITLE', 'The title of the file or folder'],
124
+ ['GDRIVE_FILE_URL', 'The link to the file or folder']
125
+ ]
126
+ end
127
+
128
+ def self.return_value
129
+ # nothing
130
+ end
131
+
132
+ def self.authors
133
+ ['Bumsoo Kim (@bskim45)']
134
+ end
135
+
136
+ def self.is_supported?(platform)
137
+ true
138
+ end
139
+ end
140
+ end
141
+ end
@@ -7,12 +7,16 @@ module Fastlane
7
7
  GDRIVE_UPDATED_FILE_NAME = :GDRIVE_UPDATED_FILE_NAME
8
8
  GDRIVE_UPDATED_FILE_URL = :GDRIVE_UPDATED_FILE_URL
9
9
  end
10
+
10
11
  class UpdateGoogleDriveFileAction < Action
11
12
  def self.run(params)
12
- UI.message("Using config file: #{params[:drive_keyfile]}")
13
+ unless params[:drive_keyfile].nil?
14
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
15
+ end
13
16
 
14
17
  session = Helper::GoogleDriveHelper.setup(
15
18
  keyfile: params[:drive_keyfile],
19
+ key_json: params[:drive_key_json],
16
20
  service_account: params[:service_account]
17
21
  )
18
22
 
@@ -46,37 +50,63 @@ module Fastlane
46
50
 
47
51
  def self.available_options
48
52
  [
49
- FastlaneCore::ConfigItem.new(key: :drive_keyfile,
50
- env_name: 'GDRIVE_KEY_FILE',
51
- description: 'Json config file',
52
- type: String,
53
- default_value: 'drive_key.json',
54
- verify_block: proc do |value|
55
- UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
56
- end),
57
- FastlaneCore::ConfigItem.new(key: :service_account,
58
- env_name: 'GDRIVE_SERVICE_ACCOUNT',
59
- description: 'Credential is service account',
60
- optional: true,
61
- is_string: false,
62
- default_value: false),
63
- FastlaneCore::ConfigItem.new(key: :file_id,
64
- env_name: "GDRIVE_UPDATE_FILE_ID",
65
- description: "Target file id to update the content",
66
- optional: false,
67
- type: String,
68
- verify_block: proc do |value|
69
- UI.user_error!("No target file id given, pass using `file_id: 'some_id'`") unless value and !value.empty?
70
- end),
71
- FastlaneCore::ConfigItem.new(key: :upload_file,
72
- env_name: "GDRIVE_UPLOAD_FILE",
73
- description: "Path to a file to be uploaded",
74
- optional: false,
75
- is_string: false,
76
- verify_block: proc do |value|
77
- UI.user_error!("No upload file is given, pass using `upload_file: 'some/path/a.txt'`") unless value and !value.empty?
78
- UI.user_error!("Couldn't find upload file at path '#{value}'") unless File.exist?(value)
79
- end)
53
+ FastlaneCore::ConfigItem.new(
54
+ key: :drive_keyfile,
55
+ env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
56
+ description: 'Path to the JSON keyfile',
57
+ conflicting_options: [:drive_key_json],
58
+ type: String,
59
+ optional: true,
60
+ verify_block: proc do |value|
61
+ UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
62
+ UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
63
+ end
64
+ ),
65
+ FastlaneCore::ConfigItem.new(
66
+ key: :drive_key_json,
67
+ env_name: 'GDRIVE_KEY_JSON',
68
+ description: 'Credential key in stringified JSON format',
69
+ optional: true,
70
+ conflicting_options: [:drive_keyfile],
71
+ type: String,
72
+ sensitive: true,
73
+ verify_block: proc do |value|
74
+ begin
75
+ JSON.parse(value)
76
+ rescue JSON::ParserError
77
+ UI.user_error!("Provided credential key is not a valid JSON")
78
+ end
79
+ end
80
+ ),
81
+ FastlaneCore::ConfigItem.new(
82
+ key: :service_account,
83
+ env_name: 'GDRIVE_SERVICE_ACCOUNT',
84
+ description: 'true if the credential is for a service account, false otherwise',
85
+ optional: true,
86
+ is_string: false,
87
+ default_value: false
88
+ ),
89
+ FastlaneCore::ConfigItem.new(
90
+ key: :file_id,
91
+ env_name: "GDRIVE_UPDATE_FILE_ID",
92
+ description: "Target file id to update the content",
93
+ optional: false,
94
+ type: String,
95
+ verify_block: proc do |value|
96
+ UI.user_error!("No target `file_id` is provided. Pass it using `file_id: 'some_id'`") unless value and !value.empty?
97
+ end
98
+ ),
99
+ FastlaneCore::ConfigItem.new(
100
+ key: :upload_file,
101
+ env_name: "GDRIVE_UPLOAD_FILE",
102
+ description: "Path to a file to be uploaded",
103
+ optional: false,
104
+ is_string: false,
105
+ verify_block: proc do |value|
106
+ UI.user_error!("No upload file is given, pass using `upload_file: 'some/path/a.txt'`") unless value and !value.empty?
107
+ UI.user_error!("Couldn't find upload file at path '#{value}'") unless File.exist?(value)
108
+ end
109
+ )
80
110
  ]
81
111
  end
82
112
 
@@ -7,12 +7,16 @@ module Fastlane
7
7
  GDRIVE_UPLOADED_FILE_NAMES = :GDRIVE_UPLOADED_FILE_NAMES
8
8
  GDRIVE_UPLOADED_FILE_URLS = :GDRIVE_UPLOADED_FILE_URLS
9
9
  end
10
+
10
11
  class UploadToGoogleDriveAction < Action
11
12
  def self.run(params)
12
- UI.message("Using config file: #{params[:drive_keyfile]}")
13
+ unless params[:drive_keyfile].nil?
14
+ UI.message("Using credential file: #{params[:drive_keyfile]}")
15
+ end
13
16
 
14
17
  session = Helper::GoogleDriveHelper.setup(
15
18
  keyfile: params[:drive_keyfile],
19
+ key_json: params[:drive_key_json],
16
20
  service_account: params[:service_account]
17
21
  )
18
22
 
@@ -56,46 +60,74 @@ module Fastlane
56
60
 
57
61
  def self.available_options
58
62
  [
59
- FastlaneCore::ConfigItem.new(key: :drive_keyfile,
60
- env_name: 'GDRIVE_KEY_FILE',
61
- description: 'Json config file',
62
- type: String,
63
- default_value: 'drive_key.json',
64
- verify_block: proc do |value|
65
- UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
66
- end),
67
- FastlaneCore::ConfigItem.new(key: :service_account,
68
- env_name: 'GDRIVE_SERVICE_ACCOUNT',
69
- description: 'Credential is service account',
70
- optional: true,
71
- is_string: false,
72
- default_value: false),
73
- FastlaneCore::ConfigItem.new(key: :folder_id,
74
- env_name: "GDRIVE_UPLOAD_FOLDER_ID",
75
- description: "Upload target folder id",
76
- optional: false,
77
- type: String,
78
- verify_block: proc do |value|
79
- UI.user_error!("No target folder id given, pass using `folder_id: 'some_id'`") unless value and !value.empty?
80
- end),
81
- FastlaneCore::ConfigItem.new(key: :upload_files,
82
- env_name: "GDRIVE_UPLOAD_FILES",
83
- description: "Path to files to be uploaded",
84
- optional: false,
85
- is_string: false,
86
- verify_block: proc do |value|
87
- UI.user_error!("upload_files must be an Array of paths to files") unless value.kind_of?(Array)
88
- UI.user_error!("No upload file is given, pass using `upload_files: ['a', 'b']`") unless value and !value.empty?
89
- value.each do |path|
90
- UI.user_error!("Couldn't find upload file at path '#{path}'") unless File.exist?(path)
91
- end
92
- end),
93
- FastlaneCore::ConfigItem.new(key: :public_links,
94
- env_name: 'GDRIVE_PUBLIC_LINKS',
95
- description: 'Uploaded file links should be public',
96
- optional: true,
97
- default_value: false,
98
- is_string: false)
63
+ FastlaneCore::ConfigItem.new(
64
+ key: :drive_keyfile,
65
+ env_names: ['GDRIVE_KEY_FILE', 'GOOGLE_APPLICATION_CREDENTIALS'],
66
+ description: 'Path to the JSON keyfile',
67
+ conflicting_options: [:drive_key_json],
68
+ type: String,
69
+ optional: true,
70
+ verify_block: proc do |value|
71
+ UI.user_error!("Couldn't find config keyfile at path '#{value}'") unless File.exist?(value)
72
+ UI.user_error!("'#{value}' doesn't seem to be a valid JSON keyfile") unless FastlaneCore::Helper.json_file?(value)
73
+ end
74
+ ),
75
+ FastlaneCore::ConfigItem.new(
76
+ key: :drive_key_json,
77
+ env_name: 'GDRIVE_KEY_JSON',
78
+ description: 'Credential key in stringified JSON format',
79
+ optional: true,
80
+ conflicting_options: [:drive_keyfile],
81
+ type: String,
82
+ sensitive: true,
83
+ verify_block: proc do |value|
84
+ begin
85
+ JSON.parse(value)
86
+ rescue JSON::ParserError
87
+ UI.user_error!("Provided credential key is not a valid JSON")
88
+ end
89
+ end
90
+ ),
91
+ FastlaneCore::ConfigItem.new(
92
+ key: :service_account,
93
+ env_name: 'GDRIVE_SERVICE_ACCOUNT',
94
+ description: 'true if the credential is for a service account, false otherwise',
95
+ optional: true,
96
+ is_string: false,
97
+ default_value: false
98
+ ),
99
+ FastlaneCore::ConfigItem.new(
100
+ key: :folder_id,
101
+ env_name: "GDRIVE_UPLOAD_FOLDER_ID",
102
+ description: "Upload target folder id",
103
+ optional: false,
104
+ type: String,
105
+ verify_block: proc do |value|
106
+ UI.user_error!("No target `folder_id` was provided. Pass it using `folder_id: 'some_id'`") unless value and !value.empty?
107
+ end
108
+ ),
109
+ FastlaneCore::ConfigItem.new(
110
+ key: :upload_files,
111
+ env_name: "GDRIVE_UPLOAD_FILES",
112
+ description: "Path to files to be uploaded",
113
+ optional: false,
114
+ is_string: false,
115
+ verify_block: proc do |value|
116
+ UI.user_error!("upload_files must be an Array of paths to files") unless value.kind_of?(Array)
117
+ UI.user_error!("No upload file is given, pass using `upload_files: ['a', 'b']`") unless value and !value.empty?
118
+ value.each do |path|
119
+ UI.user_error!("Couldn't find upload file at path '#{path}'") unless File.exist?(path)
120
+ end
121
+ end
122
+ ),
123
+ FastlaneCore::ConfigItem.new(
124
+ key: :public_links,
125
+ env_name: 'GDRIVE_PUBLIC_LINKS',
126
+ description: 'Uploaded file links should be public',
127
+ optional: true,
128
+ default_value: false,
129
+ is_string: false
130
+ )
99
131
  ]
100
132
  end
101
133
 
@@ -1,15 +1,18 @@
1
1
  require 'fastlane_core/ui/ui'
2
2
  require 'google_drive'
3
+
3
4
  module Fastlane
4
5
  UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
5
6
 
6
7
  module Helper
7
8
  class GoogleDriveHelper
8
- def self.setup(keyfile: nil, service_account: false)
9
+ def self.setup(keyfile: nil, key_json: nil, service_account: false)
10
+ keyfile_or_io = keyfile || StringIO.new(key_json || '')
11
+
9
12
  if service_account
10
- ::GoogleDrive::Session.from_service_account_key(keyfile)
13
+ ::GoogleDrive::Session.from_service_account_key(keyfile_or_io)
11
14
  else
12
- ::GoogleDrive::Session.from_config(keyfile)
15
+ ::GoogleDrive::Session.from_config(keyfile_or_io)
13
16
  end
14
17
  rescue Exception => e
15
18
  UI.error(e.message)
@@ -24,6 +27,14 @@ module Fastlane
24
27
  UI.user_error!("File with id '#{fid}' not found in Google Drive")
25
28
  end
26
29
 
30
+ def self.file_by_title(root_folder:, title:)
31
+ file = root_folder.file_by_title(title)
32
+ file
33
+ rescue Exception => e
34
+ UI.error(e.message)
35
+ UI.user_error!("File with title '#{title}' not found in Google Drive")
36
+ end
37
+
27
38
  def self.upload_file(file: nil, file_name: nil, title: nil)
28
39
  raise "Not Google Drive file" unless file.kind_of?(::GoogleDrive::File)
29
40
 
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module GoogleDrive
3
- VERSION = "0.8.0"
3
+ VERSION = "0.10.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-google_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bumsoo Kim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-17 00:00:00.000000000 Z
11
+ date: 2024-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google_drive2
@@ -196,6 +196,20 @@ dependencies:
196
196
  - - ">="
197
197
  - !ruby/object:Gem::Version
198
198
  version: '0'
199
+ - !ruby/object:Gem::Dependency
200
+ name: simplecov_json_formatter
201
+ requirement: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ type: :development
207
+ prerelease: false
208
+ version_requirements: !ruby/object:Gem::Requirement
209
+ requirements:
210
+ - - ">="
211
+ - !ruby/object:Gem::Version
212
+ version: '0'
199
213
  - !ruby/object:Gem::Dependency
200
214
  name: fastlane
201
215
  requirement: !ruby/object:Gem::Requirement
@@ -220,6 +234,8 @@ files:
220
234
  - README.md
221
235
  - lib/fastlane/plugin/google_drive.rb
222
236
  - lib/fastlane/plugin/google_drive/actions/create_google_drive_folder_action.rb
237
+ - lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_id_action.rb
238
+ - lib/fastlane/plugin/google_drive/actions/find_google_drive_file_by_title_action.rb
223
239
  - lib/fastlane/plugin/google_drive/actions/update_google_drive_file_action.rb
224
240
  - lib/fastlane/plugin/google_drive/actions/upload_to_google_drive_action.rb
225
241
  - lib/fastlane/plugin/google_drive/helper/google_drive_helper.rb
@@ -243,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
259
  - !ruby/object:Gem::Version
244
260
  version: '0'
245
261
  requirements: []
246
- rubygems_version: 3.0.8
262
+ rubygems_version: 3.1.6
247
263
  signing_key:
248
264
  specification_version: 4
249
265
  summary: Upload files to Google Drive