Skip to content

Commit d8ae968

Browse files
Add sample workflows docs (#131)
* Add sample workflows docs * Fix index * Fix markup * Updates * Apply suggestions from code review Co-authored-by: Rafael Fontenelle <[email protected]> * Changes * Move & reword --------- Co-authored-by: Rafael Fontenelle <[email protected]>
1 parent 70509b4 commit d8ae968

File tree

2 files changed

+158
-1
lines changed

2 files changed

+158
-1
lines changed

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ See also Translating_ in the Python Developer's Guide for more information.
3838
:caption: Contents:
3939

4040
new-translators.rst
41-
bumping-relsease.rst
4241
commands.rst
42+
workflows.rst
4343
placeholders.rst

docs/workflows.rst

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
================
2+
GitHub Workflows
3+
================
4+
5+
All Python documentation translation repositories are hosted on `GitHub <https://github.com>`_.
6+
GitHub provides a very useful `CI <https://en.wikipedia.org/wiki/Continuous_integration>`_
7+
system, *GitHub Actions*, which runs *workflows*. Workflows are particularly useful
8+
for testing projects, in translation repos they can be used to update translations
9+
from Transifex, lint translated files, and test build the translated documentation.
10+
11+
This repository provides three sample workflows: a Linting workflow, a Test Build
12+
workflow, and a workflow for pulling translations from Transifex. They can be found
13+
in the `sample-workflows <https://github.com/python-docs-translations/transifex-automations/tree/main/sample-workflows>`_
14+
directory and explanations of how they work and what you need to do to set them up can be found below.
15+
16+
.. seealso::
17+
- `GitHub docs: Writing workflows <https://docs.github.com/en/actions/writing-workflows>`_
18+
- :doc:`Setting up Transifex <commands>`
19+
20+
Running Workflows
21+
-----------------
22+
23+
To run on of our provided workflows (or any workflow), put the file in the
24+
``.github/workflows`` folder and it will run automatically depending on how it
25+
is configured.
26+
27+
General Overview
28+
----------------
29+
30+
.. code-block:: yaml
31+
32+
name: Linting Workflow
33+
34+
The name can be freely configured and will be displayed in the "Actions" tab.
35+
36+
.. code-block:: yaml
37+
38+
on:
39+
schedule:
40+
- cron: '0 0 * * *'
41+
42+
Using `cron <https://en.wikipedia.org/wiki/Cron>`_, the frequency of the workflow
43+
runs can be set. In the sample workflows it is configured to ``'0 0 * * *'``,
44+
meaning it will run once daily. See `crontab.guru <https://crontab.guru/>`_ for
45+
a simple cron editor.
46+
47+
.. code-block:: yaml
48+
49+
on:
50+
...
51+
push:
52+
branches:
53+
- '*'
54+
workflow_dispatch:
55+
56+
The workflow can also be set to run under different conditions, in the case of the
57+
sample workflows it is set to run on a ``push`` to any branch, and can be run
58+
manually due to the ``workflow_dispatch`` option.
59+
60+
.. code-block:: yaml
61+
62+
jobs:
63+
64+
All jobs or sections under ``jobs:`` will be run. The sample workflows can be
65+
merged into one by combining all of their jobs. (Note: there must only be one `jobs:`)
66+
67+
In the workflows, replace all instances of ``XX`` with your `IETF <https://datatracker.ietf.org/doc/html/rfc5646.html>`_
68+
language tag, as described in `PEP 545 <https://peps.python.org/pep-0545/#language-tag>`_.
69+
These tools, however, require and underscore (``_``) rather than a dash (``-``);
70+
for example ``pl`` or ``pt_BR``.
71+
72+
73+
Transifex Pull Workflow
74+
-----------------------
75+
76+
How to configure the `Transifex Pull Workflow <https://github.com/python-docs-translations/transifex-automations/blob/main/sample-workflows/transifex-pull.yml>`_.
77+
78+
This workflow automatically pulls updated translations from Transifex, commits
79+
them to the repository, and pushes them back to the relevant branch, if
80+
significant changes are detected.
81+
82+
Ensure the ``TX_TOKEN`` secret is configured in your repository with your Transifex API token.
83+
For generating your API key, see this `Transifex article <https://help.transifex.com/en/articles/6248858-generating-an-api-token>`_,
84+
for setting up secrets, see this `guide <https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository>`_.
85+
86+
.. code-block:: yaml
87+
88+
matrix:
89+
version: [ 3.14 ]
90+
91+
Set the ``version`` list to the branches for which translations should be updated.
92+
93+
.. code-block:: yaml
94+
95+
- name: Filter files
96+
run: |
97+
! git diff -I'^"POT-Creation-Date: ' \
98+
-I'^"Language-Team: ' \
99+
-I'^# ' -I'^"Last-Translator: ' \
100+
--exit-code \
101+
&& echo "SIGNIFICANT_CHANGES=1" >> $GITHUB_ENV || exit 0
102+
103+
This step detects whether the changes are significant by ignoring changes
104+
to the file header. A commit and push only occur if meaningful changes are found,
105+
these filters can be modified to suit.
106+
107+
108+
Test Build Workflow
109+
-------------------
110+
111+
How to configure the `Test Build Workflow <https://github.com/python-docs-translations/transifex-automations/blob/main/sample-workflows/test-build.yml>`_.
112+
113+
.. code-block:: yaml
114+
115+
matrix:
116+
version: [ 3.14 ]
117+
format: [ html, latex ]
118+
119+
Set version to the branches in your translation repository that you want to be
120+
built, for example: ``version: [ 3.14, 3.13, 3.12 ]``, note that this has to be
121+
changed in both ``matrix``'s in the workflow. The format can be modified
122+
to run for just ``html`` if that is preferred.
123+
124+
.. code-block:: yaml
125+
126+
- uses: actions/setup-python@master
127+
with:
128+
python-version: 3.12 # pin for Sphinx 3.4.3 for 3.10
129+
130+
The ``python-version`` can be unpinned if no branches older than ``3.11`` are set
131+
in the ``version`` list.
132+
133+
.. code-block:: yaml
134+
135+
output-pdf:
136+
137+
Remove the ``output-pdf`` job if you do not want pdf output to be built. The
138+
section also has to be removed if ``latex`` is not in the ``format`` list.
139+
140+
The workflow uses the ``actions/upload-artifact@master`` tool which allows for
141+
the generated builds to be downloaded. In a run in the "Actions" tab they can be
142+
found in the "Artifacts" section.
143+
144+
145+
Linting Workflow
146+
----------------
147+
148+
How to configure the po linting `workflow <https://github.com/python-docs-translations/transifex-automations/blob/main/sample-workflows/po-lint.yml>`_.
149+
This workflow will lint all po files on your branch using `sphinx-lint <https://pypi.org/project/sphinx-lint/>`_.
150+
151+
.. code-block:: yaml
152+
153+
matrix:
154+
version: [ 3.14 ]
155+
156+
Set the ``version`` list to the versions you have available and want the linting
157+
workflow to be run on.

0 commit comments

Comments
 (0)