name: Sync on: workflow_call: inputs: version: description: "Branch name corresponding to a Python version" required: true type: string tx_project: description: "Name of the Transifex translation project" required: true type: string secrets: TX_TOKEN: description: "Token required for interacting with Transifex API" required: false env: PYDOC_LANGUAGE: pt_BR PYDOC_TX_PROJECT: ${{ inputs.tx_project }} PYDOC_VERSION: ${{ inputs.version }} TX_CLI_VERSION: '1.6.17' jobs: sync: runs-on: ubuntu-latest steps: # 1- Set up environment - name: Check out this repository uses: actions/checkout@v6 - name: Set language dir variable run: echo "PYDOC_LANG_DIR=${{ env.PYDOC_VERSION }}" >> $GITHUB_ENV - name: Checkout this repository ${{ env.PYDOC_VERSION }} uses: actions/checkout@v6 with: ref: ${{ env.PYDOC_VERSION }} path: ${{ env.PYDOC_LANG_DIR }} - uses: actions/setup-python@v6 with: python-version: ${{ inputs.version }} allow-prereleases: true cache: 'pip' pip-install: -r requirements.txt # 2- Install dependencies - name: Install Transifex CLI tool run: | cd /usr/local/bin curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v$TX_CLI_VERSION - name: Install APT dependencies run: sudo apt update -y && sudo apt install gettext -y # 3- Pull translations - name: Generate updated .tx/config if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }} run: python scripts/generate_txconfig.py -p ./${{ env.PYDOC_LANG_DIR }} ${{ env.PYDOC_TX_PROJECT }} env: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Pull translations from Transifex id: pull if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }} run: | # Clean up obsolete files find ./${{ env.PYDOC_LANG_DIR }} -name '*.po' -exec rm {} \; ./scripts/pull_translations.sh env: TX_TOKEN: ${{ secrets.TX_TOKEN }} - name: Merge translations from newer branch if: inputs.tx_project != 'python-newest' # python-newest doesn't have a newer branch run: | newer_branch=${PYDOC_VERSION%%.*}.$((${PYDOC_VERSION##*.}+1)) git clone --depth 1 --single-branch --branch $newer_branch https://github.com/python/python-docs-pt-br ${newer_branch}-dir pomerge --from ./${newer_branch}-dir/{**/,}*.po --to ./${{ env.PYDOC_LANG_DIR }}/{**/,}*.po rm -rf ./${newer_branch}-dir - name: powrap if: steps.pull.outcome == 'success' run: | cd ./${{ env.PYDOC_LANG_DIR }} powrap *.po **/*.po - name: Update statistics if: always() run: | ./scripts/stats.py git -C ./${{ env.PYDOC_LANG_DIR }} diff stats.json env: PYDOC_LANG_DIR: ${{ env.PYDOC_LANG_DIR }} - name: Update potodo.md if: always() run: | ./scripts/potodo.sh git -C ./${{ env.PYDOC_LANG_DIR }} diff potodo.md env: PYDOC_LANG_DIR: ${{ env.PYDOC_LANG_DIR }} # 4- Commit and push translations - name: Commit run: ./scripts/commit.sh env: PYDOC_LANG_DIR: ${{ env.PYDOC_LANG_DIR }} - name: Push if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }} run: | cd ./${{ env.PYDOC_LANG_DIR }} git push