mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-06 09:20:43 +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
28
.github/workflows/crowdin-sync.yml
vendored
28
.github/workflows/crowdin-sync.yml
vendored
@ -11,8 +11,9 @@ jobs:
|
|||||||
name: Autosync
|
name: Autosync
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
env:
|
env:
|
||||||
CROWDIN_BASE_URL: "https://api.crowdin.com/api/v2/projects"
|
_CROWDIN_BASE_URL: "https://api.crowdin.com/api/v2/projects"
|
||||||
CROWDIN_PROJECT_ID: "308189"
|
_CROWDIN_PROJECT_ID: "308189"
|
||||||
|
_DIFF_BRANCH: "master"
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
|
uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4
|
||||||
@ -29,7 +30,7 @@ jobs:
|
|||||||
BRANCH_EXISTS=true
|
BRANCH_EXISTS=true
|
||||||
|
|
||||||
git fetch -a
|
git fetch -a
|
||||||
git switch master
|
git switch $_DIFF_BRANCH
|
||||||
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_EXISTS=false
|
BRANCH_EXISTS=false
|
||||||
git switch -c $BRANCH_NAME
|
git switch -c $BRANCH_NAME
|
||||||
@ -61,7 +62,7 @@ jobs:
|
|||||||
# 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"
|
echo "::set-output name=id::$BRANCH_ID"
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ jobs:
|
|||||||
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\": $CROWDIN_MASTER_BRANCH_ID}" | jq -r '.data.id'
|
-d "{\"branchId\": $CROWDIN_MASTER_BRANCH_ID}" | jq -r '.data.id'
|
||||||
)
|
)
|
||||||
echo "[*] Crowin translations build id: $BRANCH_ID"
|
echo "[*] Crowin translations build id: $BRANCH_ID"
|
||||||
@ -91,7 +92,7 @@ jobs:
|
|||||||
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/$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"
|
echo "[*] Build status: $BRANCH_STATUS"
|
||||||
if [[ "$BRANCH_STATUS" == "finished" ]]; then break; fi
|
if [[ "$BRANCH_STATUS" == "finished" ]]; then break; fi
|
||||||
@ -103,6 +104,8 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
sleep 15 # Wait for the build download url to become live
|
||||||
|
|
||||||
- name: Get Crowdin download URL
|
- name: Get Crowdin download URL
|
||||||
id: crowdin-download-url
|
id: crowdin-download-url
|
||||||
env:
|
env:
|
||||||
@ -112,7 +115,7 @@ jobs:
|
|||||||
# 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/$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 "[*] Crowin translations download url: $DOWNLOAD_URL"
|
||||||
echo "::set-output name=value::$DOWNLOAD_URL"
|
echo "::set-output name=value::$DOWNLOAD_URL"
|
||||||
@ -135,12 +138,11 @@ jobs:
|
|||||||
BRANCH_NAME: ${{ steps.branch.outputs.branch-name }}
|
BRANCH_NAME: ${{ steps.branch.outputs.branch-name }}
|
||||||
BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }}
|
BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }}
|
||||||
run: |
|
run: |
|
||||||
DIFF_BRANCH=master
|
|
||||||
if [[ "$BRANCH_EXISTS" == "true" ]]; then
|
if [[ "$BRANCH_EXISTS" == "true" ]]; then
|
||||||
DIFF_BRANCH=$BRANCH_NAME
|
_DIFF_BRANCH=$BRANCH_NAME
|
||||||
fi
|
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 "[*] git diff lines: ${DIFF_LEN}"
|
||||||
echo "::set-output name=num::$DIFF_LEN"
|
echo "::set-output name=num::$DIFF_LEN"
|
||||||
|
|
||||||
@ -148,11 +150,10 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
BRANCH_NAME: ${{ steps.branch.outputs.branch-name }}
|
BRANCH_NAME: ${{ steps.branch.outputs.branch-name }}
|
||||||
BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }}
|
BRANCH_EXISTS: ${{ steps.branch.outputs.branch-exists }}
|
||||||
DIFF_BRANCH: master
|
|
||||||
DIFF_LEN: ${{ steps.files-changed.outputs.num }}
|
DIFF_LEN: ${{ steps.files-changed.outputs.num }}
|
||||||
run: |
|
run: |
|
||||||
echo "=====Translations Changed====="
|
echo "=====Translations Changed====="
|
||||||
git diff --name-only origin/${DIFF_BRANCH}
|
git diff --name-only origin/${_DIFF_BRANCH}
|
||||||
echo "=============================="
|
echo "=============================="
|
||||||
|
|
||||||
if [ "$DIFF_LEN" != "0" ]; then
|
if [ "$DIFF_LEN" != "0" ]; then
|
||||||
@ -179,7 +180,8 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
if [ "$BRANCH_EXISTS" == "false" ]; then
|
if [ "$BRANCH_EXISTS" == "false" ]; then
|
||||||
echo "[*] Creating PR"
|
echo "[*] Creating PR"
|
||||||
gh pr create --title "Autosync Crowdin Translations" \
|
gh pr create --base $_DIFF_BRANCH \
|
||||||
|
--title "Autosync Crowdin Translations" \
|
||||||
--body "Autosync the updated translations"
|
--body "Autosync the updated translations"
|
||||||
else
|
else
|
||||||
echo "[*] Existing PR updated"
|
echo "[*] Existing PR updated"
|
||||||
|
Loading…
Reference in New Issue
Block a user