mirror of
https://github.com/bitwarden/browser
synced 2024-12-24 17:11:55 +01:00
Crowdin Automation Cleanup (#1148)
* adding a "global variable" syntax for env vars * switching diff branch to a testing branch instead of master * adding base branch to the PR creation * adding the diff branch to be the base branch to branch off of * switching the diff branch back to master * updating the last half of the workflow to use the new global var format
This commit is contained in:
parent
26cc36a91e
commit
9bb252f954
30
.github/workflows/crowdin-sync.yml
vendored
30
.github/workflows/crowdin-sync.yml
vendored
@ -11,8 +11,9 @@ jobs:
|
||||
name: Autosync
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
CROWDIN_BASE_URL: "https://api.crowdin.com/api/v2/projects"
|
||||
CROWDIN_PROJECT_ID: "308189"
|
||||
_CROWDIN_BASE_URL: "https://api.crowdin.com/api/v2/projects"
|
||||
_CROWDIN_PROJECT_ID: "308189"
|
||||
_DIFF_BRANCH: "master"
|
||||
steps:
|
||||
- name: Checkout repo
|
||||
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
|
||||
@ -29,7 +30,7 @@ jobs:
|
||||
BRANCH_EXISTS=true
|
||||
|
||||
git fetch -a
|
||||
git switch master
|
||||
git switch $_DIFF_BRANCH
|
||||
if [ $(git branch -a | egrep "remotes/origin/${BRANCH_NAME}$" | wc -l) -eq 0 ]; then
|
||||
BRANCH_EXISTS=false
|
||||
git switch -c $BRANCH_NAME
|
||||
@ -61,7 +62,7 @@ jobs:
|
||||
# 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'
|
||||
$_CROWDIN_BASE_URL/$_CROWDIN_PROJECT_ID/branches | jq -r '.data[0].data.id'
|
||||
)
|
||||
echo "::set-output name=id::$BRANCH_ID"
|
||||
|
||||
@ -76,7 +77,7 @@ jobs:
|
||||
curl -X POST -s \
|
||||
-H "Authorization: Bearer $CROWDIN_API_TOKEN" \
|
||||
-H "Content-Type: application/json" \
|
||||
$CROWDIN_BASE_URL/$CROWDIN_PROJECT_ID/translations/builds \
|
||||
$_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"
|
||||
@ -91,7 +92,7 @@ jobs:
|
||||
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'
|
||||
$_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
|
||||
@ -103,6 +104,8 @@ jobs:
|
||||
fi
|
||||
done
|
||||
|
||||
sleep 15 # Wait for the build download url to become live
|
||||
|
||||
- name: Get Crowdin download URL
|
||||
id: crowdin-download-url
|
||||
env:
|
||||
@ -112,7 +115,7 @@ jobs:
|
||||
# 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'
|
||||
$_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"
|
||||
@ -135,12 +138,11 @@ jobs:
|
||||
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
|
||||
_DIFF_BRANCH=$BRANCH_NAME
|
||||
fi
|
||||
|
||||
DIFF_LEN=$(git diff origin/${DIFF_BRANCH} | wc -l | xargs)
|
||||
DIFF_LEN=$(git diff origin/${_DIFF_BRANCH} | wc -l | xargs)
|
||||
echo "[*] git diff lines: ${DIFF_LEN}"
|
||||
echo "::set-output name=num::$DIFF_LEN"
|
||||
|
||||
@ -148,11 +150,10 @@ jobs:
|
||||
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}
|
||||
git diff --name-only origin/${_DIFF_BRANCH}
|
||||
echo "=============================="
|
||||
|
||||
if [ "$DIFF_LEN" != "0" ]; then
|
||||
@ -179,8 +180,9 @@ jobs:
|
||||
run: |
|
||||
if [ "$BRANCH_EXISTS" == "false" ]; then
|
||||
echo "[*] Creating PR"
|
||||
gh pr create --title "Autosync Crowdin Translations" \
|
||||
--body "Autosync the updated translations"
|
||||
gh pr create --base $_DIFF_BRANCH \
|
||||
--title "Autosync Crowdin Translations" \
|
||||
--body "Autosync the updated translations"
|
||||
else
|
||||
echo "[*] Existing PR updated"
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user