CI #795
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - 'main' | |
| paths-ignore: | |
| - 'docs/**' | |
| - '.readthedocs.yaml' | |
| - 'sample-workflows/**' | |
| pull_request: | |
| branches: | |
| - 'main' | |
| paths-ignore: | |
| - 'docs/**' | |
| - '.readthedocs.yaml' | |
| - 'sample-workflows/**' | |
| workflow_dispatch: | |
| inputs: | |
| push: | |
| description: "Push source strings and translations to Transifex" | |
| type: boolean | |
| pull: | |
| description: "Pull translations from Transifex" | |
| type: boolean | |
| schedule: | |
| - cron: '0 14 */2 * *' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| env: | |
| TX_CLI_VERSION: '1.6.16' | |
| TX_PROJECT: python-newest # Project name for the latest python version | |
| jobs: | |
| trigger: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| all_versions: ${{ steps.version.outputs.all_versions }} | |
| current: ${{ steps.version.outputs.current }} | |
| version_pairs: ${{ steps.version.outputs.version_pairs }} | |
| languages: ${{ steps.languages.outputs.languages }} | |
| steps: | |
| - name: Check out ${{ github.repository }} | |
| uses: actions/[email protected] | |
| - name: Set up Python 3 | |
| uses: actions/[email protected] | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| cache-dependency-path: requirements.txt | |
| pip-install: -r requirements.txt | |
| - name: Set version variables | |
| id: version | |
| run: | | |
| { | |
| echo "all_versions=$(scripts/manage_versions.py all)" | |
| echo "current=$(scripts/manage_versions.py current)" | |
| echo "version_pairs=$(scripts/manage_versions.py generate_pairs)" | |
| } >> "$GITHUB_OUTPUT" | |
| - name: Check out branch ${{ steps.version.outputs.current }} | |
| uses: actions/[email protected] | |
| with: | |
| ref: ${{ steps.version.outputs.current }} | |
| path: ${{ steps.version.outputs.current }} | |
| - name: Set languages variable | |
| id: languages | |
| working-directory: ${{ steps.version.outputs.current }} | |
| run: | | |
| echo "languages=$(../scripts/list-langs.py)" >> "$GITHUB_OUTPUT" | |
| - name: Print variables values | |
| run: | | |
| echo all_versions: ${{ steps.version.outputs.all_versions }} | |
| echo current: ${{ steps.version.outputs.current }} | |
| echo version_pairs: ${{ steps.version.outputs.version_pairs }} | |
| echo languages: ${{ steps.languages.outputs.languages }} | |
| update: | |
| runs-on: ubuntu-latest | |
| needs: trigger | |
| permissions: | |
| contents: write | |
| strategy: | |
| max-parallel: 1 | |
| fail-fast: false | |
| matrix: | |
| cpython_version: ${{fromJson(needs.trigger.outputs.all_versions)}} | |
| # must match existent projects in Transifex | |
| steps: | |
| - name: Check out ${{ github.repository }} | |
| uses: actions/[email protected] | |
| - name: Check out ${{ matrix.cpython_version }} branch of CPython | |
| uses: actions/[email protected] | |
| with: | |
| repository: python/cpython | |
| persist-credentials: false | |
| ref: ${{ matrix.cpython_version }} | |
| path: cpython | |
| - name: Check out ${{ matrix.cpython_version }} branch of ${{ github.repository }} | |
| uses: actions/[email protected] | |
| with: | |
| ref: ${{ matrix.cpython_version }} | |
| path: cpython/Doc/locales | |
| - name: Set up Python 3 | |
| uses: actions/[email protected] | |
| with: | |
| python-version: '3.12' | |
| cache: 'pip' | |
| cache-dependency-path: | | |
| requirements.txt | |
| cpython/Doc/requirements.txt | |
| pip-install: -r requirements.txt -r cpython/Doc/requirements.txt | |
| - name: Install Transifex CLI | |
| working-directory: /usr/local/bin | |
| run: | | |
| curl -o- https://raw.githubusercontent.com/transifex/cli/master/install.sh | bash -s -- v${{ env.TX_CLI_VERSION }} | |
| - name: Install dependencies | |
| run: | | |
| sudo apt update -y && sudo apt install gettext -y | |
| - name: Change Transifex project name if Python version != python-newest | |
| if: ${{ matrix.cpython_version != needs.trigger.outputs.current }} | |
| shell: bash | |
| run: | | |
| ver="$(echo "${{ matrix.cpython_version }}" | sed 's|\.||')" | |
| echo "TX_PROJECT=python-$ver" >> "$GITHUB_ENV" | |
| echo "${{ env.TX_PROJECT }}" | |
| # required for generating .tx/config | |
| - name: Generate POT files | |
| working-directory: cpython/Doc | |
| run: | | |
| (cd locales; rm -r pot;) | |
| make BUILDER=gettext SPHINXOPTS='-E -D gettext_compact=0 -d build/.doctrees-gettext' build | |
| mv build/gettext locales/pot | |
| - name: Include obsolete catalog templates (pot files) for removal | |
| run: | | |
| deleted_files="$(git status -s | grep ^' D' | cut -d' ' -f3)" | |
| # shellcheck disable=SC2086 | |
| if [ -n "$deleted_files" ]; then git rm -v $deleted_files; else echo "no POT files to remove"; fi | |
| - name: Remove problematic source messages from POT files | |
| run: | | |
| scripts/remove-msgid.sh cpython/Doc/locales/pot | |
| - name: Generate Transifex configuration file (.tx/config) | |
| working-directory: cpython/Doc/locales | |
| run: | | |
| rm .tx/config | |
| sphinx-intl create-txconfig | |
| sphinx-intl update-txconfig-resources --pot-dir pot --locale-dir . --transifex-organization-name python-doc --transifex-project-name ${{ env.TX_PROJECT }} | |
| sed -i '/^minimum_perc *= 0$/s/0/1/' .tx/config | |
| git diff .tx/config | |
| - name: Push source strings to Transifex | |
| if: ${{ github.event_name == 'schedule' || | |
| (github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true') }} | |
| working-directory: cpython/Doc/locales | |
| id: tx_push | |
| run: | | |
| tx push --source --skip | |
| env: | |
| TX_TOKEN: ${{ secrets.TX_TOKEN }} | |
| - name: Lock unused translations | |
| if: steps.tx_push.outcome == 'success' | |
| run: | | |
| python3 scripts/lock-translations.py cpython/Doc/locales/.tx/config ${{ env.TX_PROJECT }} | |
| env: | |
| TX_TOKEN: ${{ secrets.TX_TOKEN }} | |
| # Remove PO files to pull and store exactly what is in Transifex, without leftovers | |
| - name: Pull translations for all languages | |
| if: ${{ github.event_name == 'schedule' || | |
| (github.event_name == 'workflow_dispatch' && github.event.inputs.pull == 'true') }} | |
| working-directory: cpython/Doc/locales | |
| run: | | |
| find ./* -type f -name '*.po' -delete | |
| find ./* -type d -empty -print -delete | |
| tx pull --all --translations --force | |
| env: | |
| TX_TOKEN: ${{ secrets.TX_TOKEN }} | |
| - name: Powrap POT files and modified PO files | |
| working-directory: cpython/Doc/locales | |
| run: | | |
| powrap --modified | |
| powrap pot/{**/,}*.pot | |
| - name: Commit changes | |
| working-directory: cpython/Doc/locales | |
| run: | | |
| git config user.name github-actions[bot] | |
| git config user.email 41898282+github-actions[bot]@users.noreply.github.com | |
| git status | |
| shopt -s globstar | |
| git diff -I'^"POT-Creation-Date: ' --numstat ./**/*.po ./**/*.pot | cut -f3 | xargs -r git add -v | |
| # shellcheck disable=SC2046,SC2035 | |
| git add -v $(git ls-files -o --exclude-standard *.po *.pot) .tx/config | |
| git diff-index --cached --quiet HEAD || { git commit -vm "Update translations from Transifex"; } | |
| - name: Push changes | |
| working-directory: cpython/Doc/locales | |
| if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }} | |
| run: | | |
| git push |