1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

Fix crowdin sync (#1122)

* fixing syntax error

* changing the way we check the number of build status tries

* adding in the Crowdin Api Token env var to the main step

* Breaking up the Crowdin update step into smaller manageable steps

* fixing env var for the download step

* fixing build id env for download

* Fixing PR branch env vars

* adding in a different way of pushing if branch already exists

* fixing the git bot user
This commit is contained in:
Joseph Flinn 2021-08-11 09:01:29 -07:00 committed by GitHub
parent 709d187498
commit b9b20bc36b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,33 +10,36 @@ jobs:
crowdin-sync: crowdin-sync:
name: Autosync name: Autosync
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04
env:
CROWDIN_BASE_URL: "https://api.crowdin.com/api/v2/projects"
CROWDIN_PROJECT_ID: "308189"
steps: steps:
- name: Checkout repo - name: Checkout repo
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
- name: Setup git config - name: Setup git config
run: | run: |
git config user.name = "GitHub Action Bot" git config user.name "github-actions"
git config user.email = "<>" git config user.email "<>"
- name: Get Crowndin Sync Branch - name: Get Crowndin Sync Branch
id: branch id: branch
run: | run: |
BRANCH_NAME=crowdin-auto-sync BRANCH_NAME=crowdin-auto-sync
BRANCH_EXISTED=true BRANCH_EXISTS=true
git fetch -a git fetch -a
git switch master git switch master
if [ $(git branch -a | egrep "remotes/origin/${BRANCH_NAME}$" | wc -l) -eq 0 ]; then if [ $(git branch -a | egrep "remotes/origin/${BRANCH_NAME}$" | wc -l) -eq 0 ]; then
BRANCH_EXISTED=false BRANCH_EXISTS=false
git switch -c $BRANCH_NAME git switch -c $BRANCH_NAME
else else
git switch $BRANCH_NAME git switch $BRANCH_NAME
fi fi
git branch git branch
echo "::set-output name=branch-existed::${BRANCH_EXISTED}" echo "::set-output name=branch-exists::$BRANCH_EXISTS"
echo "::set-output name=branch-name::${BRANCH_NAME}" echo "::set-output name=branch-name::$BRANCH_NAME"
- name: Login to Azure - name: Login to Azure
uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a uses: Azure/login@77f1b2e3fb80c0e8645114159d17008b8a2e475a
@ -50,38 +53,48 @@ jobs:
keyvault: "bitwarden-prod-kv" keyvault: "bitwarden-prod-kv"
secrets: "crowdin-api-token" secrets: "crowdin-api-token"
- name: Get Crowdin updates - name: Get Crowdin master branch id
id: crowdin-master-branch
env: env:
CROWDIN_BASE_URL="https://api.crowdin.com/api/v2/projects" CROWDIN_API_TOKEN: ${{ steps.retrieve-secrets.outputs.crowdin-api-token }}
CROWDIN_PROJECT_ID="308189"
run: | run: |
# Step 1: GET master branchId # Step 1: GET master branchId
BRANCH_ID=$( BRANCH_ID=$(
curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \ curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \
$CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/branches | jq -r '.data[0].data.id' $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/branches | jq -r '.data[0].data.id'
) )
echo "::set-output name=id::$BRANCH_ID"
- name: Get Crowdin build id
id: crowdin-build
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 # Step 2: POST Build the translations and get store build id
BUILD_ID=$( BUILD_ID=$(
curl -X POST -s \ curl -X POST -s \
-H "Authorization: Bearer $CROWDIN_API_TOKEN" \ -H "Authorization: Bearer $CROWDIN_API_TOKEN" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
$CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds \ $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds \
-d "{\"branchId\": $BRANCH_ID}" | jq -r '.data.id' -d "{\"branchId\": $CROWDIN_MASTER_BRANCH_ID}" | jq -r '.data.id'
) )
echo "::set-output name=id::$BUILD_ID"
MAX_TRIES=12 - 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 for try in {1..$MAX_TRIES}; do
BRANCH_STATUS=$( BRANCH_STATUS=$(
curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \ curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \
$CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds/$BUILD_ID | jq -r '.data.status' $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds/$CROWDIN_BUILD_ID | jq -r '.data.status'
) )
echo "[*] Build status: $BRANCH_STATUS" echo "[*] Build status: $BRANCH_STATUS"
if [[ "$BRANCH_STATUS" == "finished" ]]; then if [[ "$BRANCH_STATUS" == "finished" ]]; then break; fi
break if [[ "$try" == "$MAX_TRIES" ]]; then
fi
if [[ $try -eq $MAX_TRIES ]]; then
echo "[!] Exceeded tries: $try" echo "[!] Exceeded tries: $try"
exit 1 exit 1
else else
@ -89,24 +102,35 @@ jobs:
fi fi
done 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 # Step 4: when build is finished, get download url
DOWNLOAD_URL=$( DOWNLOAD_URL=$(
curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \ curl -s -H "Authorization: Bearer $CROWDIN_API_TOKEN" \
$CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds/$BUILD_ID/download | jq -r '.data.url' $CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds/$CROWDIN_BUILD_ID/download | jq -r '.data.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 # Step 5: download the translations via the download url
SAVE_FILE=translations.zip curl -s $CROWDIN_DOWNLOAD_URL --output $SAVE_FILE
curl -s $DOWNLOAD_URL --output $SAVE_FILE
echo "[*] Saved to: $SAVE_FILE" echo "[*] Saved to: $SAVE_FILE"
# Step 6: Unzip and cleanup
unzip -o $SAVE_FILE unzip -o $SAVE_FILE
rm $SAVE_FILE rm $SAVE_FILE
- name: Commit changes - name: Commit changes
env: env:
BRANCH_NAME: ${{ steps.branch.outputs.branch-name }} BRANCH_NAME: ${{ steps.branch.outputs.branch-name }}
BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }}
run: | run: |
echo "[*] Adding new translations" echo "[*] Adding new translations"
git add . git add .
@ -115,16 +139,21 @@ jobs:
echo "==============================" echo "=============================="
echo "[*] Committing" echo "[*] Committing"
git commit -m "Autosync Crowdin translations" git commit -m "Autosync Crowdin translations"
echo "[*] Pushing" echo "[*] Pushing"
git push -u origin $BRANCH_NAME if [ "$BRANCH_EXISTS" == "false" ]; then
git push -u origin $BRANCH_NAME
else
git push
fi
- name: Create/Update PR - name: Create/Update PR
env: env:
BRANCH_NAME: ${{ steps.cherry-pick.outputs.branch-name }} BRANCH_NAME: ${{ steps.branch.outputs.branch-name }}
BRANCH_EXISTED: ${{ steps.cherry-pick.outputs.branch-existed }} BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: | run: |
if [ "$BRANCH_EXISTED" == "false" ]; then if [ "$BRANCH_EXISTS" == "false" ]; then
echo "[*] Creating PR" echo "[*] Creating PR"
gh pr create --title "Autosync Crowdin Translations" \ gh pr create --title "Autosync Crowdin Translations" \
--body "Autosync the updated translations" --body "Autosync the updated translations"