-
Notifications
You must be signed in to change notification settings - Fork 0
/
out
executable file
·151 lines (108 loc) · 4.26 KB
/
out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/ruby
require 'json'
require 'aptly_cli'
require 'commander'
$stdout = STDERR
input = JSON.load($stdin.read, nil, { symbolize_names: true, create_additions: false })
config = { proto: 'http' }
options = Commander::Command::Options.new
%i{ server port username password debug name comment default_distribution default_component }.each do |option|
options.__send__("#{option}=", input[:source][option])
end
if input[:params][:archive_file] && File.exist?("#{ARGV.first}/#{input[:params][:archive_file]}")
input[:params][:archive] = File.read("#{ARGV.first}/#{input[:params][:archive_file]}").strip
end
api_uri = URI(input[:source][:api_uri])
options.server = api_uri.host
options.port = api_uri.port
repo = AptlyCli::AptlyRepo.new(config, options)
response = repo.repo_show("#{input[:source][:component]}-#{input[:source][:distribution]}")
unless (200...300) === response.code
response = repo.repo_create({
name: "#{input[:source][:component]}-#{input[:source][:distribution]}",
DefaultDistribution: input[:source][:distribution],
DefaultComponent: input[:source][:component]
})
unless (200...300) === response.code
warn(response.parsed_response.first['error'])
exit(1)
end
end
file = AptlyCli::AptlyFile.new(config, options)
response = file.file_post({
file_uri: "/#{input[:source][:component]}-#{input[:source][:distribution]}",
package: "#{ARGV.first}/#{input[:params][:archive]}",
local_file: "#{ARGV.first}/#{input[:params][:archive]}"
})
unless (200...300) === response.code
warn(response.parsed_response.first['error'])
file.file_delete("/#{input[:source][:component]}-#{input[:source][:distribution]}/#{File.basename(input[:params][:archive])}")
exit(1)
end
response = repo.repo_upload({
name: "#{input[:source][:component]}-#{input[:source][:distribution]}",
dir: "#{input[:source][:component]}-#{input[:source][:distribution]}",
file: File.basename(input[:params][:archive]),
noremove: false,
forcereplace: false
})
unless (200...300) === response.code && response.parsed_response['FailedFiles'].empty?
warn(response.parsed_response.inspect)
file.file_delete("/#{input[:source][:component]}-#{input[:source][:distribution]}/#{File.basename(input[:params][:archive])}")
exit(1)
end
snapshot_name = "#{input[:source][:component]}-#{input[:source][:distribution]}-#{Time.now.getutc.to_i}"
snapshot = AptlyCli::AptlySnapshot.new(config, options)
response = snapshot.snapshot_create(
snapshot_name, #name
"#{input[:source][:component]}-#{input[:source][:distribution]}" #repo
)
unless (200...300) === response.code
warn(response.parsed_response.first['error'])
snapshot.snapshot_delete(snapshot_name)
exit(1)
end
publish = AptlyCli::AptlyPublish.new(config, options)
response = publish.publish_list()
unless response.parsed_response.any?{ |entry| entry['Distribution'].eql?(input[:source][:distribution]) && entry['Sources'].any?{ |entry_source| entry_source['Component'].eql?(input[:source][:component]) } }
response = publish.publish_repo(
snapshot_name,
{
sourcekind: 'snapshot',
prefix: input[:source][:component],
passphraseFile: input[:params][:gpg_passphrase_file],
batch: true
}
)
unless (200...300) === response.code
warn(response.parsed_response)
exit(1)
end
end
response = publish.publish_update({
snapshots: { snapshot_name => input[:source][:component] },
prefix: input[:source][:component],
distribution: input[:source][:distribution],
passphraseFile: input[:params][:gpg_passphrase_file],
batch: true
})
snapshot.snapshot_delete(snapshot_name)
unless (200...300) === response.code
warn(response.parsed_response.first['error'])
exit(1)
end
response = repo.repo_package_query({
name: "#{input[:source][:component]}-#{input[:source][:distribution]}",
query: input[:source][:package],
with_deps: false,
format: 'details'
})
matches = response.parsed_response
.select{ |entry| entry['Filename'].eql?(File.basename(input[:params][:archive])) }
.map{ |entry| { ref: entry['FilesHash'], filename: entry['Filename'] } }
if matches.empty?
warn('Could not determine new version, response was: ' + response.inspect)
exit(1)
end
$stdout = STDOUT
puts({ version: matches.first, metadata: [ { name: :filename, value: matches.first['Filename'] } ] }.to_json)