Skip to content

Commit 2dbc487

Browse files
committed
ci: generate Transifex config before pushing translations
1 parent a7701eb commit 2dbc487

1 file changed

Lines changed: 84 additions & 6 deletions

File tree

‎.github/workflows/transifex-push.yml‎

Lines changed: 84 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ concurrency:
2828
group: transifex-push-${{ github.ref }}
2929
cancel-in-progress: false
3030

31+
env:
32+
TX_CLI_VERSION: "1.6.16"
33+
TX_PROJECT: python-newest
34+
TX_LANGUAGE: pa
35+
CPYTHON_VERSION: "3.15"
36+
3137
jobs:
3238
push-translations:
3339
name: Push Punjabi translations
@@ -40,16 +46,75 @@ jobs:
4046
with:
4147
persist-credentials: false
4248

49+
- name: Set up Python
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: "3.12"
53+
54+
- name: Install configuration dependencies
55+
run: |
56+
sudo apt-get update
57+
sudo apt-get install -y gettext
58+
python -m pip install requests cogapp polib transifex-python sphinx-intl blurb six
59+
60+
- name: Generate Transifex configuration
61+
run: |
62+
curl -fsSLO https://raw.githubusercontent.com/python-docs-translations/transifex-automations/main/sample-workflows/transifex-util.py
63+
chmod +x transifex-util.py
64+
./transifex-util.py recreate_tx_config \
65+
--language "$TX_LANGUAGE" \
66+
--project-slug "$TX_PROJECT" \
67+
--version "$CPYTHON_VERSION"
68+
69+
- name: Validate custom builtins resource mappings
70+
run: |
71+
python - <<'PY'
72+
import configparser
73+
from pathlib import Path
74+
75+
path = Path(".tx/config")
76+
if not path.is_file():
77+
raise SystemExit("ERROR: .tx/config was not generated")
78+
79+
config = configparser.ConfigParser()
80+
config.read(path)
81+
82+
expected = {
83+
"builtins--constants",
84+
"builtins--exceptions",
85+
"builtins--functions",
86+
"builtins--index",
87+
"builtins--stdtypes",
88+
"builtins--threadsafety",
89+
"builtins--time-complexity",
90+
}
91+
92+
resources = {
93+
section.rsplit(":r:", 1)[-1]
94+
for section in config.sections()
95+
if ":r:" in section
96+
}
97+
missing = expected - resources
98+
99+
if missing:
100+
raise SystemExit(
101+
"ERROR: generated config is missing custom builtins resources: "
102+
+ ", ".join(sorted(missing))
103+
)
104+
105+
print("All seven custom builtins resource mappings are present.")
106+
PY
107+
43108
- name: Install Transifex CLI
44109
working-directory: /usr/local/bin
45110
run: |
46-
curl -fsSL https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v1.6.16
111+
curl -fsSL https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- "v${TX_CLI_VERSION}"
47112
48113
- name: Push Punjabi translations
49114
env:
50115
TX_TOKEN: ${{ secrets.TX_TOKEN }}
51116
run: |
52-
tx push --translation --languages pa --use-git-timestamps
117+
tx push --translation --languages "$TX_LANGUAGE" --use-git-timestamps
53118
54119
push-sources:
55120
name: Generate and push source templates
@@ -63,7 +128,7 @@ jobs:
63128
with:
64129
persist-credentials: false
65130

66-
- name: Checkout CPython 3.15
131+
- name: Checkout CPython source
67132
uses: actions/checkout@v4
68133
with:
69134
repository: python/cpython
@@ -81,6 +146,7 @@ jobs:
81146
sudo apt-get update
82147
sudo apt-get install -y gettext
83148
python -m pip install -r cpython/Doc/requirements.txt
149+
python -m pip install requests cogapp polib transifex-python sphinx-intl blurb six
84150
85151
- name: Generate gettext source templates
86152
run: |
@@ -89,15 +155,27 @@ jobs:
89155
mkdir -p gettext
90156
cp -a cpython/Doc/build/gettext/. gettext/
91157
158+
- name: Generate Transifex configuration
159+
run: |
160+
curl -fsSLO https://raw.githubusercontent.com/python-docs-translations/transifex-automations/main/sample-workflows/transifex-util.py
161+
chmod +x transifex-util.py
162+
./transifex-util.py recreate_tx_config \
163+
--language "$TX_LANGUAGE" \
164+
--project-slug "$TX_PROJECT" \
165+
--version "$CPYTHON_VERSION"
166+
92167
- name: Validate configured source templates
93168
run: |
94169
python - <<'PY'
95170
import configparser
96171
from pathlib import Path
97172
173+
path = Path(".tx/config")
174+
if not path.is_file():
175+
raise SystemExit("ERROR: .tx/config was not generated")
176+
98177
config = configparser.ConfigParser()
99-
if not config.read(".tx/config"):
100-
raise SystemExit("ERROR: .tx/config could not be read")
178+
config.read(path)
101179
102180
missing = []
103181
for section in config.sections():
@@ -116,7 +194,7 @@ jobs:
116194
- name: Install Transifex CLI
117195
working-directory: /usr/local/bin
118196
run: |
119-
curl -fsSL https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v1.6.16
197+
curl -fsSL https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- "v${TX_CLI_VERSION}"
120198
121199
- name: Push source templates
122200
env:

0 commit comments

Comments
 (0)