11#!/usr/bin/env python3
22
3- ###################################
4- # ZEN automatic deployment script #
5- # =============================== #
6- # This is not meant to be run #
7- # directly! #
8- ###################################
9-
103import os
114import sys
12- import shutil
135import traceback
146import subprocess as sp
7+ import difflib
158from github import Github
169
17- TRANSLATIONISSUE = 73
18- TRANSLATIONBODY = """**[Translation Guide](https://ace3.acemod.org/wiki/development/how-to-translate-ace3.html)**
19- {}
20- """
10+ # Path to stringtablediag.py
11+ STRINGTABLEDIAG_PATH = os .path .join ("tools" , "stringtablediag.py" )
12+ if not os .path .isfile (STRINGTABLEDIAG_PATH ):
13+ print (f"❌ Error: { STRINGTABLEDIAG_PATH } not found." )
14+ print (" Hint: Ensure that the repository contains 'tools/stringtablediag.py' and that you ran 'actions/checkout'." )
15+ sys .exit (1 )
16+
17+ def generate_markdown ():
18+ """Runs stringtablediag.py and returns enhanced markdown output."""
19+ result = sp .run (
20+ ["python3" , STRINGTABLEDIAG_PATH , "--markdown" ],
21+ stdout = sp .PIPE ,
22+ stderr = sp .PIPE ,
23+ text = True ,
24+ check = True
25+ )
26+ return result .stdout
27+
28+ def update_translations (repo , issue_number ):
29+ new_body = generate_markdown ()
2130
22- REPOUSER = "OverlordZorn"
23- REPONAME = "immersion-cigs-rewrite"
24- REPOPATH = "{}/{}" .format (REPOUSER ,REPONAME )
31+ issue = repo .get_issue (issue_number )
32+ old_body = issue .body or ""
2533
34+ if old_body .strip () == new_body .strip ():
35+ print ("ℹ️ Translation issue is already up to date. No changes made." )
36+ return
2637
27- def update_translations (repo ):
28- diag = sp .check_output (["python3" , "tools/stringtablediag.py" , "--markdown" ])
29- diag = str (diag , "utf-8" )
30- issue = repo .get_issue (TRANSLATIONISSUE )
31- issue .edit (body = TRANSLATIONBODY .format (diag ))
38+ # Show diff
39+ diff = difflib .unified_diff (
40+ old_body .splitlines (),
41+ new_body .splitlines (),
42+ fromfile = "current_issue" ,
43+ tofile = "new_issue" ,
44+ lineterm = ""
45+ )
46+ print ("📝 Changes detected in translation issue:" )
47+ print ("\n " .join (diff ))
3248
49+ # Update issue
50+ issue .edit (body = new_body )
51+ print ("✅ Translation issue updated." )
3352
3453def main ():
35- print ( "Obtaining token ..." )
54+ # Get GitHub token
3655 try :
3756 token = os .environ ["GH_TOKEN" ]
38- repo = Github (token ).get_repo (REPOPATH )
39- except :
40- print ("Could not obtain token." )
41- print (traceback .format_exc ())
42- return 1
43- else :
44- print ("Token sucessfully obtained." )
57+ except KeyError :
58+ print ("❌ Error: GH_TOKEN environment variable not set." )
59+ sys .exit (1 )
4560
46- print ( " \n Updating translation issue ..." )
61+ # Get translation issue number
4762 try :
48- update_translations ( repo )
49- except :
50- print ("Failed to update translation issue ." )
51- print ( traceback . format_exc () )
52- return 1
53- else :
54- print ( "Translation issue successfully updated." )
63+ translation_issue = int ( os . environ [ "TRANSLATION_ISSUE" ] )
64+ except KeyError :
65+ print ("❌ Error: TRANSLATION_ISSUE environment variable not set ." )
66+ sys . exit ( 1 )
67+ except ValueError :
68+ print ( f"❌ Error: TRANSLATION_ISSUE must be an integer, got ' { os . environ [ 'TRANSLATION_ISSUE' ] } '." )
69+ sys . exit ( 1 )
5570
56- return 0
71+ # Get repo info
72+ github_repo = os .getenv ("GITHUB_REPOSITORY" )
73+ if not github_repo :
74+ print ("❌ Error: GITHUB_REPOSITORY environment variable not set." )
75+ sys .exit (1 )
76+ user , repo_name = github_repo .split ("/" )
5777
78+ # Connect to GitHub
79+ try :
80+ repo = Github (token ).get_repo (f"{ user } /{ repo_name } " )
81+ except Exception :
82+ print ("❌ Could not obtain repo object from GitHub." )
83+ print (traceback .format_exc ())
84+ sys .exit (1 )
85+
86+ print (f"\n 📝 Updating translation issue #{ translation_issue } ..." )
87+ try :
88+ update_translations (repo , translation_issue )
89+ except Exception :
90+ print ("❌ Failed to update translation issue." )
91+ print (traceback .format_exc ())
92+ sys .exit (1 )
5893
5994if __name__ == "__main__" :
60- sys . exit ( main () )
95+ main ()
0 commit comments