-
-
Notifications
You must be signed in to change notification settings - Fork 38
140 lines (114 loc) · 4.22 KB
/
sync.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
name: Sync
on:
workflow_call:
inputs:
version:
description: "Branch name corresponding to a Python version"
required: true
type: string
tx_project:
description: "Name of the Transifex translation project"
required: true
type: string
secrets:
TX_TOKEN:
description: "Token required for interacting with Transifex API"
required: false
env:
PYDOC_LANGUAGE: pt_BR
PYDOC_TX_PROJECT: ${{ inputs.tx_project }}
PYDOC_VERSION: ${{ inputs.version }}
TX_CLI_VERSION: '1.6.17'
jobs:
sync:
runs-on: ubuntu-latest
steps:
# 1- Set up environment
- name: Check out this repository
uses: actions/checkout@v4
- name: Checkout CPython ${{ env.PYDOC_VERSION }}
uses: actions/checkout@v4
with:
repository: 'python/cpython'
ref: ${{ env.PYDOC_VERSION }}
path: cpython
- name: Set language dir variable
run:
echo "LANGUAGE_DIR=cpython/Doc/locales/${{ env.PYDOC_LANGUAGE }}/LC_MESSAGES" >> $GITHUB_ENV
- name: Checkout this repository ${{ env.PYDOC_VERSION }}
uses: actions/checkout@v4
with:
ref: ${{ env.PYDOC_VERSION }}
path: ${{ env.LANGUAGE_DIR }}
- uses: actions/setup-python@v5
with:
python-version: ${{ inputs.version }}
allow-prereleases: true
cache: 'pip'
cache-dependency-path: |
requirements.txt
cpython/Doc/requirements.txt
- name: Check for Transifex API Token availability
id: secret-check
# perform secret check & put boolean result as an output
shell: bash
run: |
available=false
[[ "${{ secrets.TX_TOKEN }}" != '' ]] && available=true
echo "available=$available" >> $GITHUB_OUTPUT
echo "available=$available"
# 2- Install dependencies
- name: Install Transifex CLI tool
run: |
cd /usr/local/bin
curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v$TX_CLI_VERSION
- name: Install APT dependencies
run: sudo apt update -y && sudo apt install gettext -y
- name: Install Python dependencies
run: |
pip install -r requirements.txt
make -C cpython/Doc venv
# 3- Pull translations
- name: Generate template files and Transifex config file
run: ./scripts/generate_templates.sh
- name: Pull translations from Transifex
id: pull
if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }}
run: |
# Clean up obsolete files
find ./${{ env.LANGUAGE_DIR }} -name '*.po' -exec rm {} \;
./scripts/pull_translations.sh
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- name: Merge translations from newer branch
if: inputs.tx_project != 'python-newest' # python-newest doesn't have a newer branch
run: |
newer_branch=${PYDOC_VERSION%%.*}.$((${PYDOC_VERSION##*.}+1))
git clone --depth 1 --single-branch --branch $newer_branch https://github.com/python/python-docs-pt-br ${newer_branch}-dir
pomerge --from ./${newer_branch}-dir/{**/,}*.po --to ./${{ env.LANGUAGE_DIR }}/{**/,}*.po
rm -rf ./${newer_branch}-dir
- name: powrap
if: steps.pull.outcome == 'success'
run: |
cd ./${{ env.LANGUAGE_DIR }}
powrap *.po **/*.po
- name: Update statistics
if: always() && steps.secret-check.outputs.available == 'true'
run: |
python ./scripts/tx_stats.py > ./${{ env.LANGUAGE_DIR }}/stats.json
git -C ./${{ env.LANGUAGE_DIR }} diff stats.json
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- name: Update potodo.md
if: always()
run: |
./scripts/potodo.sh
git diff ./${{ env.LANGUAGE_DIR }}/potodo.md
# 4- Commit and push translations
- name: Commit
run: ./scripts/commit.sh
- name: Push
if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }}
run: |
cd ./${{ env.LANGUAGE_DIR }}
git push