-
-
Notifications
You must be signed in to change notification settings - Fork 35
231 lines (200 loc) · 6.96 KB
/
update.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
name: Update
on:
workflow_dispatch:
inputs:
BRANCH:
description: CPython branch to use
required: false
type: string
default: '3.12'
pull_request:
paths:
- '.github/workflows/update.yml'
- 'Makefile'
- 'requirements.txt'
branches:
- '3.12'
push:
paths:
- '.github/workflows/update.yml'
- 'Makefile'
- 'requirements.txt'
branches:
- '3.12'
- '3.11'
- '3.10'
- '3.9'
- '3.8'
- '3.7'
schedule:
- cron: '0 23 * * *'
permissions:
contents: read
jobs:
# Download translations from Transifex, keep PO and Logs artifacts
pull:
name: Pull from Transifex
runs-on: ubuntu-latest
steps:
- name: Check out ${{ github.repository }}
uses: actions/[email protected]
- name: Get branch name on push or schedule
if: |
github.event_name == 'push' ||
github.event_name == 'schedule'
run: echo "BRANCH=${GITHUB_REF_NAME}" >>$GITHUB_ENV
- name: Get branch name on pull
if: github.event_name == 'pull_request'
run: echo "BRANCH=${GITHUB_BASE_REF}" >>$GITHUB_ENV
- name: Get branch name on manual run
if: github.event_name == 'workflow_dispatch'
run: echo "BRANCH=${{ github.event.inputs.BRANCH }}" >> $GITHUB_ENV
- name: Check out CPython
uses: actions/[email protected]
with:
repository: python/cpython
ref: ${{ env.BRANCH }}
path: cpython
- name: Set up Python 3
uses: actions/[email protected]
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: |
'requirements.txt'
'cpython/requirements.txt'
- name: Install dependencies
run: sudo apt update -y && sudo apt install gettext tree -y
- name: Pull translations
run: |
make tx-config TX_CLI_DIR=/usr/local/bin
if [ "${{ github.event_name }}" != 'pull_request' ]; then
make pull -o tx-config TX_CLI_DIR=/usr/local/bin
fi
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- name: Upload artifact - po files
uses: actions/[email protected]
with:
name: translations
path: |
*.po
**/*.po
.tx/
- name: Upload artifact - log files
if: always()
uses: actions/[email protected]
with:
name: pull-logs
path: |
logs/*
/tmp/*.log
# Job for getting po files downloaded and storing this repository
push:
name: Push to repo
needs: [pull]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out ${{ github.repository }}
uses: actions/[email protected]
- name: Download PO files
uses: actions/[email protected]
with:
name: translations
# Exclude file with only changes in POT-Creation-Date
- name: Changed files
shell: bash
run: |
git diff -I'^"POT-Creation-Date: ' --numstat *.po **/*.po | cut -f3
git ls-files -o --exclude-standard *.po **/*.po
- name: Commit and push changes
if: |
github.repository == 'python/python-docs-pt-br' &&
github.event_name != 'pull_request'
run: |
git config user.name github-actions
git config user.email [email protected]
make push
# Merge translations previously updated into older branches to make sure
# older versions of Python Docs gets translated as well.
# 'overwrite=true' means strings previously translated will get overwritten;
# other branches will preserve translated strings, only filling in new
# translations.
merge:
name: Merge into ${{ matrix.branch }}
needs: [push]
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
fail-fast: false
max-parallel: 3
matrix:
branch: ['3.11', '3.10', '3.9', '3.8', '3.7', '3.6', '2.7']
include:
- branch: 3.11
overwrite: true
steps:
- name: Get branch name on push or schedule
if: |
github.event_name == 'push' ||
github.event_name == 'schedule'
run: echo "CURRENT_BRANCH=${GITHUB_REF_NAME}" >>$GITHUB_ENV
- name: Get branch name on pull
if: github.event_name == 'pull_request'
run: echo "CURRENT_BRANCH=${GITHUB_BASE_REF}" >>$GITHUB_ENV
- name: Get branch name on manual run
if: github.event_name == 'workflow_dispatch'
run: echo "CURRENT_BRANCH=${{ github.event.inputs.BRANCH }}" >> $GITHUB_ENV
- name: Check out source branch (${{ env.CURRENT_BRANCH }})
uses: actions/[email protected]
with:
path: ${{ env.CURRENT_BRANCH }}
persist-credentials: false
- name: Check out target branch (${{ matrix.branch }})
uses: actions/[email protected]
with:
ref: ${{ matrix.branch }}
path: ${{ matrix.branch }}
- name: Set up Python 3
uses: actions/[email protected]
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: "${{ env.CURRENT_BRANCH }}/requirements.txt"
- name: Install dependencies
run: |
sudo apt update -y && sudo apt install gettext -y
pip3 install pomerge powrap
- name: Merge overwriting on stable release branch
if: ${{ matrix.overwrite == true }}
run: |
pomerge --from ${{ env.CURRENT_BRANCH }}/**/*.po --to ${{ matrix.branch }}/**/*.po
- name: Merge without overwriting on EOL or security-fix release branch
if: ${{ matrix.overwrite != true }}
run: |
pomerge --no-overwrite --from ${{ env.CURRENT_BRANCH }}/**/*.po --to ${{ matrix.branch }}/**/*.po
- name: Wrap catalog message files
run: |
powrap --modified -C ${{ matrix.branch }}
#TODO: Solve make push to work with merge scenario
- name: Commit and push changes
if: |
github.repository == 'python/python-docs-pt-br' &&
github.event_name != 'pull_request'
run: |
git config user.name github-actions
git config user.email [email protected]
git diff -I'^"POT-Creation-Date: ' --numstat *.po **/*.po | cut -f3 | xargs -r git add
git add $(git ls-files -o --exclude-standard *.po **/*.po) .tx/config
git diff-index --cached --quiet HEAD || git commit -m "Merge ${{ env.CURRENT_BRANCH }} into ${{ matrix.branch }}"
working-directory: ${{ matrix.branch }}
# Call the check.yml workflow after updating to run some tests
call-build:
name: call
needs: push
if: github.event_name != 'pull_request'
uses: ./.github/workflows/check.yml
secrets: inherit