-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from amylizzle/downloadinstead
Download releases instead
- Loading branch information
Showing
9 changed files
with
128 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ on: | |
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- master | ||
- main | ||
push: | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,53 @@ | ||
import os | ||
import tarfile | ||
from pathlib import Path | ||
|
||
from git.repo import Repo | ||
import git | ||
import wget | ||
from od_compiler.util.compiler_logger import compile_logger | ||
|
||
|
||
def updateOD(od_repo_path: Path, clean: int = False) -> None: | ||
def updateOD(od_path: Path, clean: int = False) -> None: | ||
""" | ||
Update the OpenDream repository if it exists. If it doesn't, clone a fresh copy. | ||
""" | ||
if clean: | ||
from shutil import rmtree | ||
|
||
rmtree(od_repo_path) | ||
|
||
if Path.exists(od_repo_path): | ||
od = Repo(od_repo_path) | ||
od.remote().fetch() | ||
# We reset HEAD to the upstream commit as a faster and more reliable way to stay up to date | ||
od.head.reset(commit="origin/master", working_tree=True) | ||
else: | ||
compile_logger.info("Repo not found. Cloning from GitHub.") | ||
od = Repo.clone_from( | ||
url="https://github.com/OpenDreamProject/OpenDream.git", | ||
to_path=od_repo_path, | ||
multi_options=["--depth 1", "--recurse-submodules", "--shallow-submodules"], | ||
) | ||
|
||
compile_logger.info(f"The OpenDream repo is at: {od.head.commit.hexsha}") | ||
updateSubmodules(od_repo=od) | ||
|
||
compiler_path = od_path / "compiler.tar.gz" | ||
server_path = od_path / "server.tar.gz" | ||
tag_path = od_path / "tag" | ||
|
||
def updateSubmodules(od_repo: Repo) -> None: | ||
""" | ||
Recursively update and initialize submodules | ||
if clean: | ||
from shutil import rmtree | ||
|
||
od_repo: OpenDream repository with the submodules | ||
""" | ||
for submodule in od_repo.submodules: | ||
submodule.update(init=True, recursive=True) | ||
compile_logger.info(f"{submodule.name} is at: {submodule.hexsha}") | ||
rmtree(od_path) | ||
|
||
if not Path.exists(od_path): | ||
os.mkdir(od_path) | ||
remote_heads = git.cmd.Git().ls_remote("https://github.com/OpenDreamProject/OpenDream/", heads=True) | ||
tag_path.touch(exist_ok=True) | ||
with open(str(tag_path), "r+") as tag: | ||
if tag.readline() == remote_heads: | ||
compile_logger.info("OpenDream is already up to date.") | ||
return | ||
else: | ||
tag.seek(0) | ||
tag.write(remote_heads) | ||
|
||
if compiler_path.exists(): | ||
os.remove(compiler_path) | ||
if server_path.exists(): | ||
os.remove(server_path) | ||
wget.download( | ||
"https://github.com/OpenDreamProject/OpenDream/releases/download/latest/DMCompiler_linux-x64.tar.gz", | ||
str(compiler_path), | ||
) | ||
wget.download( | ||
"https://github.com/OpenDreamProject/OpenDream/releases/download/latest/OpenDreamServer_linux-x64.tar.gz", | ||
str(server_path), | ||
) | ||
|
||
with tarfile.open(str(compiler_path), "r:gz") as tar: | ||
tar.extractall(path=od_path) | ||
with tarfile.open(str(server_path), "r:gz") as tar: | ||
tar.extractall(path=od_path) | ||
compile_logger.info(f"The OpenDream repo is at: {remote_heads}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters