You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
4.3 KiB
Ruby
173 lines
4.3 KiB
Ruby
#! /usr/bin/env ruby
|
|
|
|
require 'concurrent'
|
|
require 'httparty'
|
|
require 'minitar'
|
|
require 'time'
|
|
require 'xz'
|
|
require 'zip'
|
|
|
|
if ARGV.size < 2
|
|
$stderr.puts "Usage: #{$0} version build_number [quick]"
|
|
exit 1
|
|
end
|
|
|
|
VERSION = ARGV[0]
|
|
BUILD_NUMBER = ARGV[1].to_i
|
|
QUICK = ARGV[2]
|
|
|
|
BASE_URL = "https://jenkins.neptards.moe/job/neptools/job/build_test/#{BUILD_NUMBER}/"
|
|
|
|
def get_artifacts job
|
|
HTTParty.get("#{BASE_URL}/#{job}/api/json?tree=artifacts[relativePath]").
|
|
parsed_response['artifacts'].map {|x| x['relativePath'] }
|
|
end
|
|
|
|
def get_artifact job, path
|
|
puts "Getting artifact #{job} #{path}"
|
|
HTTParty.get "#{BASE_URL}/#{job}/artifact/#{path}"
|
|
end
|
|
|
|
NEVER = /(?!x)x/ # regex that never matches
|
|
class ComprBase
|
|
def self.create name
|
|
res = new name
|
|
begin
|
|
yield res
|
|
ensure
|
|
res.close
|
|
end
|
|
end
|
|
|
|
def boilerplate
|
|
add_local_file 'COPYING'
|
|
add_local_file 'COPYING.THIRD_PARTY'
|
|
add_local_file 'README.md'
|
|
end
|
|
|
|
def artifact job, path, mode
|
|
art = get_artifact job, path
|
|
date = Time.httpdate art.headers['last-modified']
|
|
add_file File.basename(path), mode, date, art.body
|
|
end
|
|
|
|
def artifacts job, filter = //, exe = NEVER
|
|
get_artifacts(job).each do |art|
|
|
next if art.end_with? '.xml'
|
|
artifact job, art, (art =~ exe ? 0755 : 0644) if art =~ filter
|
|
end
|
|
end
|
|
|
|
# do not use rubyzip's File#add: it will add a broken symlink when adding a
|
|
# file that is a symlink in the fs
|
|
def add_local_file fname
|
|
stat = File.stat fname
|
|
add_file fname, stat.mode, stat.mtime, File.read(fname)
|
|
end
|
|
end
|
|
|
|
Zip.default_compression = 0 # will zopfli after
|
|
class MyZip < ComprBase
|
|
def initialize name
|
|
name << ".zip"
|
|
puts "Generating #{name}"
|
|
File.unlink name if File.exists? name
|
|
@zip = Zip::File.open name, create: true
|
|
end
|
|
|
|
def close
|
|
@zip.close
|
|
system 'advzip', '-z4k', @zip.name, exception: true unless QUICK
|
|
end
|
|
|
|
def add_file fname, mode, time, body
|
|
@zip.get_output_stream fname, permissions: mode, time: time.getutc do |s|
|
|
s.write body
|
|
end
|
|
end
|
|
end
|
|
|
|
class MyTarXz < ComprBase
|
|
def initialize name
|
|
name << ".tar.xz"
|
|
puts "Generating #{name}"
|
|
compr = QUICK ? { level: 0 } : { level: 9, extreme: true }
|
|
@xz = XZ::StreamWriter.open name, **compr, external_encoding: Encoding::BINARY
|
|
begin
|
|
@tar = Minitar::Writer.open @xz
|
|
begin
|
|
@dir = File.basename(name).gsub /\.[a-zA-Z.]*$/, ''
|
|
@tar.mkdir @dir, mode: 0755, uid: 1000, gid: 1000 # todo mtime
|
|
rescue
|
|
@tar.close
|
|
raise
|
|
end
|
|
rescue
|
|
@xz.close
|
|
File.unlink name
|
|
raise
|
|
end
|
|
end
|
|
|
|
def close
|
|
@tar.close
|
|
@xz.close
|
|
end
|
|
|
|
def add_file fname, mode, time, body
|
|
time = Time.new time unless time.is_a? Time
|
|
@tar.add_file_simple \
|
|
"#{@dir}/#{File.basename fname}", mode: mode,
|
|
uid: 1000, gid: 1000, mtime: time.to_i, data: body
|
|
end
|
|
end
|
|
|
|
|
|
$pool = Concurrent::FixedThreadPool.new Etc.nprocessors
|
|
def post &blk
|
|
$pool.post do
|
|
begin
|
|
blk[]
|
|
rescue Exception => e
|
|
puts e, e.backtrace
|
|
exit! 1
|
|
end
|
|
end
|
|
end
|
|
|
|
def gen_set cls, job, name, normal_pat, sym_pat, exe_pat = NEVER
|
|
post do
|
|
cls.create "pkg/neptools-#{name}-#{VERSION}" do |o|
|
|
o.boilerplate
|
|
o.artifacts job, normal_pat, exe_pat
|
|
end
|
|
end
|
|
post do
|
|
cls.create "pkg/neptools-#{name}-#{VERSION}.symbols" do |o|
|
|
o.artifacts job, sym_pat
|
|
end
|
|
end
|
|
|
|
post do
|
|
cls.create "pkg/neptools-#{name}-#{VERSION}-debug" do |o|
|
|
o.boilerplate
|
|
o.artifacts job.gsub(/mode=rel/, 'mode=debug'), //, exe_pat
|
|
end
|
|
end
|
|
end
|
|
|
|
gen_set MyZip, 'architecture=arm,lua=no,mode=rel,os_compiler=vita-gcc',
|
|
'vita', /\.suprx$/, /\/[^.]+$/
|
|
gen_set MyTarXz, 'architecture=amd64,lua=lua,mode=rel,os_compiler=linux_steamrt-clang',
|
|
'linux_amd64', /\/[^.]+$/, /\.debug$/, /\/[^.]+$/
|
|
|
|
gen_set MyZip, 'architecture=x86,lua=lua,mode=rel,os_compiler=windows_vista-clang_msvc12',
|
|
'windows', /\.(exe|dll)$/, /\.pdb$/, /\.exe$/
|
|
gen_set MyZip, 'architecture=x86,lua=no,mode=rel,os_compiler=windows_vista-clang_msvc12',
|
|
'windows-nolua', /\.(exe|dll)$/, /\.pdb$/, /\.exe$/
|
|
gen_set MyZip, 'architecture=x86,lua=ljx,mode=rel,os_compiler=windows_vista-clang_msvc12',
|
|
'windows-ljx', /\.(exe|dll)$/, /\.pdb$/, /\.exe$/
|
|
|
|
$pool.shutdown
|
|
$pool.wait_for_termination
|