Move scripts into ./scripts/ folder.
This commit is contained in:
parent
f353f8bcc7
commit
03c1182f27
3 changed files with 0 additions and 0 deletions
116
scripts/create_release.py
Normal file
116
scripts/create_release.py
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
# Hey there, this is used to compile TShock on the build server.
|
||||
# Don't change it. Thanks!
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import urllib2
|
||||
import zipfile
|
||||
|
||||
cur_wd = os.getcwd()
|
||||
release_dir = os.path.join(cur_wd, "releases")
|
||||
|
||||
terraria_bin_name = "TerrariaServer.exe"
|
||||
sql_bins_names = ["Mono.Data.Sqlite.dll", "MySql.Data.dll", "MySql.Web.dll"]
|
||||
sqlite_dep = "sqlite3.dll"
|
||||
json_bin_name = "Newtonsoft.Json.dll"
|
||||
http_bin_name = "HttpServer.dll"
|
||||
tshock_bin_name = "TShockAPI.dll"
|
||||
tshock_symbols = "TShockAPI.dll.mdb"
|
||||
bcrypt_bin_name = "BCrypt.Net.dll"
|
||||
|
||||
terraria_release_bin = os.path.join(cur_wd, "TerrariaServerAPI", "bin", "Release", terraria_bin_name)
|
||||
terraria_debug_bin = os.path.join(cur_wd, "TerrariaServerAPI", "bin", "Debug", terraria_bin_name)
|
||||
sql_dep = os.path.join(cur_wd, "prebuilts")
|
||||
http_bin = os.path.join(cur_wd, "prebuilts", http_bin_name)
|
||||
json_bin = os.path.join(cur_wd, "prebuilts", json_bin_name)
|
||||
bcrypt_bin = os.path.join(cur_wd, "prebuilts", bcrypt_bin_name)
|
||||
release_bin = os.path.join(cur_wd, "TShockAPI", "bin", "Release", tshock_bin_name)
|
||||
debug_folder = os.path.join(cur_wd, "TShockAPI", "bin", "Debug")
|
||||
|
||||
|
||||
def create_release_folder():
|
||||
os.mkdir(release_dir)
|
||||
|
||||
def copy_dependencies():
|
||||
shutil.copy(http_bin, release_dir)
|
||||
shutil.copy(json_bin, release_dir)
|
||||
shutil.copy(bcrypt_bin, release_dir)
|
||||
shutil.copy(os.path.join(sql_dep, sqlite_dep), release_dir)
|
||||
for f in sql_bins_names:
|
||||
shutil.copy(os.path.join(sql_dep, f), release_dir)
|
||||
|
||||
def copy_debug_files():
|
||||
shutil.copy(terraria_debug_bin, release_dir)
|
||||
shutil.copy(os.path.join(debug_folder, tshock_bin_name), release_dir)
|
||||
shutil.copy(os.path.join(debug_folder, tshock_symbols), release_dir)
|
||||
|
||||
def copy_release_files():
|
||||
shutil.copy(terraria_release_bin, release_dir)
|
||||
shutil.copy(release_bin, release_dir)
|
||||
shutil.copy(release_bin, release_dir)
|
||||
|
||||
def create_base_zip(name):
|
||||
os.chdir(release_dir)
|
||||
zip = zipfile.ZipFile(name, "w")
|
||||
zip.write(terraria_bin_name)
|
||||
zip.write(sqlite_dep)
|
||||
zip.write(http_bin_name, os.path.join("ServerPlugins", http_bin_name))
|
||||
zip.write(json_bin_name, os.path.join("ServerPlugins", json_bin_name))
|
||||
zip.write(bcrypt_bin_name, os.path.join("ServerPlugins", bcrypt_bin_name))
|
||||
for f in sql_bins_names:
|
||||
zip.write(f, os.path.join("ServerPlugins", f))
|
||||
return zip
|
||||
|
||||
def package_release():
|
||||
copy_release_files()
|
||||
zip = create_base_zip("tshock_release.zip")
|
||||
zip.write(tshock_bin_name, os.path.join("ServerPlugins", tshock_bin_name))
|
||||
zip.close()
|
||||
os.remove(tshock_bin_name)
|
||||
os.remove(terraria_bin_name)
|
||||
os.chdir(cur_wd)
|
||||
|
||||
def package_debug():
|
||||
copy_debug_files()
|
||||
zip = create_base_zip("tshock_debug.zip")
|
||||
zip.write(tshock_bin_name, os.path.join("ServerPlugins", tshock_bin_name))
|
||||
zip.write(tshock_symbols, os.path.join("ServerPlugins", tshock_symbols))
|
||||
zip.close()
|
||||
os.remove(tshock_bin_name)
|
||||
os.remove(tshock_symbols)
|
||||
os.remove(terraria_bin_name)
|
||||
os.chdir(cur_wd)
|
||||
|
||||
def delete_files():
|
||||
os.chdir(release_dir)
|
||||
for f in sql_bins_names:
|
||||
os.remove(f)
|
||||
os.remove(sqlite_dep)
|
||||
os.remove(json_bin_name)
|
||||
os.remove(bcrypt_bin_name)
|
||||
os.remove(http_bin_name)
|
||||
os.chdir(cur_wd)
|
||||
|
||||
def update_terraria_source():
|
||||
subprocess.check_call(['/usr/bin/git', 'submodule', 'init'])
|
||||
subprocess.check_call(['/usr/bin/git', 'submodule', 'update'])
|
||||
|
||||
def build_software():
|
||||
release_proc = subprocess.Popen(['/usr/local/bin/xbuild', './TShockAPI/TShockAPI.csproj', '/p:Configuration=Release'])
|
||||
debug_proc = subprocess.Popen(['/usr/local/bin/xbuild', './TShockAPI/TShockAPI.csproj', '/p:Configuration=Debug'])
|
||||
release_proc.wait()
|
||||
debug_proc.wait()
|
||||
if (release_proc.returncode != 0):
|
||||
raise CalledProcessError(release_proc.returncode)
|
||||
if (debug_proc.returncode != 0):
|
||||
raise CalledProcessError(debug_proc.returncode)
|
||||
|
||||
if __name__ == '__main__':
|
||||
create_release_folder()
|
||||
update_terraria_source()
|
||||
copy_dependencies()
|
||||
build_software()
|
||||
package_release()
|
||||
package_debug()
|
||||
delete_files()
|
||||
105
scripts/deploy_release.py
Normal file
105
scripts/deploy_release.py
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
import requests
|
||||
import json
|
||||
import sys
|
||||
import os
|
||||
import subprocess
|
||||
import base64
|
||||
import urllib
|
||||
|
||||
create_release_url = 'https://api.github.com/repos/NyxStudios/TShock/releases'
|
||||
config_doc_get_url = 'https://tshock.atlassian.net/wiki/rest/api/content/%s?expand=body.storage,version,ancestors'
|
||||
config_doc_put_url = 'https://tshock.atlassian.net/wiki/rest/api/content/%s'
|
||||
conversion_page_url = 'https://tshock.atlassian.net/wiki/rest/api/contentbody/convert/storage'
|
||||
|
||||
config_desc_page = "3047451"
|
||||
ssc_desc_page = "39845891"
|
||||
permissions_desc_page = "3047433"
|
||||
rest_desc_page = "40632322"
|
||||
|
||||
def convert_view_to_storage(page):
|
||||
print("Converting " + str(page['id']))
|
||||
confluence_header = {"Content-Type":"application/json"}
|
||||
r = requests.post(conversion_page_url, auth=(os.environ["bamboo_confluence_username"], os.environ["bamboo_confluence_password"]), headers=confluence_header, data=json.dumps(page['body']['storage']), verify=True)
|
||||
page['body']['storage'] = json.loads(r.text)
|
||||
return page
|
||||
|
||||
def get_confluence_page(id):
|
||||
print("Fetching page " + str(id))
|
||||
confluence_header = {"Content-Type":"application/json"}
|
||||
r = requests.get(config_doc_get_url % id, auth=(os.environ["bamboo_confluence_username"], os.environ["bamboo_confluence_password"]), headers=confluence_header, verify=True)
|
||||
page = json.loads(r.text)
|
||||
return page
|
||||
|
||||
def put_confluence_page(page):
|
||||
print("Storing page " + str(page['id']))
|
||||
confluence_header = {"Content-Type":"application/json"}
|
||||
page['version']['number'] = page['version']['number'] + 1
|
||||
page = convert_view_to_storage(page)
|
||||
r = requests.put(config_doc_put_url % page['id'], auth=(os.environ["bamboo_confluence_username"], os.environ["bamboo_confluence_password"]), headers=confluence_header, data=json.dumps(page), verify=True)
|
||||
page = json.loads(r.text)
|
||||
return page
|
||||
|
||||
def update_confluence_page(id, content):
|
||||
page = get_confluence_page(id)
|
||||
page['body']['storage']['value'] = content
|
||||
page['body']['storage']['representation'] = 'wiki'
|
||||
put_confluence_page(page)
|
||||
|
||||
def read_and_update_config_on_confluence(id, file):
|
||||
#Read the Config
|
||||
config = ""
|
||||
with open(file, "r") as f:
|
||||
line = f.readline()
|
||||
while (line is not ""):
|
||||
config = config + line
|
||||
line = f.readline()
|
||||
#update confluence page
|
||||
config = config.replace("{", "\{")
|
||||
config = config.replace("}", "\}")
|
||||
config = config.replace("[", "\[")
|
||||
config = config.replace("]", "\]")
|
||||
config = config.replace("\t", " ")
|
||||
update_confluence_page(id, config)
|
||||
|
||||
#Load variables from ENV, which are put there by the bamboo build.
|
||||
branch = os.environ["GIT_BRANCH"]
|
||||
tag_name = os.environ["bamboo_tag_name"]
|
||||
name = os.environ["bamboo_release_name"]
|
||||
body = os.environ["bamboo_release_body"]
|
||||
token = os.environ["bamboo_github_oauth_password"]
|
||||
|
||||
#build release file name using the tag, stripping the 'v' off the front ie 'v.1.2.3' => '.1.2.3' resulting in a file called 'tshock.1.2.3.zip'
|
||||
release_name = 'tshock_' + tag_name[1:] + '.zip'
|
||||
|
||||
#invoke the mv command on the artifact from bamboo to the new name above
|
||||
subprocess.call('mv tshock_release.zip ' + release_name, shell=True)
|
||||
|
||||
#construct the payload for the post request to github to create the release.
|
||||
data = {'tag_name':tag_name, 'target_commitish':branch, 'name':name, 'body':body, 'draft':False, 'prerelease':False}
|
||||
#headers for the post request with our oauth token, allowing us write access
|
||||
create_headers = {'Content-Type': 'application/json', 'Authorization': 'token ' + token}
|
||||
#payload is a json string, not a strong typed json object
|
||||
json_data = json.dumps(data)
|
||||
|
||||
#make the post request, creating a release
|
||||
r = requests.post(create_release_url, data=json_data, headers=create_headers)
|
||||
#parse the response into an object
|
||||
json_response = json.loads(r.text)
|
||||
|
||||
#extract the relevant information from the object needed to attach a binary to the release created previously
|
||||
release_id = json_response['id']
|
||||
upload_url = json_response['upload_url'].rsplit('{')[0]
|
||||
|
||||
#construct the post url using the release name, as that is required by the api
|
||||
upload_url = upload_url + '?name=' + release_name
|
||||
|
||||
#headers for the post request, need to specify that our file is a zip, and how large it is
|
||||
upload_headers = {'Authorization': 'token ' + token, 'Content-Type':'application/zip', 'Content-Length':str(os.path.getsize(release_name))}
|
||||
|
||||
#upload the binary, resulting in a complete binary
|
||||
r = requests.post(upload_url, data=open(release_name, 'rb'), headers = upload_headers, verify=False)
|
||||
|
||||
read_and_update_config_on_confluence(config_desc_page, "ConfigDescriptions.txt")
|
||||
read_and_update_config_on_confluence(ssc_desc_page, "ServerSideConfigDescriptions.txt")
|
||||
read_and_update_config_on_confluence(permissions_desc_page, "PermissionsDescriptions.txt")
|
||||
read_and_update_config_on_confluence(rest_desc_page, "RestDescriptions.txt")
|
||||
17
scripts/test_release.py
Normal file
17
scripts/test_release.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import subprocess
|
||||
import shutil
|
||||
import os.path
|
||||
import zipfile
|
||||
|
||||
def generate_release():
|
||||
zip = zipfile.ZipFile("tshock_release.zip", "r")
|
||||
zip.extractall()
|
||||
|
||||
def generate_configs():
|
||||
subprocess.call(['/usr/local/bin/mono', 'TerrariaServer.exe', '-dump'])
|
||||
if not os.path.isfile('ConfigDescriptions.txt') or not os.path.isfile('PermissionsDescriptions.txt') or not os.path.isfile('ServerSideConfigDescriptions.txt') or not os.path.isfile('RestDescriptions.txt'):
|
||||
raise CalledProcessError(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
generate_release()
|
||||
generate_configs()
|
||||
Loading…
Add table
Add a link
Reference in a new issue