From 4592fcd942df8b9e5ebc9bd4ccfdd34f3d256e1a Mon Sep 17 00:00:00 2001 From: A <5249513+Dumeng@users.noreply.github.com> Date: Thu, 3 Aug 2023 22:43:09 +0800 Subject: [PATCH] Update workflow and make it reusable (#315) * Update workflow definition and dependencies version. * Simplify the code structure. * Make workflow reusable across versions. --- .github/scripts/build.sh | 4 ++-- .github/scripts/commit.sh | 3 +-- .github/scripts/prepare.sh | 8 +------ .github/scripts/update.sh | 3 +-- .github/workflows/python-310.yml | 25 +++++-------------- .github/workflows/python-311.yml | 25 +++++-------------- .github/workflows/python-312.yml | 24 ++++--------------- .github/workflows/python-37.yml | 24 ++++--------------- .github/workflows/python-38.yml | 24 ++++--------------- .github/workflows/python-39.yml | 25 +++++-------------- .github/workflows/sync.yml | 41 ++++++++++++++++++++++++++++++++ 11 files changed, 79 insertions(+), 127 deletions(-) create mode 100644 .github/workflows/sync.yml diff --git a/.github/scripts/build.sh b/.github/scripts/build.sh index bbf4eb060..2cbcb8e11 100755 --- a/.github/scripts/build.sh +++ b/.github/scripts/build.sh @@ -13,5 +13,5 @@ error() { cd cpython/Doc || exit 1 mkdir -p locales/"$LOCALE"/ ln -sfn "$(realpath ../../docs)" locales/"$LOCALE"/LC_MESSAGES -make venv -make html SPHINXOPTS="-D language=$LOCALE -D gettext_compact=0 -W --keep-going -j2" 2> >(error) +pip3 install -q -r requirements.txt +make html SPHINXOPTS="-D language=$LOCALE -D gettext_compact=0 -W --keep-going" 2> >(error) diff --git a/.github/scripts/commit.sh b/.github/scripts/commit.sh index ae7d04096..878c0d57e 100755 --- a/.github/scripts/commit.sh +++ b/.github/scripts/commit.sh @@ -11,5 +11,4 @@ if ! git status -s|grep '\.po'; then fi git add . git commit -m '[po] auto sync' -header="$(echo -n token:"$GITHUB_TOKEN" | base64)" -git -c http.extraheader="AUTHORIZATION: basic $header" push +git push diff --git a/.github/scripts/prepare.sh b/.github/scripts/prepare.sh index cf1326646..1ca5daab0 100755 --- a/.github/scripts/prepare.sh +++ b/.github/scripts/prepare.sh @@ -2,10 +2,4 @@ set -ex -git clone --depth=1 --branch="$VERSION" https://github.com/python/cpython cpython -git clone --branch="$VERSION" https://github.com/"$GITHUB_REPOSITORY" docs - -pip3 install --user setuptools -curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -sudo apt-get update -sudo apt-get install -y python3-venv +curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash \ No newline at end of file diff --git a/.github/scripts/update.sh b/.github/scripts/update.sh index bcdb2d7d9..d2f6f13be 100755 --- a/.github/scripts/update.sh +++ b/.github/scripts/update.sh @@ -1,5 +1,4 @@ #!/bin/bash -tx=$(realpath ./tx) cd docs || exit 1 -$tx pull --languages "$LOCALE" -t --use-git-timestamps +$(realpath ../tx) pull --languages "$LOCALE" -t --use-git-timestamps --workers 25 --silent diff --git a/.github/workflows/python-310.yml b/.github/workflows/python-310.yml index 5524337ef..10e299b45 100644 --- a/.github/workflows/python-310.yml +++ b/.github/workflows/python-310.yml @@ -5,25 +5,12 @@ on: branches: - master schedule: - - cron: "8 * * * *" + - cron: "26 * * * *" jobs: sync: - runs-on: ubuntu-latest - env: - LOCALE: zh_CN - VERSION: "3.10" - steps: - - uses: actions/checkout@v2 - - name: prepare - run: .github/scripts/prepare.sh - - name: update - run: .github/scripts/update.sh - env: - TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} - - name: build - run: .github/scripts/build.sh - - name: commit - run: .github/scripts/commit.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ./.github/workflows/sync.yml + with: + version: "3.10" + secrets: inherit + \ No newline at end of file diff --git a/.github/workflows/python-311.yml b/.github/workflows/python-311.yml index d2f7aee35..3ac6cf1ba 100644 --- a/.github/workflows/python-311.yml +++ b/.github/workflows/python-311.yml @@ -5,25 +5,12 @@ on: branches: - master schedule: - - cron: "11 * * * *" + - cron: "38 * * * *" jobs: sync: - runs-on: ubuntu-latest - env: - LOCALE: zh_CN - VERSION: "3.11" - steps: - - uses: actions/checkout@v2 - - name: prepare - run: .github/scripts/prepare.sh - - name: update - run: .github/scripts/update.sh - env: - TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} - - name: build - run: .github/scripts/build.sh - - name: commit - run: .github/scripts/commit.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ./.github/workflows/sync.yml + with: + version: "3.11" + secrets: inherit + diff --git a/.github/workflows/python-312.yml b/.github/workflows/python-312.yml index 51c5b3f6a..228e64d78 100644 --- a/.github/workflows/python-312.yml +++ b/.github/workflows/python-312.yml @@ -5,25 +5,11 @@ on: branches: - master schedule: - - cron: "42 * * * *" + - cron: "50 * * * *" jobs: sync: - runs-on: ubuntu-latest - env: - LOCALE: zh_CN - VERSION: "3.12" - steps: - - uses: actions/checkout@v2 - - name: prepare - run: .github/scripts/prepare.sh - - name: update - run: .github/scripts/update.sh - env: - TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} - - name: build - run: .github/scripts/build.sh - - name: commit - run: .github/scripts/commit.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ./.github/workflows/sync.yml + with: + version: "3.12" + secrets: inherit diff --git a/.github/workflows/python-37.yml b/.github/workflows/python-37.yml index 6864df933..867c77ad3 100644 --- a/.github/workflows/python-37.yml +++ b/.github/workflows/python-37.yml @@ -5,25 +5,11 @@ on: branches: - master schedule: - - cron: "53 * * * *" + - cron: "0 * * * *" jobs: sync: - runs-on: ubuntu-latest - env: - LOCALE: zh_CN - VERSION: "3.7" - steps: - - uses: actions/checkout@v2 - - name: prepare - run: .github/scripts/prepare.sh - - name: update - run: .github/scripts/update.sh - env: - TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} - - name: build - run: .github/scripts/build.sh - - name: commit - run: .github/scripts/commit.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ./.github/workflows/sync.yml + with: + version: "3.7" + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/python-38.yml b/.github/workflows/python-38.yml index 35948544c..e3725dc36 100644 --- a/.github/workflows/python-38.yml +++ b/.github/workflows/python-38.yml @@ -5,25 +5,11 @@ on: branches: - master schedule: - - cron: "38 * * * *" + - cron: "2 * * * *" jobs: sync: - runs-on: ubuntu-latest - env: - LOCALE: zh_CN - VERSION: "3.8" - steps: - - uses: actions/checkout@v2 - - name: prepare - run: .github/scripts/prepare.sh - - name: update - run: .github/scripts/update.sh - env: - TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} - - name: build - run: .github/scripts/build.sh - - name: commit - run: .github/scripts/commit.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ./.github/workflows/sync.yml + with: + version: "3.8" + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/python-39.yml b/.github/workflows/python-39.yml index 4b16958a5..458459371 100644 --- a/.github/workflows/python-39.yml +++ b/.github/workflows/python-39.yml @@ -5,25 +5,12 @@ on: branches: - master schedule: - - cron: "23 * * * *" + - cron: "14 * * * *" jobs: sync: - runs-on: ubuntu-latest - env: - LOCALE: zh_CN - VERSION: "3.9" - steps: - - uses: actions/checkout@v2 - - name: prepare - run: .github/scripts/prepare.sh - - name: update - run: .github/scripts/update.sh - env: - TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} - - name: build - run: .github/scripts/build.sh - - name: commit - run: .github/scripts/commit.sh - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: ./.github/workflows/sync.yml + with: + version: "3.9" + secrets: inherit + \ No newline at end of file diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 000000000..a5a126e20 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,41 @@ +name: Reusable workflow example + +on: + workflow_call: + inputs: + version: + required: true + type: string + secrets: + TRANSIFEX_APIKEY: + required: true + +jobs: + sync: + runs-on: ubuntu-latest + env: + LOCALE: zh_CN + VERSION: ${{ inputs.version }} + steps: + - uses: actions/checkout@v3 + - name: Checkout CPython + uses: actions/checkout@v3 + with: + repository: 'python/cpython' + ref: ${{env.VERSION}} + path: cpython + - name: Checkout Current Branch + uses: actions/checkout@v3 + with: + ref: ${{env.VERSION}} + path: docs + - name: prepare + run: .github/scripts/prepare.sh + - name: update + run: .github/scripts/update.sh + env: + TX_TOKEN: ${{ secrets.TRANSIFEX_APIKEY }} + - name: build + run: .github/scripts/build.sh + - name: commit + run: .github/scripts/commit.sh \ No newline at end of file