Skip to content

Commit

Permalink
properly support gitlab vs github downloads and folders
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercoms committed Sep 16, 2023
1 parent 12c2390 commit 5cf8a26
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 21 deletions.
25 changes: 14 additions & 11 deletions pbpy/pbgh.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from pbpy import pbconfig
from pbpy import pbgit
from pbpy import pbunreal
from pbpy import pbinfo

gh_executable_path = ".github\\gh\\gh.exe"
chglog_executable_path = ".github\\gh\\git-chglog.exe"
glab_executable_path = ".github\\glab\\glab.exe"
chglog_config_path = ".github\\chglog.yml"
gh_executable_path = "\\git\\gh.exe"
chglog_executable_path = "\\git\\git-chglog.exe"
glab_executable_path = "\\git\\glab.exe"
chglog_config_path = "\\chglog.yml"
release_file = "RELEASE_MSG"
binary_package_name = "Binaries.zip"

Expand All @@ -32,22 +33,24 @@ def get_token_env():
else:
pbtools.error_state(f"Credential retrieval failed. Please get help from {pbconfig.get('support_channel')}")


@lru_cache()
def get_cli_executable(git_url=None):
hostname = urlparse(git_url if git_url else pbconfig.get("git_url")).hostname

if hostname == 'github.com':
return gh_executable_path
return pbinfo.format_repo_folder(gh_executable_path)
elif hostname == 'gitlab.com':
return glab_executable_path
return pbinfo.format_repo_folder(glab_executable_path)
else:
# Fall back to gitlab path as that's most likely
# what our provider will be if we can't determine
return glab_executable_path
return pbinfo.format_repo_folder(glab_executable_path)


def download_release_file(version, pattern=None, directory=None, repo=None):
cli_exec_path = get_cli_executable(repo)
repo = urlparse(repo).path

if not os.path.isfile(cli_exec_path):
pblog.error(f"CLI executable not found at {cli_exec_path}")
Expand Down Expand Up @@ -219,11 +222,11 @@ def generate_release():
pblog.info(proc.stdout)
proc = pbtools.run_with_combined_output([pbgit.get_git_executable(), "push", "origin", version])
pblog.info(proc.stdout)
if not os.path.exists(chglog_executable_path):
pbtools.error(f"git-chglog executable not found at {chglog_executable_path}")
if not os.path.exists(pbinfo.format_repo_folder(chglog_executable_path)):
pbtools.error(f"git-chglog executable not found at {pbinfo.format_repo_folder(chglog_executable_path)}")
proc = pbtools.run_with_combined_output([
chglog_executable_path,
"-c", chglog_config_path,
pbinfo.format_repo_folder(chglog_executable_path),
"-c", pbinfo.format_repo_folder(chglog_config_path),
"-o", release_file,
version
])
Expand Down
21 changes: 21 additions & 0 deletions pbpy/pbinfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from urllib.parse import urlparse
from functools import lru_cache

from pbpy import pbconfig

@lru_cache()
def get_repo_folder():
hostname = urlparse(pbconfig.get("git_url")).hostname

if hostname == 'github.com':
return ".github"
elif hostname == 'gitlab.com':
return ".gitlab"
else:
# Fall back to gitlab path as that's most likely
# what our provider will be if we can't determine
return ".gitlab"

@lru_cache()
def format_repo_folder(base):
return f"{get_repo_folder()}{base}"
2 changes: 1 addition & 1 deletion pbpy/pbpy_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ver = "0.3.0"
ver = "0.4.0"
11 changes: 6 additions & 5 deletions pbpy/pbunreal.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from pbpy import pblog
from pbpy import pbgit
from pbpy import pbuac
from pbpy import pbinfo

# Those variable values are not likely to be changed in the future, it's safe to keep them hardcoded
uev_prefix = "uev:"
Expand All @@ -45,7 +46,7 @@

engine_installation_folder_regex = [r"[0-9].[0-9]{2}.*-", r"-[0-9]{8}"]

p4merge_path = ".github/p4merge/p4merge.exe"
p4merge_path = "/p4merge/p4merge.exe"

reg_path = r"HKCU\Software\Epic Games\Unreal Engine\Builds"

Expand Down Expand Up @@ -677,7 +678,7 @@ def register_engine(version, path):
pbtools.run(["reg", "add", reg_path, "/f", "/v", version, "/t", "REG_SZ", "/d", path])
return True

