2023-01-19 10:33:49 +01:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# SPDX-License-Identifier: LicenseRef-EliasSteurerTachiom OR AGPL-3.0-only
|
2021-08-21 12:53:19 +02:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
import shutil
|
|
|
|
import argparse
|
2023-08-24 17:17:22 +02:00
|
|
|
from pathlib import Path
|
2021-08-21 12:53:19 +02:00
|
|
|
from sys import platform
|
|
|
|
from execute_util import execute
|
|
|
|
from datetime import datetime
|
2021-08-21 13:28:32 +02:00
|
|
|
from shutil import copyfile
|
2021-08-21 12:53:19 +02:00
|
|
|
import subprocess
|
2022-08-26 15:43:50 +02:00
|
|
|
from util import cd_repo_root_path
|
|
|
|
import platform
|
2022-11-02 12:15:34 +01:00
|
|
|
from sys import stdout
|
|
|
|
|
|
|
|
stdout.reconfigure(encoding='utf-8')
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
|
|
|
|
class PublishConfig:
|
|
|
|
vdf_config_name: str
|
|
|
|
depot_config_name: str
|
|
|
|
steamcmd_path: Path
|
|
|
|
|
|
|
|
|
|
|
|
def init_publish_config():
|
|
|
|
config = PublishConfig()
|
|
|
|
|
|
|
|
root_path = cd_repo_root_path()
|
|
|
|
tools_path = os.path.join(root_path, "Tools")
|
|
|
|
contentBuiler_path = os.path.join(tools_path, "Steam/ContentBuilder/")
|
|
|
|
|
|
|
|
if platform.system() == "Windows":
|
|
|
|
config.vdf_config_name = "app_build_windows.vdf"
|
|
|
|
config.depot_config_name = "depot_build_windows.vdf"
|
|
|
|
config.steamcmd_path = os.path.join(
|
|
|
|
contentBuiler_path, "builder/steamcmd.exe")
|
|
|
|
elif platform.system() == "Darwin":
|
|
|
|
config.vdf_config_name = "app_build_mac.vdf"
|
|
|
|
config.depot_config_name = "depot_build_mac.vdf"
|
|
|
|
config.steamcmd_path = os.path.join(
|
|
|
|
contentBuiler_path, "builder_osx/steamcmd")
|
|
|
|
execute(f"chmod +x {config.steamcmd_path}")
|
|
|
|
elif platform.system() == "Linux":
|
|
|
|
config.vdf_config_name = "app_build_linux.vdf"
|
|
|
|
config.depot_config_name = "depot_build_linux.vdf"
|
|
|
|
config.steamcmd_path = os.path.join(
|
|
|
|
contentBuiler_path, "builder_linux/steamcmd.sh")
|
|
|
|
execute(f"chmod +x {config.steamcmd_path}")
|
|
|
|
|
|
|
|
return config
|
|
|
|
|
|
|
|
|
|
|
|
def check_steam_login(username: str, password: str):
|
|
|
|
config = init_publish_config()
|
|
|
|
cmd = [config.steamcmd_path, "+login", username, password, "+quit"]
|
|
|
|
|
|
|
|
try:
|
|
|
|
with subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) as process:
|
|
|
|
try:
|
|
|
|
stdout, stderr = process.communicate(
|
|
|
|
timeout=60) # 1 minute timeout
|
|
|
|
for line in stdout.splitlines():
|
|
|
|
print(line) # Print the line for debugging purposes
|
|
|
|
|
|
|
|
if "Logging in user" in line:
|
|
|
|
return True
|
|
|
|
elif "Steam Guard code" in line:
|
|
|
|
process.terminate()
|
|
|
|
return False
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
process.kill()
|
|
|
|
print("Steam login check timed out after 1 minute.")
|
|
|
|
return False
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Error during Steam login check: {e}")
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2021-08-21 12:53:19 +02:00
|
|
|
# Executes steamcmd with username and password. Changes the content of the config
|
|
|
|
# for better readability in the steam builds tab
|
|
|
|
# https://partner.steamgames.com/apps/builds/672870
|
|
|
|
|
|
|
|
def get_git_revision_short_hash():
|
|
|
|
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'])
|
|
|
|
|
|
|
|
|
2021-08-21 14:11:16 +02:00
|
|
|
def get_git_commit_text():
|
|
|
|
return subprocess.check_output(['git', 'log', '-1', '--pretty=%B'])
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
|
2022-07-24 17:56:00 +02:00
|
|
|
def publish(
|
2022-07-09 13:05:42 +02:00
|
|
|
steam_username,
|
|
|
|
steam_password,
|
|
|
|
set_live_branch_name
|
|
|
|
):
|
|
|
|
|
2022-08-26 15:43:50 +02:00
|
|
|
# Make sure the script is always started from the same folder
|
|
|
|
root_path = cd_repo_root_path()
|
|
|
|
tools_path = os.path.join(root_path, "Tools")
|
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
config = init_publish_config()
|
2021-08-21 13:17:08 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
print(f"Set steamCmd path: {config.steamcmd_path}")
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
abs_vdf_path = os.path.join(
|
|
|
|
tools_path, "Steam/steamcmd/" + config.vdf_config_name)
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2022-07-09 13:05:42 +02:00
|
|
|
if not os.path.isfile(abs_vdf_path):
|
|
|
|
print("Incorrect vdf name")
|
|
|
|
sys.exit(-1)
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2022-07-09 13:05:42 +02:00
|
|
|
file = open(abs_vdf_path, "r")
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2022-07-09 13:05:42 +02:00
|
|
|
config_content = file.read()
|
|
|
|
git_hash = get_git_revision_short_hash().decode("utf-8").replace("\n", "")
|
|
|
|
git_commit_text = get_git_commit_text().decode("utf-8").replace("\n", "")
|
2023-02-04 14:06:48 +01:00
|
|
|
# Remove ' and " that can occour it is a merge commit
|
2023-08-24 17:17:22 +02:00
|
|
|
git_commit_text = git_commit_text.replace('\"', '')
|
|
|
|
git_commit_text = git_commit_text.replace('\'', '')
|
2022-11-12 17:09:51 +01:00
|
|
|
current_date_time = datetime.now().strftime("%d/%m/%Y, %H:%M:%S")
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
build_description = "- git hash: " + git_hash + ", commit: " + \
|
|
|
|
git_commit_text + " - upload datetime: " + current_date_time
|
|
|
|
config_content = config_content.replace(
|
|
|
|
"{{BUILD_DESCRIPTION}}", build_description)
|
|
|
|
config_content = config_content.replace(
|
|
|
|
"{{SET_LIVE_ON_BRANCH}}", set_live_branch_name)
|
2022-07-09 13:05:42 +02:00
|
|
|
tmp_steam_config_foldername = "tmp_steam_config/"
|
2023-08-24 17:17:22 +02:00
|
|
|
tmp_steam_config_dir = os.path.abspath(
|
|
|
|
os.path.join(tools_path, tmp_steam_config_foldername))
|
2022-07-09 13:05:42 +02:00
|
|
|
|
|
|
|
if os.path.isdir(tmp_steam_config_dir):
|
2023-02-11 11:57:09 +01:00
|
|
|
print(f"Deleting tmp config {tmp_steam_config_dir}")
|
2022-07-09 13:05:42 +02:00
|
|
|
shutil.rmtree(tmp_steam_config_dir)
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2022-07-09 13:05:42 +02:00
|
|
|
os.mkdir(tmp_steam_config_dir)
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
f = open(os.path.abspath(tmp_steam_config_dir +
|
|
|
|
"/" + config.vdf_config_name), "w")
|
2022-07-09 13:05:42 +02:00
|
|
|
f.write(config_content)
|
|
|
|
f.close()
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2022-07-09 13:05:42 +02:00
|
|
|
print(f"Using config:\n {config_content}\n")
|
2021-08-21 13:28:32 +02:00
|
|
|
|
2022-07-09 13:05:42 +02:00
|
|
|
# We also must copy the depot file
|
2023-08-24 17:17:22 +02:00
|
|
|
abs_depot_path = os.path.join(
|
|
|
|
tools_path, "Steam/steamcmd/" + config.depot_config_name)
|
|
|
|
copyfile(abs_depot_path, tmp_steam_config_dir +
|
|
|
|
"/" + config.depot_config_name)
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
tmp_steam_config_path = "\"" + \
|
|
|
|
os.path.abspath(os.path.join(
|
|
|
|
tmp_steam_config_dir, config.vdf_config_name)) + "\""
|
2022-07-09 13:05:42 +02:00
|
|
|
|
|
|
|
print("Execute steamcmd on: " + tmp_steam_config_path)
|
2023-08-24 17:17:22 +02:00
|
|
|
execute(f"{config.steamcmd_path} +login {steam_username} {steam_password} +run_app_build {tmp_steam_config_path} +quit")
|
2022-07-09 13:05:42 +02:00
|
|
|
|
|
|
|
print("Deleting tmp config")
|
|
|
|
shutil.rmtree(tmp_steam_config_dir)
|
2021-08-21 12:53:19 +02:00
|
|
|
|
2023-08-24 17:17:22 +02:00
|
|
|
|
2022-07-09 13:05:42 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description='Publish ScreenPlay to Steam')
|
|
|
|
parser.add_argument('-steam_username', action="store", dest="steam_username", required=True,
|
|
|
|
help="Steam Username.")
|
|
|
|
parser.add_argument('-steam_password', action="store", dest="steam_password", required=True,
|
|
|
|
help="Steam Password.")
|
|
|
|
parser.add_argument('-set_live_branch_name', action="store", dest="set_live_branch_name",
|
|
|
|
help="Branch name. Defaults to internal")
|
|
|
|
parser.add_argument('-steam_config', action="store", dest="vdf_config_name",
|
|
|
|
help="Name to the .vdf config. This will use the .vdf files from the steamcmd folder.")
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
if not args.steam_username or not args.steam_password:
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if args.set_live_branch_name:
|
|
|
|
set_live_branch_name = args.set_live_branch_name
|
|
|
|
else:
|
|
|
|
set_live_branch_name = "internal"
|
|
|
|
|
2022-07-24 17:56:00 +02:00
|
|
|
publish(
|
2022-07-09 13:05:42 +02:00
|
|
|
steam_username=args.steam_username,
|
|
|
|
steam_password=args.steam_password,
|
|
|
|
set_live_branch_name=set_live_branch_name
|
2023-08-24 17:17:22 +02:00
|
|
|
)
|