ci: add simple packaging script
This commit is contained in:
parent
ceb05bfa68
commit
4beca5dfb8
4 changed files with 266 additions and 83 deletions
|
|
@ -1,44 +0,0 @@
|
|||
local mesonBuild (buildName, cxx, ld, mesonOptions) = {
|
||||
kind: "pipeline",
|
||||
type: "exec",
|
||||
name: buildName,
|
||||
steps: [
|
||||
{
|
||||
environment: {
|
||||
CXX: cxx,
|
||||
CXX_LD: ld
|
||||
},
|
||||
name: "setup",
|
||||
commands: [
|
||||
"meson setup build " + mesonOptions,
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "build",
|
||||
commands: [
|
||||
"ninja -C build",
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "upload",
|
||||
commands: [
|
||||
"upload-binary " + buildName
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
[
|
||||
mesonBuild("linux-release-gcc", "gcc", "", ""),
|
||||
mesonBuild("linux-release-clang", "clang", "lld", ""),
|
||||
|
||||
mesonBuild("linux-release-intel", "/opt/intel/bin/icc", "", ""),
|
||||
mesonBuild("linux-debug-gcc", "gcc", "", "--buildtype=debug"),
|
||||
|
||||
mesonBuild("macos-release-clang", "", "", "--cross-file=/opt/meson/cross/darwin.ini"),
|
||||
mesonBuild("macos-debug-clang", "", "", "--cross-file=/opt/meson/cross/darwin.ini --buildtype=debug"),
|
||||
|
||||
mesonBuild("win32-release-msvc", "", "", "--cross-file=/opt/meson/cross/msvc.ini -Db_vscrt=mt"),
|
||||
mesonBuild("win32-debug-msvc", "", "", "--cross-file=/opt/meson/cross/msvc.ini --buildtype=debug -Db_vscrt=mtd"),
|
||||
mesonBuild("win32-release-mingw", "", "", "--cross-file=/opt/meson/cross/mingw.ini"),
|
||||
]
|
||||
81
meson.build
81
meson.build
|
|
@ -10,7 +10,7 @@ project (
|
|||
'cpp',
|
||||
|
||||
version: '4.1',
|
||||
license: 'GPL',
|
||||
license: 'MIT',
|
||||
|
||||
default_options: [
|
||||
'buildtype=release',
|
||||
|
|
@ -33,6 +33,7 @@ find_program ('hostname', required: true)
|
|||
buildCompiler = meson.get_compiler ('cpp')
|
||||
buildSystem = host_machine.system ()
|
||||
buildVersion = meson.project_version ()
|
||||
buildCount = run_command ('git', 'rev-list', '--count', 'HEAD').stdout ().strip ()
|
||||
|
||||
compilerId = buildCompiler.get_id ()
|
||||
compilerVersion = buildCompiler.version ()
|
||||
|
|
@ -46,8 +47,8 @@ isWindows = buildSystem == 'windows'
|
|||
isLinux = buildSystem == 'linux'
|
||||
isDarwin = buildSystem == 'darwin'
|
||||
|
||||
flagsLinker = []
|
||||
flagsCompiler = []
|
||||
ldflags = []
|
||||
ccflags = []
|
||||
|
||||
cdata = configuration_data()
|
||||
|
||||
|
|
@ -58,19 +59,19 @@ else
|
|||
endif
|
||||
|
||||
cdata.set ('commitHash', run_command ('git', 'rev-parse', '--short', 'HEAD').stdout ().strip ())
|
||||
cdata.set ('commitCount', run_command ('git', 'rev-list', '--count', 'HEAD').stdout ().strip ())
|
||||
cdata.set ('commitAuthor', run_command ('git', 'log', '--pretty="%ae"', '-1').stdout ().strip ())
|
||||
|
||||
cdata.set ('commitCount', buildCount)
|
||||
cdata.set ('buildVersion', buildVersion)
|
||||
cdata.set ('buildMachine', run_command ('hostname', '-f').stdout ().strip ())
|
||||
cdata.set ('buildCompiler', compilerId + ' ' + compilerVersion)
|
||||
|
||||
configure_file (input: 'inc/version.h.in', output: 'version.build.h', configuration: cdata)
|
||||
|
||||
flagsCompiler += '-DVERSION_GENERATED'
|
||||
ccflags += '-DVERSION_GENERATED'
|
||||
|
||||
if isCLang or isGCC or (isIntel and not isWindows)
|
||||
flagsCompiler += [
|
||||
ccflags += [
|
||||
'-m32',
|
||||
'-fno-threadsafe-statics',
|
||||
'-fno-exceptions',
|
||||
|
|
@ -78,29 +79,28 @@ if isCLang or isGCC or (isIntel and not isWindows)
|
|||
]
|
||||
|
||||
if not isDarwin
|
||||
flagsCompiler += [
|
||||
ccflags += [
|
||||
'-pedantic',
|
||||
]
|
||||
endif
|
||||
|
||||
if isOptimize
|
||||
flagsCompiler += '-msse3'
|
||||
ccflags += '-msse3'
|
||||
|
||||
if isCLang or isGCC and not isDarwin
|
||||
flagsCompiler += [
|
||||
if (isCLang or isGCC) and not isDarwin
|
||||
ccflags += [
|
||||
'-flto',
|
||||
'-fdata-sections',
|
||||
'-ffunction-sections'
|
||||
]
|
||||
|
||||
if isGCC
|
||||
flagsCompiler += '-fgraphite-identity'
|
||||
flagsLinker += '-flto-partition=none'
|
||||
ccflags += '-fgraphite-identity'
|
||||
ldflags += '-flto-partition=none'
|
||||
endif
|
||||
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'-flto',
|
||||
'-s',
|
||||
'-Wl,--version-script=../version_script.lds',
|
||||
'-Wl,--gc-sections'
|
||||
]
|
||||
|
|
@ -108,7 +108,7 @@ if isCLang or isGCC or (isIntel and not isWindows)
|
|||
endif
|
||||
|
||||
if isLinux
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'-m32',
|
||||
'-lm',
|
||||
'-ldl'
|
||||
|
|
@ -117,7 +117,7 @@ if isCLang or isGCC or (isIntel and not isWindows)
|
|||
endif
|
||||
|
||||
if isIntel and (isLinux or isDarwin)
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'-static-intel',
|
||||
'-no-intel-extensions'
|
||||
]
|
||||
|
|
@ -125,24 +125,24 @@ endif
|
|||
|
||||
if isLinux or isDarwin
|
||||
if isDarwin
|
||||
flagsCompiler += '-mmacosx-version-min=10.9'
|
||||
flagsLinker += [
|
||||
ccflags += '-mmacosx-version-min=10.9'
|
||||
ldflags += [
|
||||
'-dynamiclib',
|
||||
'-lstdc++',
|
||||
'-mmacosx-version-min=10.9'
|
||||
]
|
||||
else
|
||||
flagsLinker += '-static-libgcc'
|
||||
ldflags += '-static-libgcc'
|
||||
endif
|
||||
|
||||
if not isOptimize
|
||||
flagsCompiler += [
|
||||
ccflags += [
|
||||
'-g3',
|
||||
'-ggdb',
|
||||
'-DCR_DEBUG'
|
||||
]
|
||||
else
|
||||
flagsCompiler += [
|
||||
ccflags += [
|
||||
'-mtune=generic',
|
||||
'-msse3',
|
||||
'-mfpmath=sse',
|
||||
|
|
@ -155,13 +155,13 @@ if isLinux or isDarwin
|
|||
]
|
||||
|
||||
if isIntel
|
||||
flagsCompiler += [
|
||||
ccflags += [
|
||||
'-ipo',
|
||||
'-wd11076',
|
||||
'-wd11074'
|
||||
]
|
||||
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'-cxxlib-nostd',
|
||||
'-Wl,--no-undefined,-z,notext,--gc-sections',
|
||||
'-ipo'
|
||||
|
|
@ -170,57 +170,57 @@ if isLinux or isDarwin
|
|||
llvmLinker = find_program ('lld', required: false)
|
||||
|
||||
if llvmLinker.found() == true
|
||||
flagsLinker += '-fuse-ld=' + llvmLinker.path ().split ('/')[-1]
|
||||
ldflags += '-fuse-ld=' + llvmLinker.path ().split ('/')[-1]
|
||||
endif
|
||||
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'-nostdlib++',
|
||||
'-Wunused-command-line-argument',
|
||||
'-Wl,-z,notext',
|
||||
'--no-undefined'
|
||||
]
|
||||
elif isGCC and not isDarwin
|
||||
flagsLinker += '-Wl,--no-undefined'
|
||||
ldflags += '-Wl,--no-undefined'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
if isWindows and (isVC or isIntel)
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'/MACHINE:X86',
|
||||
'user32.lib',
|
||||
'ws2_32.lib'
|
||||
]
|
||||
|
||||
flagsCompiler += [
|
||||
ccflags += [
|
||||
'/TP'
|
||||
]
|
||||
|
||||
if isOptimize
|
||||
flagsCompiler += '/GL'
|
||||
flagsLinker += '/LTCG'
|
||||
ccflags += '/GL'
|
||||
ldflags += '/LTCG'
|
||||
endif
|
||||
|
||||
elif isWindows and (isCLang or isGCC)
|
||||
if isCLang
|
||||
flagsLinker += '-Wl,/MACHINE:X86'
|
||||
ldflags += '-Wl,/MACHINE:X86'
|
||||
else
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'-static-libgcc',
|
||||
'-Wl,--add-stdcall-alias'
|
||||
]
|
||||
endif
|
||||
|
||||
flagsLinker += [
|
||||
ldflags += [
|
||||
'-luser32',
|
||||
'-lws2_32'
|
||||
]
|
||||
endif
|
||||
|
||||
add_global_arguments (flagsCompiler, language: 'cpp')
|
||||
add_global_link_arguments (flagsLinker, language: 'cpp')
|
||||
add_global_arguments (ccflags, language: 'cpp')
|
||||
add_global_link_arguments (ldflags, language: 'cpp')
|
||||
|
||||
sourceFiles = files (
|
||||
sources = files (
|
||||
'src/android.cpp',
|
||||
'src/botlib.cpp',
|
||||
'src/chatlib.cpp',
|
||||
|
|
@ -242,17 +242,20 @@ includes = include_directories ([
|
|||
], is_system: true)
|
||||
|
||||
if isWindows and not isCLang
|
||||
sourceFiles += import('windows').compile_resources (
|
||||
sources += import('windows').compile_resources (
|
||||
'vc/yapb.rc',
|
||||
include_directories: includes,
|
||||
args: '-DVERSION_GENERATED'
|
||||
args: ['-DVERSION_GENERATED']
|
||||
)
|
||||
endif
|
||||
|
||||
shared_library (
|
||||
meson.project_name (),
|
||||
sourceFiles,
|
||||
sources,
|
||||
include_directories: includes,
|
||||
|
||||
gnu_symbol_visibility: 'hidden',
|
||||
name_prefix: '')
|
||||
|
||||
run_target ('package',
|
||||
command : ['python', meson.source_root() + '/package.py', '@0@.@1@'.format (buildVersion, buildCount)])
|
||||
224
package.py
Normal file
224
package.py
Normal file
|
|
@ -0,0 +1,224 @@
|
|||
#
|
||||
# YaPB - Counter-Strike Bot based on PODBot by Markus Klinge.
|
||||
# Copyright © 2004-2020 YaPB Project <yapb@jeefo.net>.
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
import os, sys, subprocess
|
||||
import locale, urllib3
|
||||
import pathlib, shutil
|
||||
import zipfile, tarfile
|
||||
import datetime, calendar
|
||||
|
||||
from github import Github
|
||||
|
||||
class BotRelease (object):
|
||||
def __init__(self):
|
||||
print ("Initializing Packaging")
|
||||
|
||||
self.workDir = os.path.join (pathlib.Path ().absolute (), 'cfg')
|
||||
self.botDir = os.path.join (self.workDir, 'addons', 'yapb')
|
||||
self.distDir = os.path.join (pathlib.Path ().absolute (), 'dist');
|
||||
|
||||
if len (sys.argv) < 2:
|
||||
raise Exception('Missing required parameters.')
|
||||
|
||||
self.version = sys.argv[1]
|
||||
|
||||
os.makedirs (self.distDir, exist_ok=True)
|
||||
|
||||
self.outFileWin32 = os.path.join (self.distDir, "yapb-{}-windows.zip".format (self.version))
|
||||
self.outFileLinux = os.path.join (self.distDir, "yapb-{}-linux.tar.xz".format (self.version))
|
||||
self.outFileMacOS = os.path.join (self.distDir, "yapb-{}-macos.zip".format (self.version))
|
||||
|
||||
self.outFileWin32Setup = self.outFileWin32.replace ("zip", "exe")
|
||||
self.win32SetupUrl = "https://github.com/yapb/setup/releases/latest/download/botsetup.exe"
|
||||
|
||||
def makeDirs (self):
|
||||
dirs = [
|
||||
'bin',
|
||||
os.path.join ('data', 'pwf'),
|
||||
os.path.join ('data', 'train'),
|
||||
os.path.join ('data', 'graph'),
|
||||
os.path.join ('data', 'logs')
|
||||
]
|
||||
|
||||
for dir in dirs:
|
||||
os.makedirs (os.path.join (self.botDir, dir), exist_ok=True)
|
||||
|
||||
def download (self, fromWhere, toFile):
|
||||
http = urllib3.PoolManager (10, headers = {"user-agent": "YaPB"})
|
||||
data = http.urlopen ('GET', fromWhere)
|
||||
|
||||
with open (toFile, "wb") as file:
|
||||
file.write (data.data)
|
||||
|
||||
def getGraph (self, name):
|
||||
file = os.path.join (self.botDir, 'data', 'graph', "{}.graph".format (name))
|
||||
url = "https://yapb.ru/files/graph/{}.graph".format (name);
|
||||
|
||||
if os.path.exists (file):
|
||||
return
|
||||
|
||||
self.download (url, file)
|
||||
|
||||
def getGraphs (self):
|
||||
print ("Downloading graphs: ")
|
||||
|
||||
files = ['as_oilrig', 'cs_747', 'cs_estate', 'cs_assault', 'cs_office',
|
||||
'cs_italy', 'cs_havana', 'cs_siege', 'cs_backalley', 'cs_militia',
|
||||
'cs_downed_cz', 'cs_havana_cz', 'cs_italy_cz', 'cs_militia_cz',
|
||||
'cs_office_cz', 'de_airstrip_cz', 'de_aztec_cz', 'de_cbble_cz',
|
||||
'de_chateau_cz', 'de_corruption_cz', 'de_dust_cz', 'de_dust2_cz',
|
||||
'de_fastline_cz', 'de_inferno_cz', 'de_piranesi_cz', 'de_prodigy_cz',
|
||||
'de_sienna_cz', 'de_stadium_cz', 'de_tides_cz', 'de_torn_cz',
|
||||
'de_truth_cz', 'de_vostok_cz', 'de_inferno', 'de_aztec', 'de_dust',
|
||||
'de_dust2', 'de_torn', 'de_storm', 'de_airstrip', 'de_piranesi',
|
||||
'de_prodigy', 'de_chateau', 'de_cbble', 'de_nuke', 'de_survivor',
|
||||
'de_vertigo', 'de_train']
|
||||
|
||||
for file in files:
|
||||
print (" " + file)
|
||||
|
||||
self.getGraph (file)
|
||||
|
||||
def unlinkBinaries (self):
|
||||
libs = ['yapb.so', 'yapb.dll', 'yapb.dylib']
|
||||
|
||||
for lib in libs:
|
||||
path = os.path.join (self.botDir, 'bin', lib)
|
||||
|
||||
if os.path.exists (path):
|
||||
os.remove (path)
|
||||
|
||||
def copyBinary (self, path):
|
||||
shutil.copy (path, os.path.join (self.botDir, 'bin'))
|
||||
|
||||
def zipDir (self, path, handle):
|
||||
length = len (path) + 1
|
||||
emptyDirs = []
|
||||
|
||||
for root, dirs, files in os.walk (path):
|
||||
emptyDirs.extend ([dir for dir in dirs if os.listdir (os.path.join (root, dir)) == []])
|
||||
|
||||
for file in files:
|
||||
filePath = os.path.join (root, file)
|
||||
handle.write (filePath, filePath[length:])
|
||||
|
||||
for dir in emptyDirs:
|
||||
dirPath = os.path.join (root, dir)
|
||||
|
||||
zif = zipfile.ZipInfo (dirPath[length:] + "/")
|
||||
handle.writestr (zif, "")
|
||||
|
||||
emptyDirs = []
|
||||
|
||||
def generateZip (self, dir):
|
||||
zipFile = zipfile.ZipFile (dir, 'w', zipfile.ZIP_DEFLATED)
|
||||
zipFile.comment = bytes (self.version, encoding = "ascii")
|
||||
|
||||
self.zipDir (self.workDir, zipFile)
|
||||
zipFile.close ()
|
||||
|
||||
def convertZipToTXZ (self, zip, txz):
|
||||
timeshift = int ((datetime.datetime.now () - datetime.datetime.utcnow ()).total_seconds ())
|
||||
|
||||
with zipfile.ZipFile (zip) as zipf:
|
||||
with tarfile.open (txz, 'w:xz') as tarf:
|
||||
for zif in zipf.infolist ():
|
||||
tif = tarfile.TarInfo (name = zif.filename)
|
||||
tif.size = zif.file_size
|
||||
tif.mtime = calendar.timegm (zif.date_time) - timeshift
|
||||
|
||||
tarf.addfile (tarinfo = tif, fileobj = zipf.open (zif.filename))
|
||||
|
||||
os.remove (zip)
|
||||
|
||||
def generateWin32 (self):
|
||||
print ("Generating Win32 ZIP")
|
||||
|
||||
binary = os.path.join ('build_x86_win32', 'yapb.dll')
|
||||
|
||||
if not os.path.exists (binary):
|
||||
return
|
||||
|
||||
self.unlinkBinaries ()
|
||||
|
||||
self.copyBinary (binary)
|
||||
self.generateZip (self.outFileWin32)
|
||||
|
||||
self.download (self.win32SetupUrl, "botsetup.exe")
|
||||
|
||||
print ("Generating Win32 EXE")
|
||||
|
||||
with open ("botsetup.exe", "rb") as sfx, open (self.outFileWin32, "rb") as zip, open (self.outFileWin32Setup, "wb") as exe:
|
||||
exe.write (sfx.read ())
|
||||
exe.write (zip.read ())
|
||||
|
||||
def generateLinux (self):
|
||||
print ("Generating Linux TXZ")
|
||||
|
||||
binary = os.path.join ('build_x86_linux', 'yapb.so');
|
||||
|
||||
if not os.path.exists (binary):
|
||||
return
|
||||
|
||||
self.unlinkBinaries ()
|
||||
self.copyBinary (binary)
|
||||
|
||||
tmpFile = "tmp.zip"
|
||||
|
||||
self.generateZip (tmpFile)
|
||||
self.convertZipToTXZ (tmpFile, self.outFileLinux)
|
||||
|
||||
def generateMac (self):
|
||||
print ("Generating macOS ZIP")
|
||||
|
||||
binary = os.path.join ('build_x86_macos', 'yapb.dylib')
|
||||
|
||||
if not os.path.exists (binary):
|
||||
return
|
||||
|
||||
self.unlinkBinaries ()
|
||||
self.copyBinary (binary)
|
||||
|
||||
self.generateZip (self.outFileMacOS)
|
||||
|
||||
def generate (self):
|
||||
self.generateWin32 ()
|
||||
self.generateLinux ()
|
||||
self.generateMac ()
|
||||
|
||||
def createRelease (self, repository, version):
|
||||
print ("Creating Github Tag")
|
||||
|
||||
releases = [self.outFileLinux, self.outFileWin32, self.outFileMacOS, self.outFileWin32Setup]
|
||||
|
||||
for release in releases:
|
||||
if not os.path.exists (release):
|
||||
return
|
||||
|
||||
releaseName = "YaPB " + version
|
||||
releaseMessage = repository.get_commits()[0].commit.message
|
||||
releaseSha = repository.get_commits()[0].sha;
|
||||
|
||||
ghr = repository.create_git_tag_and_release (tag = version, tag_message = version, release_name = releaseName, release_message = releaseMessage, type='commit', object = releaseSha, draft = False)
|
||||
|
||||
print ("Uploading packages to Github")
|
||||
|
||||
for release in releases:
|
||||
ghr.upload_asset( path = release, label = os.path.basename (release))
|
||||
|
||||
def uploadGithub (self):
|
||||
gh = Github (os.environ["GITHUB_TOKEN"])
|
||||
repo = gh.get_repo ("yapb/test")
|
||||
|
||||
self.createRelease (repo, self.version)
|
||||
|
||||
release = BotRelease ()
|
||||
|
||||
release.makeDirs ()
|
||||
release.getGraphs ()
|
||||
release.generate ()
|
||||
release.uploadGithub ()
|
||||
Loading…
Add table
Add a link
Reference in a new issue