forked from gocd/build_utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-to-maven
executable file
·92 lines (74 loc) · 2.67 KB
/
upload-to-maven
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
#!/usr/bin/env ruby
if File.basename($PROGRAM_NAME) != 'rake'
require 'shellwords'
puts "bundle exec rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
exec "bundle exec rake -f #{Shellwords.escape($PROGRAM_NAME)} #{Shellwords.shelljoin(ARGV)}"
end
$stdout.sync = true
$stderr.sync = true
require 'rubygems'
require 'timeout'
require 'json'
def artifact_suffix
ENV['ARTIFACT_SUFFIX'] || '-experimental'
end
def experimental?
artifact_suffix =~ /experimental/
end
def version_info
JSON.parse(File.read('target/version.json'))
end
def go_version
version_info['go_version']
end
def go_full_version
version_info['go_full_version']
end
def maven_release_version
experimental? ? go_full_version : go_version
end
task :clean do
rm_rf 'target'
end
task :init do
mkdir_p 'target'
end
task :fetch do
job_identifier = ENV['INSTALLER_JOB_IDENTIFIER'] || (fail 'INSTALLER_JOB_IDENTIFIER not set. Example: build-linux/645/go-sdk/2/go-plugin-api')
url = "https://build.gocd.org/go/files/#{job_identifier}/go-plugin-api.zip"
username = ENV['ARTIFACT_FETCH_USERNAME'] || 'view'
password = ENV['ARTIFACT_FETCH_PASSWORD'] || 'password'
cd 'target' do
Timeout.timeout(60) do
loop do
sh("curl --silent --fail --user #{username}:#{password} -D curl-headers.txt #{url} -o go-plugin-api.zip")
if File.read('curl-headers.txt') =~ /HTTP\/1\.1 200 OK/
rm_f 'curl-headers.txt'
break
end
sleep 1
end
end
sh('unzip go-plugin-api.zip')
sh("curl --silent --fail --user #{username}:#{password} https://build.gocd.org/go/files/#{job_identifier}/dist/meta/version.json -o version.json")
end
end
task :prepare_for_upload do
{
"go-plugin-api-#{go_full_version}.jar" => "go-plugin-api#{artifact_suffix}-#{maven_release_version}.jar",
"go-plugin-api-#{go_full_version}-javadoc.jar" => "go-plugin-api#{artifact_suffix}-#{maven_release_version}-javadoc.jar",
"go-plugin-api-#{go_full_version}-sources.jar" => "go-plugin-api#{artifact_suffix}-#{maven_release_version}-sources.jar"
}.each do |original_name, new_name|
if original_name != new_name
cp "target/go-plugin-api/#{original_name}", "target/go-plugin-api/#{new_name}"
end
end
end
task :upload do
pom_content = File.read('deploy-pom.xml').gsub('${goReleaseVersion}', maven_release_version).gsub('${artifactSuffix}', artifact_suffix)
File.open('target/go-plugin-api/pom.xml', 'w') { |f| f.puts pom_content }
cd 'target/go-plugin-api' do
sh("mvn -DautoReleaseToCentral=#{ENV['AUTO_RELEASE_TO_CENTRAL'] || 'false'} --batch-mode deploy")
end
end
task default: [:clean, :init, :fetch, :prepare_for_upload, :upload]