Skip to content

Commit

Permalink
Output translation archive from CI, see #12
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Mar 18, 2023
1 parent a0e717d commit f6d4e2e
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,36 @@ def seven_zip_extract(input_path, outputDir=None):

call(args)

def seven_zip_compress(input_path, output_path):
args = ["7z", "a", "-md=512m", output_path, input_path, "-y"]

call(args)


def get_chapter_name_and_translation_from_git_tag():
returned_chapter_name = None
translation = False

def get_chapter_name_from_git_tag():
if GIT_TAG is None:
raise Exception(
"'github_actions' was selected, but environment variable GIT_REF was not set - are you sure you're running this script from Github Actions?"
"'github_actions' was selected, but environment variable GITHUB_REF was not set - are you sure you're running this script from Github Actions?"
)
else:
# Look for the chapter name to build in the git tag
tag_fragments = [x.lower() for x in re.split("[\W_]", GIT_REF)]

if "all" in tag_fragments:
return "all"
returned_chapter_name = "all"
else:
for chapter_name in chapter_to_build_variants.keys():
if chapter_name.lower() in tag_fragments:
return chapter_name
returned_chapter_name = chapter_name
break

if "translation" in tag_fragments:
translation = True

return None
return returned_chapter_name, translation


def get_build_variants(selected_chapter: str) -> List[BuildVariant]:
Expand Down Expand Up @@ -244,18 +256,23 @@ def save(self):
args = parser.parse_args()

force_download = args.force_download

# NOTE: For now, translation archive output is always enabled, as most of the time this script will be used for translators
translation = args.translation

# Get chapter name from git tag if "github_actions" specified as the chapter
chapter_name = args.chapter
if chapter_name == "github_actions":
chapter_name = get_chapter_name_from_git_tag()
chapter_name, translation = get_chapter_name_and_translation_from_git_tag()
if chapter_name is None:
print(
f">>>> WARNING: No chapter name (or 'all') was found in git tag {GIT_TAG} - skipping building .assets"
)
exit(0)

# NOTE: For now, translation archive output is always enabled, as most of the time this script will be used for translators
translation = True

# Get a list of build variants (like 'onikakushi 5.2.2f1 win') depending on commmand line arguments
build_variants = get_build_variants(chapter_name)
build_variants_list = "\n - ".join([b.get_build_command() for b in build_variants])
Expand Down Expand Up @@ -347,3 +364,11 @@ def save(self):
if build_variant.translation_default:
destination_default_sharedassets = os.path.join(translation_data_dir, "sharedassets0.assets")
shutil.copyfile(source_sharedassets, destination_default_sharedassets)

if translation:
containing_folder = "output"
output_path = "output/translation.7z"
if os.path.exists(output_path):
os.remove(output_path)

seven_zip_compress('output/translation', output_path)

0 comments on commit f6d4e2e

Please sign in to comment.