-
Notifications
You must be signed in to change notification settings - Fork 1
265 lines (228 loc) · 9.1 KB
/
ci.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: CI
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
workflow_dispatch:
inputs:
push:
description: "Push source strings and translations to Transifex"
type: boolean
pull:
description: "Pull translations from Transifex"
type: boolean
schedule:
- cron: '0 14 * * 5'
env:
TX_CLI_VERSION: '1.6.7'
PYTHON_NEWEST: '3.12' # Latest Python version being translated
TX_PROJECT: python-newest # Project name for the latest python version
jobs:
trigger:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
all_versions: ${{ steps.version.outputs.all_versions }}
current: ${{ steps.version.outputs.current }}
old_versions: ${{ steps.version.outputs.old_versions }}
languages: ${{ steps.languages.outputs.languages }}
steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v4.1.0
- name: Set up Python 3
uses: actions/setup-python@v4.7.0
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: |
requirements.txt
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements.txt
- name: Set version variables
id: version
run: |
echo "all_versions=$(scripts/manage_versions.py all)" >> $GITHUB_OUTPUT
echo "current=$(scripts/manage_versions.py current)" >> $GITHUB_OUTPUT
echo "old_versions=$(scripts/manage_versions.py others)" >> $GITHUB_OUTPUT
- name: Check out branch ${{ steps.version.outputs.current }}
uses: actions/checkout@v4.1.0
with:
ref: ${{ steps.version.outputs.current }}
path: ${{ steps.version.outputs.current }}
- name: Set languages variable
id: languages
working-directory: ${{ steps.version.outputs.current }}
run: |
echo "languages=$(../scripts/list-langs.py)" >> $GITHUB_OUTPUT
- name: Print variables values
run: |
echo all_versions: ${{ steps.version.outputs.all_versions }}
echo current: ${{ steps.version.outputs.current }}
echo old_versions: ${{ steps.version.outputs.old_versions }}
echo languages: ${{ steps.languages.outputs.languages }}
update:
runs-on: ubuntu-latest
needs: trigger
permissions:
contents: write
strategy:
max-parallel: 1
fail-fast: false
matrix:
cpython_version: ${{fromJson(needs.trigger.outputs.all_versions)}}
# must match existent projects in Transifex
steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v4.1.0
- name: Check out ${{ matrix.cpython_version }} branch of CPython
uses: actions/checkout@v4.1.0
with:
repository: python/cpython
persist-credentials: false
ref: ${{ matrix.cpython_version }}
path: cpython
- name: Check out ${{ matrix.cpython_version }} branch of ${{ github.repository }}
uses: actions/checkout@v4.1.0
with:
ref: ${{ matrix.cpython_version }}
path: cpython/Doc/locales
- name: Set up Python 3
uses: actions/setup-python@v4.7.0
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: |
requirements.txt
cpython/Doc/requirements.txt
- name: Install Transifex CLI
working-directory: /usr/local/bin
run: |
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v${{ env.TX_CLI_VERSION }}
- name: Install dependencies
run: |
sudo apt update -y && sudo apt install gettext -y
pip3 install --upgrade pip
pip3 install -r requirements.txt -r cpython/Doc/requirements.txt
- name: Change Transifex project name if Python version != python-newest
if: ${{ matrix.cpython_version != env.PYTHON_NEWEST }}
shell: bash
run: |
ver=$(echo ${{ matrix.cpython_version }} | sed 's|\.||')
echo "TX_PROJECT=python-$ver" >> $GITHUB_ENV
echo ${{ env.TX_PROJECT }}
# required for generating .tx/config
- name: Generate POT files
working-directory: cpython/Doc
run: |
sphinx-build -E -b gettext -D gettext_compact=0 -d build/.doctrees . locales/pot
# See issue #15
- name: Patch POT files
working-directory: cpython/Doc/locales/pot
run: |
$GITHUB_WORKSPACE/scripts/remove-ilegal-strings.sh library/{codecs,re}.pot reference/lexical_analysis.pot
- name: Generate Transifex configuration file (.tx/config)
working-directory: cpython/Doc/locales
run: |
sphinx-intl create-txconfig
sphinx-intl update-txconfig-resources --pot-dir pot --locale-dir . --transifex-organization-name python-doc --transifex-project-name ${{ env.TX_PROJECT }}
sed -i '/^minimum_perc = 0$/s/0/1/' .tx/config
- name: Push source strings to Transifex
if: ${{ github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true') }}
working-directory: cpython/Doc/locales
id: tx_push
run: |
tx push --source --skip
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- name: Lock unused translations
if: steps.tx_push.outcome == 'success'
run: |
python3 scripts/lock-translations.py cpython/Doc/locales/.tx/config ${{ env.TX_PROJECT }}
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- name: Pull translations for all languages
if: ${{ github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.pull == 'true') }}
working-directory: cpython/Doc/locales
run: |
tx pull --all --translations --force
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- name: Powrap POT files and modified PO files
working-directory: cpython/Doc/locales
run: |
powrap --modified
powrap pot/{**/,}*.pot
- name: Commit and push changes
working-directory: cpython/Doc/locales
if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }}
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
git status
shopt -s globstar
git diff -I'^"POT-Creation-Date: ' --numstat **/*.po **/*.pot | cut -f3 | xargs -r git add
git add $(git ls-files -o --exclude-standard *.po *.pot) .tx/config
git diff-index --cached --quiet HEAD || { git commit -m "Update translations from ${{ env.BRANCH }}" && git push; }
propagate_translations:
runs-on: ubuntu-latest
needs: [trigger, update]
permissions:
contents: read
strategy:
max-parallel: 4
fail-fast: false
matrix:
branch: ${{fromJson(needs.trigger.outputs.old_versions)}}
language: ${{fromJson(needs.trigger.outputs.languages)}}
steps:
- name: Check out main
uses: actions/checkout@v4.1.0
- name: Check out branch ${{ needs.trigger.outputs.current }}
uses: actions/checkout@v4.1.0
with:
ref: ${{ needs.trigger.outputs.current }}
path: ${{ needs.trigger.outputs.current }}
- name: Check out branch ${{ matrix.branch }}
uses: actions/checkout@v4.1.0
with:
ref: ${{ matrix.branch }}
path: ${{ matrix.branch }}
- name: Set up Python 3
uses: actions/setup-python@v4.7.0
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: |
requirements.txt
- name: Install Transifex CLI
working-directory: /usr/local/bin
run: |
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v${{ env.TX_CLI_VERSION }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install pomerge
- name: Merge ${{ matrix.language }} translations from ${{ needs.trigger.outputs.current }} into ${{ matrix.branch }}
run: |
if test -d ${{ matrix.branch }}/${{ matrix.language }}; then
shopt -s globstar
pomerge --from-files ${{ needs.trigger.outputs.current }}/${{ matrix.language }}/**/*.po --to-files ${{ matrix.branch }}/${{ matrix.language }}/**/*.po
else
echo "Branch ${{ matrix.branch }} has no lang code ${{ matrix.language }}."
fi
- name: Push ${{ matrix.language }} translations for Python ${{ matrix.branch }} documentation to Transifex
if: ${{ github.event_name == 'schedule' ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true') }}
working-directory: ${{ matrix.branch }}
run: |
tx push -t -l ${{ matrix.language }}
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}