Skip to content

Commit adf6305

Browse files
Copilotm-aciek
andauthored
Use actions/checkout for language repo; resolve translation branch once in prepare
Agent-Logs-Url: https://github.com/m-aciek/python-docs-offline/sessions/22650f24-fed8-48df-870d-6d2777a9e279 Co-authored-by: m-aciek <9288014+m-aciek@users.noreply.github.com>
1 parent 26518ab commit adf6305

1 file changed

Lines changed: 64 additions & 189 deletions

File tree

.github/workflows/build.yaml

Lines changed: 64 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ jobs:
6262
outputs:
6363
dist_version: ${{ steps.get-version.outputs.dist_version }}
6464
major_minor: ${{ steps.get-version.outputs.major_minor }}
65+
translation_ref: ${{ steps.resolve-translation.outputs.translation_ref }}
66+
translation_repository: ${{ steps.resolve-translation.outputs.translation_repository }}
6567
steps:
6668
- uses: actions/setup-python@master
6769
with:
@@ -75,36 +77,24 @@ jobs:
7577
echo "dist_version=$(python tools/extensions/patchlevel.py --short)" >> "$GITHUB_OUTPUT"
7678
echo "major_minor=$(python -c 'from tools.extensions.patchlevel import get_version_info; print(get_version_info()[0])')" >> "$GITHUB_OUTPUT"
7779
working-directory: ./Doc
78-
build-html:
79-
needs: prepare
80-
runs-on: ubuntu-latest
81-
steps:
82-
- uses: actions/setup-python@master
83-
with:
84-
python-version: ${{ inputs.python_version }}
85-
- uses: actions/checkout@master
86-
with:
87-
repository: ${{ inputs.repository }}
88-
ref: ${{ inputs.reference }}
89-
- name: Sync translation sources
80+
- name: Resolve translation branch
81+
id: resolve-translation
9082
if: ${{ inputs.language != 'en' }}
9183
env:
9284
LANGUAGE_TAG: ${{ inputs.language }}
93-
TARGET_VERSION: ${{ needs.prepare.outputs.major_minor }}
85+
MAJOR_MINOR: ${{ steps.get-version.outputs.major_minor }}
9486
run: |
9587
python - <<'PY'
9688
import bisect
9789
import os
98-
import pathlib
9990
import re
10091
import subprocess
101-
92+
10293
language = os.environ["LANGUAGE_TAG"]
103-
target_version = os.environ["TARGET_VERSION"]
94+
target_version = os.environ["MAJOR_MINOR"]
10495
repo_tag = language.replace("_", "-").lower()
10596
repo_url = f"https://github.com/python/python-docs-{repo_tag}.git"
106-
output_file = os.environ["GITHUB_OUTPUT"]
107-
97+
10898
remote_branches = subprocess.check_output(
10999
["git", "ls-remote", "--heads", repo_url], text=True
110100
)
@@ -117,20 +107,33 @@ jobs:
117107
)
118108
if not branches:
119109
raise SystemExit(f"No numeric translation branches found for {repo_url}")
120-
121110
branch_tuples = [tuple(map(int, value.split("."))) for value in branches]
122111
target_tuple = tuple(map(int, target_version.split(".")))
123112
index = bisect.bisect_left(branch_tuples, target_tuple)
124113
chosen = branches[index] if index < len(branches) else branches[-1]
125-
126-
destination = pathlib.Path("Doc") / "locale" / language / "LC_MESSAGES"
127-
destination.parent.mkdir(parents=True, exist_ok=True)
128-
subprocess.check_call(
129-
["git", "clone", "--branch", chosen, "--single-branch", repo_url, str(destination)]
130-
)
131-
with open(output_file, "a", encoding="utf-8") as file:
132-
file.write(f"translation_branch={chosen}\n")
114+
115+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as file:
116+
file.write(f"translation_ref={chosen}\n")
117+
file.write(f"translation_repository=python/python-docs-{repo_tag}\n")
133118
PY
119+
build-html:
120+
needs: prepare
121+
runs-on: ubuntu-latest
122+
steps:
123+
- uses: actions/setup-python@master
124+
with:
125+
python-version: ${{ inputs.python_version }}
126+
- uses: actions/checkout@master
127+
with:
128+
repository: ${{ inputs.repository }}
129+
ref: ${{ inputs.reference }}
130+
- name: Checkout translation sources
131+
if: ${{ inputs.language != 'en' }}
132+
uses: actions/checkout@master
133+
with:
134+
repository: ${{ needs.prepare.outputs.translation_repository }}
135+
ref: ${{ needs.prepare.outputs.translation_ref }}
136+
path: Doc/locale/${{ inputs.language }}/LC_MESSAGES
134137
- id: build-settings
135138
env:
136139
LANGUAGE_TAG: ${{ inputs.language }}
@@ -140,7 +143,7 @@ jobs:
140143
import json
141144
import os
142145
import shlex
143-
146+
144147
language = os.environ["LANGUAGE_TAG"]
145148
config_sphinxopts = json.loads(os.environ["SPHINXOPTS_JSON"])
146149
common = []
@@ -153,7 +156,7 @@ jobs:
153156
]
154157
artifact_suffix = "" if language == "en" else f"-{language}"
155158
pdf = [*common, *config_sphinxopts]
156-
159+
157160
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as file:
158161
file.write(f"artifact_suffix={artifact_suffix}\n")
159162
file.write(f"common_sphinxopts={shlex.join(common)}\n")
@@ -196,45 +199,13 @@ jobs:
196199
with:
197200
repository: ${{ inputs.repository }}
198201
ref: ${{ inputs.reference }}
199-
- name: Sync translation sources
202+
- name: Checkout translation sources
200203
if: ${{ inputs.language != 'en' }}
201-
env:
202-
LANGUAGE_TAG: ${{ inputs.language }}
203-
TARGET_VERSION: ${{ needs.prepare.outputs.major_minor }}
204-
run: |
205-
python - <<'PY'
206-
import bisect
207-
import os
208-
import pathlib
209-
import re
210-
import subprocess
211-
212-
language = os.environ["LANGUAGE_TAG"]
213-
target_version = os.environ["TARGET_VERSION"]
214-
repo_tag = language.replace("_", "-").lower()
215-
repo_url = f"https://github.com/python/python-docs-{repo_tag}.git"
216-
remote_branches = subprocess.check_output(
217-
["git", "ls-remote", "--heads", repo_url], text=True
218-
)
219-
branches = sorted(
220-
{
221-
match.group(1)
222-
for match in re.finditer(r"refs/heads/([0-9]+\.[0-9]+)$", remote_branches, re.M)
223-
},
224-
key=lambda value: tuple(map(int, value.split("."))),
225-
)
226-
if not branches:
227-
raise SystemExit(f"No numeric translation branches found for {repo_url}")
228-
branch_tuples = [tuple(map(int, value.split("."))) for value in branches]
229-
target_tuple = tuple(map(int, target_version.split(".")))
230-
index = bisect.bisect_left(branch_tuples, target_tuple)
231-
chosen = branches[index] if index < len(branches) else branches[-1]
232-
destination = pathlib.Path("Doc") / "locale" / language / "LC_MESSAGES"
233-
destination.parent.mkdir(parents=True, exist_ok=True)
234-
subprocess.check_call(
235-
["git", "clone", "--branch", chosen, "--single-branch", repo_url, str(destination)]
236-
)
237-
PY
204+
uses: actions/checkout@master
205+
with:
206+
repository: ${{ needs.prepare.outputs.translation_repository }}
207+
ref: ${{ needs.prepare.outputs.translation_ref }}
208+
path: Doc/locale/${{ inputs.language }}/LC_MESSAGES
238209
- id: build-settings
239210
env:
240211
LANGUAGE_TAG: ${{ inputs.language }}
@@ -244,7 +215,7 @@ jobs:
244215
import json
245216
import os
246217
import shlex
247-
218+
248219
language = os.environ["LANGUAGE_TAG"]
249220
config_sphinxopts = json.loads(os.environ["SPHINXOPTS_JSON"])
250221
common = []
@@ -257,7 +228,7 @@ jobs:
257228
]
258229
artifact_suffix = "" if language == "en" else f"-{language}"
259230
pdf = [*common, *config_sphinxopts]
260-
231+
261232
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as file:
262233
file.write(f"artifact_suffix={artifact_suffix}\n")
263234
file.write(f"common_sphinxopts={shlex.join(common)}\n")
@@ -300,45 +271,13 @@ jobs:
300271
with:
301272
repository: ${{ inputs.repository }}
302273
ref: ${{ inputs.reference }}
303-
- name: Sync translation sources
274+
- name: Checkout translation sources
304275
if: ${{ inputs.language != 'en' }}
305-
env:
306-
LANGUAGE_TAG: ${{ inputs.language }}
307-
TARGET_VERSION: ${{ needs.prepare.outputs.major_minor }}
308-
run: |
309-
python - <<'PY'
310-
import bisect
311-
import os
312-
import pathlib
313-
import re
314-
import subprocess
315-
316-
language = os.environ["LANGUAGE_TAG"]
317-
target_version = os.environ["TARGET_VERSION"]
318-
repo_tag = language.replace("_", "-").lower()
319-
repo_url = f"https://github.com/python/python-docs-{repo_tag}.git"
320-
remote_branches = subprocess.check_output(
321-
["git", "ls-remote", "--heads", repo_url], text=True
322-
)
323-
branches = sorted(
324-
{
325-
match.group(1)
326-
for match in re.finditer(r"refs/heads/([0-9]+\.[0-9]+)$", remote_branches, re.M)
327-
},
328-
key=lambda value: tuple(map(int, value.split("."))),
329-
)
330-
if not branches:
331-
raise SystemExit(f"No numeric translation branches found for {repo_url}")
332-
branch_tuples = [tuple(map(int, value.split("."))) for value in branches]
333-
target_tuple = tuple(map(int, target_version.split(".")))
334-
index = bisect.bisect_left(branch_tuples, target_tuple)
335-
chosen = branches[index] if index < len(branches) else branches[-1]
336-
destination = pathlib.Path("Doc") / "locale" / language / "LC_MESSAGES"
337-
destination.parent.mkdir(parents=True, exist_ok=True)
338-
subprocess.check_call(
339-
["git", "clone", "--branch", chosen, "--single-branch", repo_url, str(destination)]
340-
)
341-
PY
276+
uses: actions/checkout@master
277+
with:
278+
repository: ${{ needs.prepare.outputs.translation_repository }}
279+
ref: ${{ needs.prepare.outputs.translation_ref }}
280+
path: Doc/locale/${{ inputs.language }}/LC_MESSAGES
342281
- id: build-settings
343282
env:
344283
LANGUAGE_TAG: ${{ inputs.language }}
@@ -348,7 +287,7 @@ jobs:
348287
import json
349288
import os
350289
import shlex
351-
290+
352291
language = os.environ["LANGUAGE_TAG"]
353292
config_sphinxopts = json.loads(os.environ["SPHINXOPTS_JSON"])
354293
common = []
@@ -361,7 +300,7 @@ jobs:
361300
]
362301
artifact_suffix = "" if language == "en" else f"-{language}"
363302
pdf = [*common, *config_sphinxopts]
364-
303+
365304
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as file:
366305
file.write(f"artifact_suffix={artifact_suffix}\n")
367306
file.write(f"common_sphinxopts={shlex.join(common)}\n")
@@ -405,45 +344,13 @@ jobs:
405344
with:
406345
repository: ${{ inputs.repository }}
407346
ref: ${{ inputs.reference }}
408-
- name: Sync translation sources
347+
- name: Checkout translation sources
409348
if: ${{ inputs.language != 'en' }}
410-
env:
411-
LANGUAGE_TAG: ${{ inputs.language }}
412-
TARGET_VERSION: ${{ needs.prepare.outputs.major_minor }}
413-
run: |
414-
python - <<'PY'
415-
import bisect
416-
import os
417-
import pathlib
418-
import re
419-
import subprocess
420-
421-
language = os.environ["LANGUAGE_TAG"]
422-
target_version = os.environ["TARGET_VERSION"]
423-
repo_tag = language.replace("_", "-").lower()
424-
repo_url = f"https://github.com/python/python-docs-{repo_tag}.git"
425-
remote_branches = subprocess.check_output(
426-
["git", "ls-remote", "--heads", repo_url], text=True
427-
)
428-
branches = sorted(
429-
{
430-
match.group(1)
431-
for match in re.finditer(r"refs/heads/([0-9]+\.[0-9]+)$", remote_branches, re.M)
432-
},
433-
key=lambda value: tuple(map(int, value.split("."))),
434-
)
435-
if not branches:
436-
raise SystemExit(f"No numeric translation branches found for {repo_url}")
437-
branch_tuples = [tuple(map(int, value.split("."))) for value in branches]
438-
target_tuple = tuple(map(int, target_version.split(".")))
439-
index = bisect.bisect_left(branch_tuples, target_tuple)
440-
chosen = branches[index] if index < len(branches) else branches[-1]
441-
destination = pathlib.Path("Doc") / "locale" / language / "LC_MESSAGES"
442-
destination.parent.mkdir(parents=True, exist_ok=True)
443-
subprocess.check_call(
444-
["git", "clone", "--branch", chosen, "--single-branch", repo_url, str(destination)]
445-
)
446-
PY
349+
uses: actions/checkout@master
350+
with:
351+
repository: ${{ needs.prepare.outputs.translation_repository }}
352+
ref: ${{ needs.prepare.outputs.translation_ref }}
353+
path: Doc/locale/${{ inputs.language }}/LC_MESSAGES
447354
- id: build-settings
448355
env:
449356
LANGUAGE_TAG: ${{ inputs.language }}
@@ -453,7 +360,7 @@ jobs:
453360
import json
454361
import os
455362
import shlex
456-
363+
457364
language = os.environ["LANGUAGE_TAG"]
458365
config_sphinxopts = json.loads(os.environ["SPHINXOPTS_JSON"])
459366
common = []
@@ -466,7 +373,7 @@ jobs:
466373
]
467374
artifact_suffix = "" if language == "en" else f"-{language}"
468375
pdf = [*common, *config_sphinxopts]
469-
376+
470377
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as file:
471378
file.write(f"artifact_suffix={artifact_suffix}\n")
472379
file.write(f"common_sphinxopts={shlex.join(common)}\n")
@@ -503,45 +410,13 @@ jobs:
503410
with:
504411
repository: ${{ inputs.repository }}
505412
ref: ${{ inputs.reference }}
506-
- name: Sync translation sources
413+
- name: Checkout translation sources
507414
if: ${{ inputs.language != 'en' }}
508-
env:
509-
LANGUAGE_TAG: ${{ inputs.language }}
510-
TARGET_VERSION: ${{ needs.prepare.outputs.major_minor }}
511-
run: |
512-
python - <<'PY'
513-
import bisect
514-
import os
515-
import pathlib
516-
import re
517-
import subprocess
518-
519-
language = os.environ["LANGUAGE_TAG"]
520-
target_version = os.environ["TARGET_VERSION"]
521-
repo_tag = language.replace("_", "-").lower()
522-
repo_url = f"https://github.com/python/python-docs-{repo_tag}.git"
523-
remote_branches = subprocess.check_output(
524-
["git", "ls-remote", "--heads", repo_url], text=True
525-
)
526-
branches = sorted(
527-
{
528-
match.group(1)
529-
for match in re.finditer(r"refs/heads/([0-9]+\.[0-9]+)$", remote_branches, re.M)
530-
},
531-
key=lambda value: tuple(map(int, value.split("."))),
532-
)
533-
if not branches:
534-
raise SystemExit(f"No numeric translation branches found for {repo_url}")
535-
branch_tuples = [tuple(map(int, value.split("."))) for value in branches]
536-
target_tuple = tuple(map(int, target_version.split(".")))
537-
index = bisect.bisect_left(branch_tuples, target_tuple)
538-
chosen = branches[index] if index < len(branches) else branches[-1]
539-
destination = pathlib.Path("Doc") / "locale" / language / "LC_MESSAGES"
540-
destination.parent.mkdir(parents=True, exist_ok=True)
541-
subprocess.check_call(
542-
["git", "clone", "--branch", chosen, "--single-branch", repo_url, str(destination)]
543-
)
544-
PY
415+
uses: actions/checkout@master
416+
with:
417+
repository: ${{ needs.prepare.outputs.translation_repository }}
418+
ref: ${{ needs.prepare.outputs.translation_ref }}
419+
path: Doc/locale/${{ inputs.language }}/LC_MESSAGES
545420
- id: build-settings
546421
env:
547422
LANGUAGE_TAG: ${{ inputs.language }}
@@ -551,7 +426,7 @@ jobs:
551426
import json
552427
import os
553428
import shlex
554-
429+
555430
language = os.environ["LANGUAGE_TAG"]
556431
config_sphinxopts = json.loads(os.environ["SPHINXOPTS_JSON"])
557432
common = []
@@ -564,7 +439,7 @@ jobs:
564439
]
565440
artifact_suffix = "" if language == "en" else f"-{language}"
566441
pdf = [*common, *config_sphinxopts]
567-
442+
568443
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as file:
569444
file.write(f"artifact_suffix={artifact_suffix}\n")
570445
file.write(f"common_sphinxopts={shlex.join(common)}\n")

0 commit comments

Comments
 (0)