Skip to content

Commit a7701eb

Browse files
committed
ci: add Transifex translation and source push workflow
1 parent c6201ca commit a7701eb

1 file changed

Lines changed: 98 additions & 28 deletions

File tree

Lines changed: 98 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,125 @@
1+
12
name: Push Translations to Transifex
23

34
on:
5+
push:
6+
branches:
7+
- "3.15"
8+
paths:
9+
- "**/*.po"
10+
411
workflow_dispatch:
512
inputs:
6-
version:
7-
description: "Python documentation version"
13+
push_translations:
14+
description: "Push Punjabi translations to Transifex"
815
required: true
9-
type: choice
10-
options:
11-
- "3.13"
12-
- "3.14"
13-
- "3.15"
14-
default: "3.15"
16+
type: boolean
17+
default: true
18+
push_sources:
19+
description: "Generate and push CPython source templates"
20+
required: true
21+
type: boolean
22+
default: false
1523

1624
permissions:
1725
contents: read
1826

27+
concurrency:
28+
group: transifex-push-${{ github.ref }}
29+
cancel-in-progress: false
30+
1931
jobs:
2032
push-translations:
33+
name: Push Punjabi translations
34+
if: github.actor != 'github-actions[bot]' && (github.event_name == 'push' || inputs.push_translations)
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- name: Checkout translation repository
39+
uses: actions/checkout@v4
40+
with:
41+
persist-credentials: false
42+
43+
- name: Install Transifex CLI
44+
working-directory: /usr/local/bin
45+
run: |
46+
curl -fsSL https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v1.6.16
47+
48+
- name: Push Punjabi translations
49+
env:
50+
TX_TOKEN: ${{ secrets.TX_TOKEN }}
51+
run: |
52+
tx push --translation --languages pa --use-git-timestamps
53+
54+
push-sources:
55+
name: Generate and push source templates
56+
needs: push-translations
57+
if: ${{ always() && github.event_name == 'workflow_dispatch' && inputs.push_sources && (needs.push-translations.result == 'success' || needs.push-translations.result == 'skipped') }}
2158
runs-on: ubuntu-latest
2259

2360
steps:
24-
- uses: actions/checkout@v4
61+
- name: Checkout translation repository
62+
uses: actions/checkout@v4
2563
with:
26-
ref: ${{ inputs.version }}
27-
fetch-depth: 0
64+
persist-credentials: false
2865

29-
- uses: actions/setup-python@v5
66+
- name: Checkout CPython 3.15
67+
uses: actions/checkout@v4
3068
with:
31-
python-version: "3.x"
69+
repository: python/cpython
70+
ref: "3.15"
71+
path: cpython
72+
persist-credentials: false
3273

33-
- name: Install Dependencies
74+
- name: Set up Python
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: "3.12"
78+
79+
- name: Install documentation build dependencies
3480
run: |
3581
sudo apt-get update
3682
sudo apt-get install -y gettext
37-
pip install requests cogapp polib transifex-python sphinx-intl blurb six
38-
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash
39-
working-directory: /usr/local/bin
83+
python -m pip install -r cpython/Doc/requirements.txt
4084
41-
- name: Recreate Transifex configuration
85+
- name: Generate gettext source templates
4286
run: |
43-
curl -O https://raw.githubusercontent.com/python-docs-translations/transifex-automations/master/sample-workflows/transifex-util.py
44-
chmod +x transifex-util.py
45-
./transifex-util.py recreate_tx_config \
46-
--language pa \
47-
--project-slug python-newest \
48-
--version ${{ inputs.version }}
49-
env:
50-
TX_TOKEN: ${{ secrets.TX_TOKEN }}
87+
make -C cpython/Doc gettext
88+
test -d cpython/Doc/build/gettext
89+
mkdir -p gettext
90+
cp -a cpython/Doc/build/gettext/. gettext/
91+
92+
- name: Validate configured source templates
93+
run: |
94+
python - <<'PY'
95+
import configparser
96+
from pathlib import Path
97+
98+
config = configparser.ConfigParser()
99+
if not config.read(".tx/config"):
100+
raise SystemExit("ERROR: .tx/config could not be read")
51101
52-
- name: Push translations to Transifex
53-
run: tx push --translation --languages pa --use-git-timestamps
102+
missing = []
103+
for section in config.sections():
104+
source = config.get(section, "source_file", fallback="").strip()
105+
if source and not Path(source).is_file():
106+
missing.append(f"{section}: {source}")
107+
108+
if missing:
109+
print("Missing source templates:")
110+
print("\n".join(missing))
111+
raise SystemExit(1)
112+
113+
print("All configured source templates exist.")
114+
PY
115+
116+
- name: Install Transifex CLI
117+
working-directory: /usr/local/bin
118+
run: |
119+
curl -fsSL https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v1.6.16
120+
121+
- name: Push source templates
54122
env:
55123
TX_TOKEN: ${{ secrets.TX_TOKEN }}
124+
run: |
125+
tx push --source --skip

0 commit comments

Comments
 (0)