Browse Source

Added dummy upload and download with branch upload

CPK 5 months ago
parent
commit
adf9c30d9a

+ 44 - 3
.github/workflows/localization.yml

@@ -14,15 +14,56 @@ on:
         - Upload only
         - Upload only
   pull_request:
   pull_request:
 
 
+permissions:
+  contents: write
+
 jobs:
 jobs:
-  Compare-Upload:
+  compare-upload:
+    name: "Compare local English"
     runs-on: ubuntu-latest
     runs-on: ubuntu-latest
+    outputs:
+      hasChanges: ${{ steps.upload-comparison.outputs.HAS_CHANGES }}
     if: ${{ inputs.mode != 'Download only' }}
     if: ${{ inputs.mode != 'Download only' }}
     steps:
     steps:
       - name: Checkout
       - name: Checkout
         uses: actions/[email protected]
         uses: actions/[email protected]
-      - name: Compare English
+      - name: Compare local reference
+        id: upload-comparison
         run: python .github/workflows/localization/upload-comparison.py
         run: python .github/workflows/localization/upload-comparison.py
         env:
         env:
           POEDITOR_API_KEY: ${{ secrets.POEDITORKEY }}
           POEDITOR_API_KEY: ${{ secrets.POEDITORKEY }}
-          POEDITOR_PROJECT_ID: ${{ secrets.POEDITORPROJECT }}
+          POEDITOR_PROJECT_ID: ${{ secrets.POEDITORPROJECT }}
+
+  upload:
+    name: "Upload English changes"
+    runs-on: ubuntu-latest
+    needs: compare-upload
+    environment: poeditor
+    if: needs.compare-upload.outputs.hasChanges
+    steps:
+      - name: Upload Changes
+        run: echo "Changes would be uploaded here!"
+
+  download:
+    name: "Download changes"
+    runs-on: ubuntu-latest
+    if: ${{ inputs.mode != 'Upload only' }}
+    steps:
+      - name: Checkout
+        uses: actions/[email protected]
+      - name: Download languages
+        id: download-languages
+        run: python .github/workflows/localization/download-languages.py
+        env:
+          POEDITOR_API_KEY: ${{ secrets.POEDITORKEY }}
+          POEDITOR_PROJECT_ID: ${{ secrets.POEDITORPROJECT }}
+      - name: Create branch
+        if: steps.download-languages.outputs.HAS_CHANGES
+        run: git checkout -B "language-update-${{ github.run_number }}-${{ github.run_attempt }}"
+      - name: Add changes and commit
+        run: |
+          git add -A
+          git commit -m "Update language files"
+      - name: Push changes
+        run: |
+          git push

+ 10 - 1
.github/workflows/localization/download-languages.py

@@ -6,6 +6,7 @@ from datetime import datetime
 
 
 API_KEY = os.getenv("POEDITOR_API_KEY")
 API_KEY = os.getenv("POEDITOR_API_KEY")
 PROJECT_ID = os.getenv("POEDITOR_PROJECT_ID")
 PROJECT_ID = os.getenv("POEDITOR_PROJECT_ID")
+GITHUB_OUTPUT = os.getenv('GITHUB_OUTPUT')
 
 
 # POEditor API URLs
 # POEditor API URLs
 EXPORT_API_URL = "https://api.poeditor.com/v2/projects/export"
 EXPORT_API_URL = "https://api.poeditor.com/v2/projects/export"
@@ -92,8 +93,10 @@ def update_locale_file(language):
     if updated_data != local_data:
     if updated_data != local_data:
         write_ordered_json(file_path, updated_data)
         write_ordered_json(file_path, updated_data)
         print(f"✅ Updated locale file for {language['name']} ({language['code']}).")
         print(f"✅ Updated locale file for {language['name']} ({language['code']}).")
+        return False
     else:
     else:
         print(f"✅ No changes for {language['name']} ({language['code']}).")
         print(f"✅ No changes for {language['name']} ({language['code']}).")
+        return False
 
 
 def fetch_languages_list():
 def fetch_languages_list():
     """
     """
@@ -154,11 +157,17 @@ def main():
     if "Languages" not in localization_data:
     if "Languages" not in localization_data:
         print("::error::'Languages' key not found in LocalizationData.json")
         print("::error::'Languages' key not found in LocalizationData.json")
         return
         return
+    
+    has_changes = False
 
 
     for language in localization_data["Languages"]:
     for language in localization_data["Languages"]:
         if language.get("code", "").lower() == "en":
         if language.get("code", "").lower() == "en":
             continue
             continue
-        update_locale_file(language)
+        if update_locale_file(language):
+            has_changes = True
+
+    with open(GITHUB_OUTPUT, "a") as f:
+        f.write(f"HAS_CHANGES={str(has_changes).lower()}")
 
 
     # Update lastUpdated field in LocalizationData.json
     # Update lastUpdated field in LocalizationData.json
     update_localization_data(languages_updates)
     update_localization_data(languages_updates)

+ 6 - 3
.github/workflows/localization/upload-comparison.py

@@ -4,6 +4,7 @@ import requests
 
 
 API_KEY = os.getenv("POEDITOR_API_KEY")
 API_KEY = os.getenv("POEDITOR_API_KEY")
 PROJECT_ID = os.getenv("POEDITOR_PROJECT_ID")
 PROJECT_ID = os.getenv("POEDITOR_PROJECT_ID")
+GITHUB_OUTPUT = os.getenv('GITHUB_OUTPUT')
 
 
 API_URL = "https://api.poeditor.com/v2/projects/export"
 API_URL = "https://api.poeditor.com/v2/projects/export"
 LANGUAGE = "en"
 LANGUAGE = "en"
@@ -70,8 +71,6 @@ def print_group(title, items):
         print("::endgroup::")
         print("::endgroup::")
 
 
 def main():
 def main():
-    print("");
-
     remote_json = fetch_poeditor_json()
     remote_json = fetch_poeditor_json()
     if remote_json is None:
     if remote_json is None:
         print("::error::Failed to fetch POEditor en.json")
         print("::error::Failed to fetch POEditor en.json")
@@ -80,8 +79,12 @@ def main():
     local_json = load_local_json()
     local_json = load_local_json()
     
     
     modifications, additions, deletions = compare_json(local_json, remote_json)
     modifications, additions, deletions = compare_json(local_json, remote_json)
+    has_changes = (modifications or additions or deletions)
+
+    with open(GITHUB_OUTPUT, "a") as f:
+        f.write(f"HAS_CHANGES={str(has_changes).lower()}")
 
 
-    if not (modifications or additions or deletions):
+    if not has_changes:
         print("✅ No changes detected. Local and remote are in sync.")
         print("✅ No changes detected. Local and remote are in sync.")
     else:
     else:
         print_group("Key(s) Modified", modifications)
         print_group("Key(s) Modified", modifications)