From e5aa08b2e0457a54a9d82df57569d01bacd14e0c Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 14:41:11 -0700 Subject: [PATCH 1/9] rewriting the crowdin sync workflow with the crowdin github action that I missed existed... --- .github/workflows/crowdin-sync.yml | 175 ++++------------------------- 1 file changed, 20 insertions(+), 155 deletions(-) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index c645bdc6666..48cc717b8ba 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -10,37 +10,10 @@ jobs: crowdin-sync: name: Autosync runs-on: ubuntu-20.04 - env: - CROWDIN_BASE_URL: "https://api.crowdin.com/api/v2/projects" - CROWDIN_PROJECT_ID: "268134" steps: - name: Checkout repo uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 - - name: Setup git config - run: | - git config user.name "github-actions" - git config user.email "<>" - - - name: Get Crowndin Sync Branch - id: branch - run: | - BRANCH_NAME=crowdin-auto-sync - BRANCH_EXISTS=true - - git fetch -a - git switch master - if [ $(git branch -a | egrep "remotes/origin/${BRANCH_NAME}$" | wc -l) -eq 0 ]; then - BRANCH_EXISTS=false - git switch -c $BRANCH_NAME - else - git switch $BRANCH_NAME - fi - git branch - - echo "::set-output name=branch-exists::$BRANCH_EXISTS" - echo "::set-output name=branch-name::$BRANCH_NAME" - - name: Login to Azure uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a with: @@ -53,135 +26,27 @@ jobs: keyvault: "bitwarden-prod-kv" secrets: "crowdin-api-token" - - name: Get Crowdin master branch id - id: crowdin-master-branch - env: - CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }} + - name: Update crowdin config run: | - # Step 1: GET master branchId - BRANCH_ID=$( - curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \ - $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/branches | jq -r '.data[0].data.id' - ) - echo "[*] Crowin master branch id: $BRANCH_ID" - echo "::set-output name=id::$BRANCH_ID" + echo "project_id_env: CROWDIN_PROJECT_ID" >> crowdin.yml + echo "api_token_env: CROWDIN_API_TOKEN" >> crowdin.yml - - name: Get Crowdin build id - id: crowdin-build + - name: Download translations + uses: actions/checkout@e39093fd75daae7859c68eded4b43d42ec78d8ea env: - CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }} - CROWDIN_MASTER_BRANCH_ID: ${{ steps.crowdin-master-branch.outputs.id }} - run: | - # Step 2: POST Build the translations and get store build id - BUILD_ID=$( - curl -X POST -s \ - -H "Authorization: Bearer $CROWDIN_API_TOKEN" \ - -H "Content-Type: application/json" \ - $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds \ - -d "{\"branchId\": $CROWDIN_MASTER_BRANCH_ID}" | jq -r '.data.id' - ) - echo "[*] Crowin translations build id: $BRANCH_ID" - echo "::set-output name=id::$BUILD_ID" - - - name: Wait for Crowdin build to finish - env: - MAX_TRIES: 12 - CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }} - CROWDIN_BUILD_ID: ${{ steps.crowdin-build.outputs.id }} - run: | - for try in {1..$MAX_TRIES}; do - BRANCH_STATUS=$( - curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \ - $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds/$CROWDIN_BUILD_ID | jq -r '.data.status' - ) - echo "[*] Build status: $BRANCH_STATUS" - if [[ "$BRANCH_STATUS" == "finished" ]]; then break; fi - if [[ "$try" == "$MAX_TRIES" ]]; then - echo "[!] Exceeded tries: $try" - exit 1 - else - sleep 5 - fi - done - - - name: Get Crowdin download URL - id: crowdin-download-url - env: - CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }} - CROWDIN_BUILD_ID: ${{ steps.crowdin-build.outputs.id }} - run: | - # Step 4: when build is finished, get download url - DOWNLOAD_URL=$( - curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \ - $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds/$CROWDIN_BUILD_ID/download | jq -r '.data.url' - ) - echo "[*] Crowin translations download url: $DOWNLOAD_URL" - echo "::set-output name=value::$DOWNLOAD_URL" - - - name: Download Crowdin translations - env: - CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }} - CROWDIN_DOWNLOAD_URL: ${{ steps.crowdin-download-url.outputs.value }} - SAVE_FILE: "translations.zip" - run: | - # Step 5: download the translations via the download url - curl -s $CROWDIN_DOWNLOAD_URL --output $SAVE_FILE - echo "[*] Saved to: $SAVE_FILE" - unzip -o $SAVE_FILE - rm $SAVE_FILE - - - name: Check changes - id: files-changed - env: - BRANCH_NAME: ${{ steps.branch.outputs.branch-name }} - BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }} - run: | - DIFF_BRANCH=master - if [[ "$BRANCH_EXISTS" == "true" ]]; then - DIFF_BRANCH=$BRANCH_NAME - fi - - DIFF_LEN=$(git diff origin/${DIFF_BRANCH} | wc -l | xargs) - echo "[*] git diff lines: ${DIFF_LEN}" - echo "::set-output name=num::$DIFF_LEN" - - - name: Commit changes - env: - BRANCH_NAME: ${{ steps.branch.outputs.branch-name }} - BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }} - DIFF_BRANCH: master - DIFF_LEN: ${{ steps.files-changed.outputs.num }} - run: | - echo "=====Translations Changed=====" - git diff --name-only origin/${DIFF_BRANCH} - echo "==============================" - - if [ "$DIFF_LEN" != "0" ]; then - echo "[*] Adding new translations" - git add . - echo "[*] Committing" - git commit -m "Autosync Crowdin translations" - echo "[*] Pushing" - if [ "$BRANCH_EXISTS" == "false" ]; then - git push -u origin $BRANCH_NAME - else - git push - fi - else - echo "[*] No new docs" - fi - - - name: Create/Update PR - if: ${{ steps.files-changed.outputs.num }} != 0 - env: - BRANCH_NAME: ${{ steps.branch.outputs.branch-name }} - BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - if [ "$BRANCH_EXISTS" == "false" ]; then - echo "[*] Creating PR" - gh pr create --title "Autosync Crowdin Translations" \ - --body "Autosync the updated translations" - else - echo "[*] Existing PR updated" - fi + CROWDIN_PROJECT_ID: "268134" + CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }} + with: + config: crowdin.yml + crowdin_branch_name: master + upload_source: false + upload_translations: false + download_translations: true + github_user_name: "github-actions" + github_user_email: "<>" + commit_message: "Autosync the updated translations" + create_pull_request: true + pull_request_title: "Autosync Crowdin Translations" + pull_request_body: "Autosync the updated translations" + From c2fc0cb8f35e9d630ed2eac709dcf0a7f56e0181 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 14:43:03 -0700 Subject: [PATCH 2/9] switching the base git branch --- .github/workflows/crowdin-sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index 48cc717b8ba..025f77ed4ea 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -49,4 +49,5 @@ jobs: create_pull_request: true pull_request_title: "Autosync Crowdin Translations" pull_request_body: "Autosync the updated translations" + pull_request_base_branch_name: crowdin-testing-1.51.1 From e973b7fe9ea1bf03a0bc0e5e2d1e3ca74aba2880 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 14:46:08 -0700 Subject: [PATCH 3/9] switching the action that is being used --- .github/workflows/crowdin-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index 025f77ed4ea..1e1ae50b22e 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -32,7 +32,7 @@ jobs: echo "api_token_env: CROWDIN_API_TOKEN" >> crowdin.yml - name: Download translations - uses: actions/checkout@e39093fd75daae7859c68eded4b43d42ec78d8ea + uses: actions/crowdin@e39093fd75daae7859c68eded4b43d42ec78d8ea env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CROWDIN_PROJECT_ID: "268134" From c9b9e8175a8b7f33f63595fe0d6ef00c9d58745f Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 14:47:16 -0700 Subject: [PATCH 4/9] fixing the crowdin action name --- .github/workflows/crowdin-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index 1e1ae50b22e..7123d8a2a08 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -32,7 +32,7 @@ jobs: echo "api_token_env: CROWDIN_API_TOKEN" >> crowdin.yml - name: Download translations - uses: actions/crowdin@e39093fd75daae7859c68eded4b43d42ec78d8ea + uses: crowdin/github-action@e39093fd75daae7859c68eded4b43d42ec78d8ea env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CROWDIN_PROJECT_ID: "268134" From 1d905d76f9b0173d5b61c47d4d3471ae87de840a Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 14:49:08 -0700 Subject: [PATCH 5/9] expanding the crowdin tanslation download --- .github/workflows/crowdin-sync.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index 7123d8a2a08..bbc9831b521 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -43,6 +43,7 @@ jobs: upload_source: false upload_translations: false download_translations: true + push_translations: false github_user_name: "github-actions" github_user_email: "<>" commit_message: "Autosync the updated translations" @@ -50,4 +51,5 @@ jobs: pull_request_title: "Autosync Crowdin Translations" pull_request_body: "Autosync the updated translations" pull_request_base_branch_name: crowdin-testing-1.51.1 + debug_mode: true From f0484dc4fb503bd34d4e65941604ea9be74402b2 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 15:00:56 -0700 Subject: [PATCH 6/9] trying some other parameters in the crowin action --- .github/workflows/crowdin-sync.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index bbc9831b521..05ebacf1109 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -40,10 +40,9 @@ jobs: with: config: crowdin.yml crowdin_branch_name: master - upload_source: false + upload_sources: false upload_translations: false download_translations: true - push_translations: false github_user_name: "github-actions" github_user_email: "<>" commit_message: "Autosync the updated translations" @@ -51,5 +50,3 @@ jobs: pull_request_title: "Autosync Crowdin Translations" pull_request_body: "Autosync the updated translations" pull_request_base_branch_name: crowdin-testing-1.51.1 - debug_mode: true - From 1170779a98a2f37b4bce6bccf1f4ceeacbb190d1 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 15:02:43 -0700 Subject: [PATCH 7/9] adding in the git branch --- .github/workflows/crowdin-sync.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index 05ebacf1109..43ad6d4a56b 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -46,6 +46,7 @@ jobs: github_user_name: "github-actions" github_user_email: "<>" commit_message: "Autosync the updated translations" + localization_branch_name: crowdin-auto-sync create_pull_request: true pull_request_title: "Autosync Crowdin Translations" pull_request_body: "Autosync the updated translations" From e401a5236566f2a749f21223d5177aea38b7b19b Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Wed, 25 Aug 2021 15:24:26 -0700 Subject: [PATCH 8/9] settling on this workflow after testing --- .github/workflows/crowdin-sync.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index 43ad6d4a56b..fc703956dd2 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -26,11 +26,6 @@ jobs: keyvault: "bitwarden-prod-kv" secrets: "crowdin-api-token" - - name: Update crowdin config - run: | - echo "project_id_env: CROWDIN_PROJECT_ID" >> crowdin.yml - echo "api_token_env: CROWDIN_API_TOKEN" >> crowdin.yml - - name: Download translations uses: crowdin/github-action@e39093fd75daae7859c68eded4b43d42ec78d8ea env: @@ -50,4 +45,3 @@ jobs: create_pull_request: true pull_request_title: "Autosync Crowdin Translations" pull_request_body: "Autosync the updated translations" - pull_request_base_branch_name: crowdin-testing-1.51.1 From f8b362b109c038ac6b1d99c03ab2d33ebb6e3f15 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Thu, 26 Aug 2021 08:17:17 -0700 Subject: [PATCH 9/9] updating the project id env --- .github/workflows/crowdin-sync.yml | 3 ++- crowdin.yml | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/crowdin-sync.yml b/.github/workflows/crowdin-sync.yml index fc703956dd2..1adcb6144b2 100644 --- a/.github/workflows/crowdin-sync.yml +++ b/.github/workflows/crowdin-sync.yml @@ -10,6 +10,8 @@ jobs: crowdin-sync: name: Autosync runs-on: ubuntu-20.04 + env: + _CROWDIN_PROJECT_ID: "268134" steps: - name: Checkout repo uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 @@ -30,7 +32,6 @@ jobs: uses: crowdin/github-action@e39093fd75daae7859c68eded4b43d42ec78d8ea env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CROWDIN_PROJECT_ID: "268134" CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }} with: config: crowdin.yml diff --git a/crowdin.yml b/crowdin.yml index b4ec8e7dd23..4aa8bb7bad7 100644 --- a/crowdin.yml +++ b/crowdin.yml @@ -1,3 +1,5 @@ +project_id_env: _CROWDIN_PROJECT_ID +api_token_env: CROWDIN_API_TOKEN files: - source: /src/_locales/en/messages.json translation: /src/_locales/%two_letters_code%/%original_file_name%