Skip to content

Commit

Permalink
Improve translations processing logic take 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Danstiv committed Sep 14, 2024
1 parent be8488c commit 569eaec
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/process_translations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ jobs:
if: ${{ github.event_name == 'push' }}
env:
PROJECTS_DIR: '.'
BEFORE_PUSH_COMMIT_SHA: ${{ github.event.before }}
BASE_SHA: ${{ github.event.before }}
run: python3 scripts/process_master_changes.py
- name: Process translations
env:
PROJECTS_DIR: ${{ (github.event_name == 'push' && '.') || './pr' }}
BASE_SHA: ${{ (github.event_name == 'push' && github.event.before) || github.event.pull_request.base.sha }}
run: python3 scripts/process_translations.py
- name: 'Comment on PR'
if: ${{ github.event_name == 'pull_request_target' }}
Expand Down
23 changes: 12 additions & 11 deletions scripts/process_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
REPOSITORY_DIR = Path(".")
PROJECTS_DIR = Path(os.environ["PROJECTS_DIR"])

logger = logging.getLogger("process_master_changes")
logger = logging.getLogger("process_translations")
logger.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
Expand Down Expand Up @@ -320,6 +320,9 @@ def convert_docs_po_to_md_file(po_file):
logger.info("Converting because the po file has changed")
elif file_updated(source_md_file):
logger.info("Converting because the source file has changed")
else:
logger.info("No changes in po or source detected")
return
process = subprocess.Popen(
[
"po2md",
Expand Down Expand Up @@ -347,16 +350,14 @@ def main():
project_dirs = [i for i in f.read().split("\n") if i]
for project_dir in project_dirs:
process_project(PROJECTS_DIR / project_dir)
messages = message_manager.get_messages()
if not messages:
messages = [
"Validation and conversion completed without errors, let's wait for the review team.\n"
"Thanks for your contribution!"
]
with (REPOSITORY_DIR / "result.txt").open(
"w", encoding="utf-8", newline=""
) as f:
f.write("\n".join(messages))
messages = message_manager.get_messages()
if not messages:
messages = [
"Validation and conversion completed without errors, let's wait for the review team.\n"
"Thanks for your contribution!"
]
with (REPOSITORY_DIR / "result.txt").open("w", encoding="utf-8", newline="") as f:
f.write("\n".join(messages))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def convert_percents_to_braces(string):
def file_updated(file_path):
file_path = Path(file_path).resolve()
quoted_file_path = shlex.quote(file_path.name)
previous_commit = os.environ.get("BEFORE_PUSH_COMMIT_SHA", "HEAD~1")
previous_commit = os.environ["BASE_SHA"]
return_code = subprocess.call(
["bash", "-c", f"[[ $(git diff {previous_commit} -- {quoted_file_path}) ]]"],
cwd=str(file_path.parent),
Expand Down

0 comments on commit 569eaec

Please sign in to comment.