longtail_path = ".github\\longtail\\longtail.exe"
longtail_path = "\\longtail\\longtail.exe"
g_command_runner = None

def init_gcs():
Expand Down Expand Up @@ -850,7 +851,7 @@ def download_engine(bundle_name=None, download_symbols=False):
# TODO: maybe cache out Saved and Intermediate folders?
# current legacy archive behavior obviously doesn't keep them for new installs, but we could now
# have to copy them out and then copy them back in
proc = pbtools.run_stream([longtail_path, "get", "--source-path", f"{gcs_bucket}lt/{bundle_name}/{version}.json", "--target-path", str(base_path), "--cache-path", f"Saved/longtail/cache/{bundle_name}"], env={"GOOGLE_APPLICATION_CREDENTIALS": "Build/credentials.json"}, logfunc=pbtools.progress_stream_log)
proc = pbtools.run_stream([pbinfo.format_repo_folder(longtail_path), "get", "--source-path", f"{gcs_bucket}lt/{bundle_name}/{version}.json", "--target-path", str(base_path), "--cache-path", f"Saved/longtail/cache/{bundle_name}"], env={"GOOGLE_APPLICATION_CREDENTIALS": "Build/credentials.json"}, logfunc=pbtools.progress_stream_log)
print("")
if proc.returncode:
pbtools.error_state(f"Failed to download engine update. Make sure your system time is synced. If this issue persists, please request help in {pbconfig.get('support_channel')}.")
Expand Down Expand Up @@ -992,7 +993,7 @@ def update_source_control():
else:
pblog.warning(f"Credential retrieval failed. Please get help from {pbconfig.get('support_channel')}.")
with ue_config("Saved/Config/Windows/EditorPerProjectUserSettings.ini") as editor_config:
p4merge = str(Path(p4merge_path).resolve())
p4merge = str(Path(pbinfo.format_repo_folder(p4merge_path)).resolve())
editor_config["/Script/UnrealEd.EditorLoadingSavingSettings"]["TextDiffToolPath"] = f"(FilePath=\"{p4merge}\")"


Expand Down Expand Up @@ -1324,7 +1325,7 @@ def build_installed_build():
bundle_name = pbconfig.get("uev_default_bundle")
project_path = get_uproject_path().parent
proc = pbtools.run_stream([
str(project_path / longtail_path), "put",
str(project_path / pbinfo.format_repo_folder(longtail_path)), "put",
"--source-path", "Windows",
"--target-path", f"{get_versionator_gsuri()}lt/{bundle_name}/{version}.json",
"--compression-algorithm", "zstd_max"
Expand Down
6 changes: 3 additions & 3 deletions pbsync/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def sync_handler(sync_val: str, repository_val=None):
pblog.warning(f"Supported Git Version: {pbconfig.get('supported_git_version')}")
pblog.warning(f"Current Git Version: {detected_git_version}")
needs_git_update = True
repo = "microsoft/git"
repo = "https://github.com/microsoft/git"
version = f"v{supported_git_version}"
if "vfs" in detected_git_version and sys.platform == "win32" or sys.platform == "darwin":
pblog.info("Auto-updating Git...")
Expand Down Expand Up @@ -150,7 +150,7 @@ def sync_handler(sync_val: str, repository_val=None):
pblog.warning(f"Current Git LFS Version: {detected_lfs_version}")
version = f"v{supported_lfs_version}"
needs_git_update = True
repo = "git-lfs/git-lfs"
repo = "https://github.com/git-lfs/git-lfs"
if os.name == "nt":
pblog.info("Auto-updating Git LFS...")
directory = "Saved/PBSyncDownloads"
Expand Down Expand Up @@ -225,7 +225,7 @@ def sync_handler(sync_val: str, repository_val=None):
version = f"v{supported_gcm_version}"
directory = "Saved/PBSyncDownloads"
download = f"gcm-win-x86-{supported_gcm_version_raw}.exe"
repo = "GitCredentialManager/git-credential-manager"
repo = "https://github.com/GitCredentialManager/git-credential-manager"
if pbgh.download_release_file(version, download, directory=directory, repo=repo) != 0:
pblog.error("Git Credential Manager auto-update failed, please download and install manually.")
webbrowser.open(f"https://github.com/{repo}/releases/download/{version}/{download}")
Expand Down
2 changes: 1 addition & 1 deletion pbsync/pbsync_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ver = "0.5.0"
ver = "0.6.0"

0 comments on commit 5cf8a26

Please sign in to comment.