appetize-cli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -1
- data/CHANGELOG.md +4 -0
- data/README.md +18 -0
- data/lib/appetize/api.rb +37 -0
- data/lib/appetize/ci/gitlab.rb +26 -0
- data/lib/appetize/cli.rb +12 -0
- data/lib/appetize/commands/delete.rb +3 -10
- data/lib/appetize/commands/update.rb +25 -0
- data/lib/appetize/commands/upload.rb +37 -11
- data/lib/appetize/templates/update/.gitkeep +1 -0
- data/lib/appetize/version.rb +1 -1
- data/lib/appetize.rb +0 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cc8bacaba3e5f4e836d8e174d551bd32124a1ca8bfa4df92526492ac4904ae1
|
4
|
+
data.tar.gz: 7650c019adbc139aeac7beb5ee44e58f9163e340e26c7b6a43bf2f78204bd8b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 920e345be4a9c43c4cc12b853fbb0b354b2aebbd49fd6b368b6e220d344bac8d440446f7c62c39d34cd6509fb6337a49f01092f16118b99fc9388a098f4664f2
|
7
|
+
data.tar.gz: 49d8e0478a0ec95b035dc0737d758b3c798ec3cb8476a26e5b258f2ab882c452dda6e8237ee3876019facea3dedb81ee362edfbc88b0208aa1aedc88de8f8a1e
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
AllCops:
|
2
2
|
TargetRubyVersion: 2.5
|
3
|
+
SuggestExtensions: false
|
4
|
+
NewCops: enable
|
3
5
|
|
4
6
|
Style/StringLiterals:
|
5
7
|
Enabled: true
|
@@ -19,4 +21,8 @@ Lint/UnusedMethodArgument:
|
|
19
21
|
Enabled: false
|
20
22
|
|
21
23
|
Style/Documentation:
|
22
|
-
Enabled: false
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Metrics/BlockLength:
|
27
|
+
IgnoredMethods: ['describe', 'context']
|
28
|
+
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -47,6 +47,24 @@ Example:
|
|
47
47
|
$ appetize upload builds/app-debug.apk android
|
48
48
|
$ appetize upload builds/app.zip ios
|
49
49
|
|
50
|
+
### Update
|
51
|
+
|
52
|
+
Update an existing app in Appitize with a new APK/ZIP
|
53
|
+
|
54
|
+
```
|
55
|
+
Usage:
|
56
|
+
appetize update PATH PUBLIC_KEY
|
57
|
+
```
|
58
|
+
|
59
|
+
`PATH` the path to the Apk or Zip file of the app you would like to deploy
|
60
|
+
|
61
|
+
`PUBLIC_KEY` the public key provided by Appetize for the specific app deployment you'd like to update
|
62
|
+
|
63
|
+
Example:
|
64
|
+
|
65
|
+
$ appetize upload builds/app-debug.apk somepublickey
|
66
|
+
$ appetize upload builds/app.zip somepublickey
|
67
|
+
|
50
68
|
|
51
69
|
### Delete
|
52
70
|
|
data/lib/appetize/api.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module Appetize
|
6
|
+
class API
|
7
|
+
def initialize(token = nil, api_host = nil)
|
8
|
+
@token = token || ENV["APPETIZE_API_TOKEN"]
|
9
|
+
@api_host = api_host || "api.appetize.io"
|
10
|
+
|
11
|
+
raise "Appetize Token Missing" if @token.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def create(path, platform)
|
15
|
+
url = "https://#{@api_host}/v1/apps"
|
16
|
+
auth = { username: @token, password: "" }
|
17
|
+
body = { platform: platform, file: File.open(path) }
|
18
|
+
|
19
|
+
HTTParty.post(url, body: body, basic_auth: auth)
|
20
|
+
end
|
21
|
+
|
22
|
+
def update(path, public_key)
|
23
|
+
url = "https://#{@api_host}/v1/apps/#{public_key}"
|
24
|
+
auth = { username: @token, password: "" }
|
25
|
+
body = { file: File.open(path) }
|
26
|
+
|
27
|
+
HTTParty.post(url, body: body, basic_auth: auth)
|
28
|
+
end
|
29
|
+
|
30
|
+
def delete(public_key)
|
31
|
+
url = "https://#{@api_host}/v1/apps/#{public_key}"
|
32
|
+
auth = { username: @token, password: "" }
|
33
|
+
|
34
|
+
HTTParty.delete(url, basic_auth: auth)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module Appetize
|
6
|
+
module CI
|
7
|
+
class GitLab
|
8
|
+
def initialize(project_id, ref_name, api_token, api_host = nil)
|
9
|
+
@project_id = project_id
|
10
|
+
@ref_name = ref_name
|
11
|
+
@api_token = api_token
|
12
|
+
@api_host = api_host || "https://gitlab.com/api/v4"
|
13
|
+
end
|
14
|
+
|
15
|
+
def fetch_artifact(job, artifact_name)
|
16
|
+
url = "#{@api_host}/projects/#{@project_id}/jobs/artifacts/#{@ref_name}/raw/#{artifact_name}?job=#{job}"
|
17
|
+
|
18
|
+
headers = {
|
19
|
+
"PRIVATE-TOKEN" => @api_token
|
20
|
+
}
|
21
|
+
|
22
|
+
HTTParty.get(url, headers: headers)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/appetize/cli.rb
CHANGED
@@ -18,6 +18,18 @@ module Appetize
|
|
18
18
|
end
|
19
19
|
map %w[--version -v] => :version
|
20
20
|
|
21
|
+
desc "update PATH PUBLIC_KEY", "Command description..."
|
22
|
+
method_option :help, aliases: "-h", type: :boolean,
|
23
|
+
desc: "Display usage information"
|
24
|
+
def update(path, public_key, token = nil, api_host = nil)
|
25
|
+
if options[:help]
|
26
|
+
invoke :help, ["update"]
|
27
|
+
else
|
28
|
+
require_relative "commands/update"
|
29
|
+
Appetize::Commands::Update.new(path, public_key, token, api_host, options).execute
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
21
33
|
desc "upload PATH PLATFORM", "Upload an APK/ZIP to Appetize"
|
22
34
|
method_option :help, aliases: "-h", type: :boolean,
|
23
35
|
desc: "Display usage information"
|
@@ -1,26 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "httparty"
|
4
3
|
require_relative "../command"
|
4
|
+
require_relative "../api"
|
5
5
|
|
6
6
|
module Appetize
|
7
7
|
module Commands
|
8
8
|
class Delete < Appetize::Command
|
9
9
|
def initialize(public_key, token = nil, api_host = nil, options = {})
|
10
|
+
@api = Appetize::API.new(token, api_host)
|
10
11
|
@public_key = public_key
|
11
|
-
@token = token
|
12
|
-
@api_host = api_host
|
13
12
|
@options = options
|
14
13
|
end
|
15
14
|
|
16
15
|
def execute(input: $stdin, output: $stdout)
|
17
|
-
|
18
|
-
api_host = @api_host || "api.appetize.io"
|
19
|
-
|
20
|
-
url = "https://#{api_host}/v1/apps/#{@public_key}"
|
21
|
-
auth = { username: token, password: "" }
|
22
|
-
|
23
|
-
response = HTTParty.delete(url, basic_auth: auth)
|
16
|
+
response = @api.delete(@public_key)
|
24
17
|
|
25
18
|
raise "Delete failed: #{response.code}" unless response.code == 200
|
26
19
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../command"
|
4
|
+
require_relative "../api"
|
5
|
+
|
6
|
+
module Appetize
|
7
|
+
module Commands
|
8
|
+
class Update < Appetize::Command
|
9
|
+
def initialize(path, public_key, token, api_host, options)
|
10
|
+
@api = Appetize::API.new(token, api_host)
|
11
|
+
@path = path
|
12
|
+
@public_key = public_key
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(input: $stdin, output: $stdout)
|
17
|
+
response = @api.update(@path, @public_key)
|
18
|
+
|
19
|
+
raise "Update failed: #{response.code}" unless response.code == 200
|
20
|
+
|
21
|
+
output.puts response.body
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,33 +1,59 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "httparty"
|
4
3
|
require_relative "../command"
|
4
|
+
require_relative "../api"
|
5
|
+
require_relative "../ci/gitlab"
|
5
6
|
|
6
7
|
module Appetize
|
7
8
|
module Commands
|
8
9
|
class Upload < Appetize::Command
|
9
10
|
def initialize(path, platform, token, api_host, options)
|
10
|
-
@
|
11
|
+
@api = Appetize::API.new(token, api_host)
|
12
|
+
@path = path
|
11
13
|
@platform = platform
|
12
|
-
@
|
13
|
-
@api_host = api_host
|
14
|
-
@options = options
|
14
|
+
@options = options
|
15
15
|
end
|
16
16
|
|
17
17
|
def execute(input: $stdin, output: $stdout)
|
18
|
-
|
19
|
-
|
18
|
+
# If we are running in GitLab CI, check for an existing pipeline
|
19
|
+
# if a pipeline is found, fetch the public key and update the
|
20
|
+
# existing Appetize app
|
21
|
+
if Appetize::Commands::Upload.gitlab_ci?
|
22
|
+
artifact_response = fetch_gitlab_artifact
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
body = { platform: @platform, file: File.open(@path) }
|
24
|
+
if artifact_response.code == 200
|
25
|
+
public_key = JSON.parse(artifact_response.body)["publicKey"]
|
24
26
|
|
25
|
-
|
27
|
+
response = @api.update(@path, public_key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
response = @api.create(@path, @platform) if public_key.nil?
|
26
32
|
|
27
33
|
raise "Upload failed: #{response.code}" unless response.code == 200
|
28
34
|
|
29
35
|
output.puts response.body
|
30
36
|
end
|
37
|
+
|
38
|
+
def self.gitlab_ci?
|
39
|
+
ENV["GITLAB_CI"].to_s.downcase == "true"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def fetch_gitlab_artifact
|
45
|
+
gitlab_client = Appetize::CI::GitLab.new(
|
46
|
+
ENV["CI_PROJECT_ID"],
|
47
|
+
ENV["CI_COMMIT_REF_NAME"],
|
48
|
+
ENV["PRIVATE_TOKEN"],
|
49
|
+
ENV["CI_API_V4_URL"]
|
50
|
+
)
|
51
|
+
|
52
|
+
gitlab_client.fetch_artifact(
|
53
|
+
"startReview",
|
54
|
+
"appetize-information.json"
|
55
|
+
)
|
56
|
+
end
|
31
57
|
end
|
32
58
|
end
|
33
59
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
#
|
data/lib/appetize/version.rb
CHANGED
data/lib/appetize.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appetize-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darby Frey
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -59,13 +59,17 @@ files:
|
|
59
59
|
- bin/setup
|
60
60
|
- exe/appetize
|
61
61
|
- lib/appetize.rb
|
62
|
+
- lib/appetize/api.rb
|
63
|
+
- lib/appetize/ci/gitlab.rb
|
62
64
|
- lib/appetize/cli.rb
|
63
65
|
- lib/appetize/command.rb
|
64
66
|
- lib/appetize/commands/.gitkeep
|
65
67
|
- lib/appetize/commands/delete.rb
|
68
|
+
- lib/appetize/commands/update.rb
|
66
69
|
- lib/appetize/commands/upload.rb
|
67
70
|
- lib/appetize/templates/.gitkeep
|
68
71
|
- lib/appetize/templates/delete/.gitkeep
|
72
|
+
- lib/appetize/templates/update/.gitkeep
|
69
73
|
- lib/appetize/templates/upload/.gitkeep
|
70
74
|
- lib/appetize/version.rb
|
71
75
|
homepage: https://gitlab.com/gitlab-org/incubation-engineering/devops-for-mobile-apps/appetize-cli
|