diff --git a/.github/actions/commit/Dockerfile b/.github/actions/commit/Dockerfile new file mode 100644 index 000000000..027660ad1 --- /dev/null +++ b/.github/actions/commit/Dockerfile @@ -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"] diff --git a/.github/actions/commit/action.yml b/.github/actions/commit/action.yml new file mode 100644 index 000000000..ea2b045e5 --- /dev/null +++ b/.github/actions/commit/action.yml @@ -0,0 +1,5 @@ +name: Commit Translation +description: Commit translation in git repo and push to remote +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/.github/actions/commit/entrypoint.sh b/.github/actions/commit/entrypoint.sh new file mode 100755 index 000000000..70f6cd6e0 --- /dev/null +++ b/.github/actions/commit/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +set -ex + +cd docs || exit 1 +git config user.email "actions@users.noreply.github.com" +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 diff --git a/.github/actions/update/Dockerfile b/.github/actions/update/Dockerfile new file mode 100644 index 000000000..717ef9ffd --- /dev/null +++ b/.github/actions/update/Dockerfile @@ -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"] diff --git a/.github/actions/update/action.yml b/.github/actions/update/action.yml new file mode 100644 index 000000000..2c9e53179 --- /dev/null +++ b/.github/actions/update/action.yml @@ -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 }} diff --git a/.github/actions/update/entrypoint.sh b/.github/actions/update/entrypoint.sh new file mode 100755 index 000000000..c99be9c62 --- /dev/null +++ b/.github/actions/update/entrypoint.sh @@ -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 diff --git a/.github/workflows/python-37.yml b/.github/workflows/python-37.yml new file mode 100644 index 000000000..35099bdd9 --- /dev/null +++ b/.github/workflows/python-37.yml @@ -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 }} diff --git a/.github/workflows/python-38.yml b/.github/workflows/python-38.yml new file mode 100644 index 000000000..782a3125b --- /dev/null +++ b/.github/workflows/python-38.yml @@ -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 }}