Skip to content

Commit

Permalink
Add github workflows to update translation
Browse files Browse the repository at this point in the history
  • Loading branch information
zhsj committed Oct 7, 2019
1 parent 4139711 commit 60fe6f6
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/actions/commit/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM debian:stable-slim

RUN set -ex \
&& apt-get update \
&& apt-get install -y --no-install-recommends git ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
5 changes: 5 additions & 0 deletions .github/actions/commit/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Commit Translation
description: Commit translation in git repo and push to remote
runs:
using: 'docker'
image: 'Dockerfile'
13 changes: 13 additions & 0 deletions .github/actions/commit/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -ex

cd docs || exit 1
git config user.email "[email protected]"
git config user.name "Github Actions"
if git status -s|grep '\.po'; then
git add .
git commit -m '[po] auto sync'
header="$(echo -n token:"$GITHUB_TOKEN" | base64)"
git -c http.extraheader="AUTHORIZATION: basic $header" push
fi
12 changes: 12 additions & 0 deletions .github/actions/update/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3-slim

RUN set -ex \
&& pip install transifex-client \
&& rm -rf ~/.cache \
&& apt-get update \
&& apt-get install -y --no-install-recommends git make \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

ADD entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
16 changes: 16 additions & 0 deletions .github/actions/update/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Update Translation
description: Update Python Doc Translation from Transifex
inputs:
pythonVersion:
description: Python Version
required: true
locale:
description: Locale Name
required: true
default: zh_CN
runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.pythonVersion }}
- ${{ inputs.locale }}
36 changes: 36 additions & 0 deletions .github/actions/update/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

set -ex

pythonVersion="$1"
locale="$2"

echo "Python Version: $pythonVersion"
echo "Locale: $locale"

cur=$(pwd)
git clone --depth=1 --branch="$pythonVersion" https://github.com/python/cpython cpython
git clone --branch="$pythonVersion" https://github.com/"$GITHUB_REPOSITORY" docs

if [[ -n "$TRANSIFEX_APIKEY" ]]; then
cat > ~/.transifexrc << EOF
[https://www.transifex.com]
api_hostname = https://api.transifex.com
hostname = https://www.transifex.com
password = $TRANSIFEX_APIKEY
username = api
EOF
fi

# Pull Transifex translation
pushd docs || exit 1
tx pull --force --parallel --language "$locale"
popd || exit 1

# Test building docs
pushd cpython/Doc || exit 1
mkdir -p locales/"$locale"/
ln -sfn "$cur"/docs locales/"$locale"/LC_MESSAGES
make venv
make html SPHINXOPTS="-D language=$locale -D gettext_compact=0 -j4 -W --keep-going"
popd || exit 1
25 changes: 25 additions & 0 deletions .github/workflows/python-37.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: python-37

on:
push:
branches:
- master
schedule:
- cron: "38 * * * *"

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: ./.github/actions/update
with:
pythonVersion: "3.7"
locale: zh_CN
env:
TRANSIFEX_APIKEY: ${{ secrets.TRANSIFEX_APIKEY }}
- uses: ./.github/actions/commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/python-38.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: python-38

on:
push:
branches:
- master
schedule:
- cron: "18 * * * *"

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- uses: ./.github/actions/update
with:
pythonVersion: "3.8"
locale: zh_CN
env:
TRANSIFEX_APIKEY: ${{ secrets.TRANSIFEX_APIKEY }}
- uses: ./.github/actions/commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 60fe6f6

Please sign in to comment.