forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (101 loc) · 3.91 KB
/
sync_translations.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Sync Translations
on:
workflow_dispatch:
# We use a machine account PAT from secrets so workflows are triggered
# the default token is not needed and should be fully restricted
permissions: {}
jobs:
sync_translations:
name: 'Sync Translations with Crowdin'
timeout-minutes: 20
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.MACHINE_ACCOUNT_PAT }}
ref: 'main'
fetch-depth: 0
- name: Credential Prep
run: |
echo "CROWDIN_APIv2_PAT=${{ secrets.CROWDIN_APIv2_PAT }}" >> $GITHUB_ENV
shell: bash
- name: GIT Setup
run: |
git config --global user.name 'AnkiDroid Translations'
git config --global user.email '[email protected]'
git checkout -b i18n_sync
git reset --hard origin/main
shell: bash
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies and build
run: |
cd ./tools/localization
yarn
yarn build
- name: Push translation sources to crowdin
run: |
cd ./tools/localization
yarn start upload
- name: Pull translation updates from crowdin
run: |
cd ./tools/localization
yarn start download
- name: Extract downloaded ankidroid.zip file
run: |
cd ./tools/localization
yarn start extract
- name: Update translation to AnkiDroid res
run: |
cd ./tools/localization
yarn start update
- name: Commit changes
run: |
git add docs/marketing/localized_description AnkiDroid/src/main/res
git commit -am 'Updated strings from Crowdin'
git push --set-upstream origin +i18n_sync
echo "The results of the sync are on the i18n_sync branch, PR them from there for merge."
echo "https://github.com/ankidroid/Anki-Android/compare/i18n_sync?expand=1"
- name: Check if there are strings changes
id: tr_check
run: |
git checkout i18n_sync
COMMITS_COUNT=`git rev-list --count HEAD ^main`
if [ "$COMMITS_COUNT" -gt 0 ]; then
echo "HAS_CHANGES=true" >> $GITHUB_OUTPUT
else
echo "HAS_CHANGES=false" >> $GITHUB_OUTPUT
fi
- name: Create PR for strings changes if needed
if: ${{ steps.tr_check.outputs.HAS_CHANGES }}
uses: actions/github-script@v7
with:
github-token: ${{ secrets.MACHINE_ACCOUNT_PAT }}
script: |
const now = new Date();
// Date format used: YYYY/MM/DD HH:MM , UTC time(ex: 2023/01/13 08:38)
const formattedDate =
now.getUTCFullYear() + "/" +
("0" + (now.getUTCMonth() + 1)).slice(-2) + "/" +
("0" + now.getUTCDate()).slice(-2) + " " +
("0" + now.getUTCHours()).slice(-2) + ":" +
("0" + now.getUTCMinutes()).slice(-2);
try {
await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: "Updated strings from Crowdin " + formattedDate,
head: "i18n_sync",
base: "main",
body: "Contains the newest strings changes from Crowdin.\n\nhttps://crowdin.com/project/ankidroid/activity-stream\n\n[Re-sync translations](https://github.com/ankidroid/Anki-Android/actions/workflows/sync_translations.yml)",
maintainer_can_modify: true
});
} catch(err) {
if (err.status === 422) {
console.log("A PR containing translations sync already exists!");
} else {
console.log("Unexpected error creating pull request: " + err);
throw err;
}
}