Skip to content

Commit d499d11

Browse files
committed
Add github workflows to update translation
1 parent 4139711 commit d499d11

File tree

9 files changed

+147
-5
lines changed

9 files changed

+147
-5
lines changed

.github/actions/commit/Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM debian:stable-slim
2+
3+
RUN set -ex \
4+
&& apt-get update \
5+
&& apt-get install -y --no-install-recommends git ca-certificates \
6+
&& apt-get clean \
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
ADD entrypoint.sh /entrypoint.sh
10+
ENTRYPOINT ["/entrypoint.sh"]

.github/actions/commit/action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
name: Commit Translation
2+
description: Commit translation in git repo and push to remote
3+
runs:
4+
using: 'docker'
5+
image: 'Dockerfile'

.github/actions/commit/entrypoint.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
cd docs || exit 1
6+
git config user.email "github-actions[bot]@users.noreply.github.com"
7+
git config user.name "github-actions[bot]"
8+
if git status -s|grep '\.po'; then
9+
git add .
10+
git commit -m '[po] auto sync'
11+
header="$(echo -n token:"$GITHUB_TOKEN" | base64)"
12+
git -c http.extraheader="AUTHORIZATION: basic $header" push
13+
fi

.github/actions/update/Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3-slim
2+
3+
RUN set -ex \
4+
&& pip install transifex-client \
5+
&& rm -rf ~/.cache \
6+
&& apt-get update \
7+
&& apt-get install -y --no-install-recommends git make \
8+
&& apt-get clean \
9+
&& rm -rf /var/lib/apt/lists/*
10+
11+
ADD entrypoint.sh /entrypoint.sh
12+
ENTRYPOINT ["/entrypoint.sh"]

.github/actions/update/action.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Update Translation
2+
description: Update translation of Python documentation from Transifex
3+
inputs:
4+
pythonVersion:
5+
description: Python Version
6+
required: true
7+
locale:
8+
description: Locale Name
9+
required: true
10+
default: zh_CN
11+
runs:
12+
using: 'docker'
13+
image: 'Dockerfile'
14+
args:
15+
- ${{ inputs.pythonVersion }}
16+
- ${{ inputs.locale }}

.github/actions/update/entrypoint.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
pythonVersion="$1"
6+
locale="$2"
7+
8+
echo "Python Version: $pythonVersion"
9+
echo "Locale: $locale"
10+
11+
cur=$(pwd)
12+
git clone --depth=1 --branch="$pythonVersion" https://github.com/python/cpython cpython
13+
git clone --branch="$pythonVersion" https://github.com/"$GITHUB_REPOSITORY" docs
14+
15+
if [[ -n "$TRANSIFEX_APIKEY" ]]; then
16+
cat > ~/.transifexrc << EOF
17+
[https://www.transifex.com]
18+
api_hostname = https://api.transifex.com
19+
hostname = https://www.transifex.com
20+
password = $TRANSIFEX_APIKEY
21+
username = api
22+
EOF
23+
fi
24+
25+
# Pull Transifex translation
26+
pushd docs || exit 1
27+
tx pull --force --parallel --language "$locale"
28+
popd || exit 1
29+
30+
# Test building docs
31+
pushd cpython/Doc || exit 1
32+
mkdir -p locales/"$locale"/
33+
ln -sfn "$cur"/docs locales/"$locale"/LC_MESSAGES
34+
make venv
35+
make html SPHINXOPTS="-D language=$locale -D gettext_compact=0 -j4 -W --keep-going"
36+
popd || exit 1

.github/workflows/python-37.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: python-37
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
schedule:
8+
- cron: "38 * * * *"
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
with:
16+
fetch-depth: 1
17+
- uses: ./.github/actions/update
18+
with:
19+
pythonVersion: "3.7"
20+
locale: zh_CN
21+
env:
22+
TRANSIFEX_APIKEY: ${{ secrets.TRANSIFEX_APIKEY }}
23+
- uses: ./.github/actions/commit
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/python-38.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: python-38
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
schedule:
8+
- cron: "18 * * * *"
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
with:
16+
fetch-depth: 1
17+
- uses: ./.github/actions/update
18+
with:
19+
pythonVersion: "3.8"
20+
locale: zh_CN
21+
env:
22+
TRANSIFEX_APIKEY: ${{ secrets.TRANSIFEX_APIKEY }}
23+
- uses: ./.github/actions/commit
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

README.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ Maintained versions:
1010
:header-rows: 1
1111

1212
* - Version
13-
- Build status
13+
- Sync status
1414
- Translation progress
1515
* - `3.8 <https://github.com/python/python-docs-zh-cn/tree/3.8>`_
16-
- .. image:: https://travis-ci.org/python/python-docs-zh-cn.svg?branch=3.8-staging
17-
:target: https://travis-ci.org/python/python-docs-zh-cn
16+
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-38/badge.svg
17+
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-38
1818
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/newest
1919
:target: https://www.transifex.com/python-doc/python-newest/
2020
* - `3.7 <https://github.com/python/python-docs-zh-cn/tree/3.7>`_
21-
- .. image:: https://travis-ci.org/python/python-docs-zh-cn.svg?branch=3.7-staging
22-
:target: https://travis-ci.org/python/python-docs-zh-cn
21+
- .. image:: https://github.com/python/python-docs-zh-cn/workflows/python-37/badge.svg
22+
:target: https://github.com/python/python-docs-zh-cn/actions?workflow=python-37
2323
- .. image:: https://img.shields.io/badge/dynamic/json.svg?label=zh_CN&query=%24.zh_CN&url=http://gce.zhsj.me/python/37
2424
:target: https://www.transifex.com/python-doc/python-37/
2525

0 commit comments

Comments
 (0)