-
-
Notifications
You must be signed in to change notification settings - Fork 535
172 lines (156 loc) · 6.95 KB
/
crowdin_download_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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Crowdin - Download Translations
on:
# Scheduled run once a day
schedule:
- cron: '0 2 * * *'
# Run after:
# - "Upload Base" workflow completes
workflow_run:
workflows: ["Crowdin - Upload Sources"]
types:
- completed
# Support running manually
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-master
jobs:
crowdin-download-translations:
if: github.repository == 'Warzone2100/warzone2100'
permissions:
contents: read
runs-on: ubuntu-latest
environment: crowdin_sync
steps:
- name: Install gettext
env:
DEBIAN_FRONTEND: noninteractive
run: sudo apt-get -y install gettext
# Get a token using a GitHub App that has appropriate permissions *and* will trigger subsequent CI workflows
# (Since we want to run normal CI passes to catch translation string format errors that break builds)
- name: Get GH App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.WZ_CROWDIN_SYNC_GH_APP_ID }}
private-key: ${{ secrets.WZ_CROWDIN_SYNC_GH_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: "warzone2100"
- name: Checkout
uses: actions/checkout@v4
with:
ref: 'master'
token: ${{ steps.app-token.outputs.token }}
persist-credentials: true
- name: Prep local branches
id: configbranches
run: |
git fetch --prune
if [ -n "$(git show-ref origin/l10n_master)" ]; then
# has l10n_master branch
git checkout "l10n_master"
echo "CHECK_EXISTING=true" >> $GITHUB_OUTPUT
else
# no pre-existing l10n_master branch
echo "CHECK_EXISTING=false" >> $GITHUB_OUTPUT
exit 0
fi
# Switch back to master branch
git checkout -qf master
- name: Download Translations from Crowdin
uses: crowdin/github-action@v2
with:
config: 'crowdin.yml'
upload_sources: false
upload_translations: false
download_translations: true
localization_branch_name: 'l10n_master'
crowdin_branch_name: 'master'
push_translations: false
#commit_message: 'New Crowdin translations'
create_pull_request: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CROWDIN_PROJECT_ID: ${{ vars.CROWDIN_PROJECT_ID }}
CROWDIN_PERSONAL_TOKEN: ${{ secrets.CROWDIN_PERSONAL_TOKEN }}
- name: Fixup ownership
if: success() && (github.repository == 'Warzone2100/warzone2100')
run: |
sudo chown -R $(whoami) ./po
cd po
ls -al
- name: Cleanup .po files
if: success() && (github.repository == 'Warzone2100/warzone2100')
run: |
# 1.) Cleanup downloaded po (fixing up potential formatting differences and removing comments)
# For warzone2100.pot:
find po -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/cleanup-downloaded-po.sh 'po/warzone2100.pot' '{}' ';'
# For warzone2100_guide.pot:
find po/guide -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/cleanup-downloaded-po.sh 'po/guide/warzone2100_guide.pot' '{}' ';'
# 2.) Cleanup untranslated .po files
# For warzone2100.pot:
find po -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/check_po_base_unchanged.sh 'po/warzone2100.pot' '{}' ';' | xargs -r0 -I {} rm -v "{}"
# For warzone2100_guide.pot:
find po/guide -name '*.po' -type f -maxdepth 1 \
-exec \
.ci/githubactions/check_po_base_unchanged.sh 'po/guide/warzone2100_guide.pot' '{}' ';' | xargs -r0 -I {} rm -v "{}"
- name: Publish any changes to translations to l10n_master branch
if: success() && (github.repository == 'Warzone2100/warzone2100')
id: pushupdates
env:
CHECK_EXISTING_TRANSLATION_BRANCH: ${{ steps.configbranches.outputs.CHECK_EXISTING }}
run: |
git config user.name "github-actions[bot]"
git config user.email "<41898282+github-actions[bot]@users.noreply.github.com>"
# Add modified files (ignoring po header modifications):
echo "::group::Add modified files"
git difftool --dir-diff --extcmd=.ci/githubactions/crowdin_download_diff.sh | xargs -d '\n' git add
echo "::endgroup::"
# Add untracked (new) files:
echo "::group::Add untracked files"
git ls-files -z --others --exclude-standard | xargs -0 git add
echo "::endgroup::"
echo "Debug output:"
git status
echo "Commit changes:"
git commit -m "New Crowdin translations" || { echo "PROCESS_PR=false" >> $GITHUB_OUTPUT && exit 0; }
NEW_COMMIT_ID="$(git rev-parse HEAD)"
echo "New commit: ${NEW_COMMIT_ID}"
# Check if there are actual changes compared to the commit already pushed on the l10n_master branch
if [[ "${CHECK_EXISTING_TRANSLATION_BRANCH}" == "true" ]]; then
TRANSLATION_COMMIT_ID="$(git rev-parse l10n_master)"
echo "Current translation branch commit: ${TRANSLATION_COMMIT_ID}"
git diff --unified=0 ${NEW_COMMIT_ID}~..${NEW_COMMIT_ID} > l10n_temp_1.patch
git diff --unified=0 ${TRANSLATION_COMMIT_ID}~..${TRANSLATION_COMMIT_ID} > l10n_temp_2.patch
diff --brief --unified=1 \
--ignore-matching-lines='^[-+]"POT-Creation-Date: .*"' \
--ignore-matching-lines='^[-+]"PO-Revision-Date: .*"' \
--ignore-matching-lines='^[-+]"Last-Translator: .*"' \
--ignore-matching-lines='^index .*\.\..* .*' \
l10n_temp_1.patch l10n_temp_2.patch \
&& DIFF_RET=$? || DIFF_RET=$?
if [ $DIFF_RET -eq 0 ]; then
# Inputs are the same (ignoring header changes that aren't relevant)
echo "No pertinent changes - skipping force-push"
echo "PROCESS_PR=false" >> $GITHUB_OUTPUT
exit 0
fi
rm l10n_temp_1.patch
rm l10n_temp_2.patch
fi
echo "Pushing changes to l10n_master branch"
git push -f origin master:l10n_master
echo "PROCESS_PR=true" >> $GITHUB_OUTPUT
- name: Create Pull Request to update translations (if needed)
if: success() && (github.repository == 'Warzone2100/warzone2100') && (steps.pushupdates.outputs.PROCESS_PR == 'true')
id: cpr
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
GH_REPO: ${{ github.repository }}
run: |
gh pr create --base "master" --head "l10n_master" --title "New Crowdin translations" --body "New Crowdin translations sync (Auto-generated)" --label "automated pr" || echo "Seems like PR already exists?"