Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions cores/flycast/intl/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@
DIR_PATH = os.path.dirname(os.path.realpath(__file__))
YAML_PATH = os.path.join(DIR_PATH, 'crowdin.yaml')

# Apply Crowdin API Key
# Apply non-sensitive Crowdin config changes (core name only).
# Do NOT write API token into YAML; provide it via environment variable at runtime.
with open(YAML_PATH, 'r') as crowdin_config_file:
crowdin_config = crowdin_config_file.read()
crowdin_config = re.sub(r'"api_token": "_secret_"',
f'"api_token": "{API_KEY}"',
crowdin_config, 1)
crowdin_config = re.sub(r'/_core_name_',
f'/{CORE_NAME}'
, crowdin_config)
with open(YAML_PATH, 'w') as crowdin_config_file:
crowdin_config_file.write(crowdin_config)

crowdin_env = os.environ.copy()
crowdin_env['CROWDIN_PERSONAL_TOKEN'] = API_KEY

try:
# Download Crowdin CLI
jar_name = 'crowdin-cli.jar'
Expand All @@ -59,8 +60,8 @@
shutil.rmtree(jar_dir)

print('upload source & translations *.json')
subprocess.run(['java', '-jar', jar_path, 'upload', 'sources', '--config', YAML_PATH])
subprocess.run(['java', '-jar', jar_path, 'upload', 'translations', '--config', YAML_PATH])
subprocess.run(['java', '-jar', jar_path, 'upload', 'sources', '--config', YAML_PATH], env=crowdin_env)
subprocess.run(['java', '-jar', jar_path, 'upload', 'translations', '--config', YAML_PATH], env=crowdin_env)

print('wait for crowdin server to process data')
time.sleep(10)
Expand Down Expand Up @@ -108,12 +109,9 @@
workflow.write(workflow_config)

except Exception as e:
# Try really hard to reset Crowdin API Key
# Revert non-sensitive YAML mutation (core name placeholder).
with open(YAML_PATH, 'r') as crowdin_config_file:
crowdin_config = crowdin_config_file.read()
crowdin_config = re.sub(r'"api_token": ".*?"',
'"api_token": "_secret_"',
crowdin_config, 1)

# TODO this is NOT safe!
crowdin_config = re.sub(re.escape(f'/{CORE_NAME}'),
Expand Down
Loading