CI #474
This file contains 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' | |
pull_request: | |
branches: | |
- 'main' | |
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 * * 5' | |
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/checkout@v4.2.2 | |
- name: Set up Python 3 | |
uses: actions/setup-python@v5.3.0 | |
with: | |
python-version: '3' | |
cache: 'pip' | |
cache-dependency-path: | | |
requirements.txt | |
- name: Install dependencies | |
run: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install -r requirements.txt | |
- name: Set version variables | |
id: version | |
run: | | |
echo "all_versions=$(scripts/manage_versions.py all)" >> $GITHUB_OUTPUT | |
echo "current=$(scripts/manage_versions.py current)" >> $GITHUB_OUTPUT | |
echo "version_pairs=$(scripts/manage_versions.py generate_pairs)" >> $GITHUB_OUTPUT | |
- name: Check out branch ${{ steps.version.outputs.current }} | |
uses: actions/checkout@v4.2.2 | |
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/checkout@v4.2.2 | |
- name: Check out ${{ matrix.cpython_version }} branch of CPython | |
uses: actions/checkout@v4.2.2 | |
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/checkout@v4.2.2 | |
with: | |
ref: ${{ matrix.cpython_version }} | |
path: cpython/Doc/locales | |
- name: Set up Python 3 | |
uses: actions/setup-python@v5.3.0 | |
with: | |
python-version: '3' | |
cache: 'pip' | |
cache-dependency-path: | | |
requirements.txt | |
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 | |
pip3 install --upgrade pip | |
pip3 install -r requirements.txt -r cpython/Doc/requirements.txt | |
- 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;) | |
sphinx-build -E -b gettext -D gettext_compact=0 -d build/.doctrees . locales/pot | |
- name: Include obsolete catalog templates (pot files) for removal | |
run: | | |
deleted_files=$(git status -s | grep ^' D' | cut -d' ' -f3) | |
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 }} | |
- 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: | | |
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 | |
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 | |
propagate_translations: | |
runs-on: ubuntu-latest | |
needs: [trigger, update] | |
permissions: | |
contents: read | |
strategy: | |
max-parallel: 4 | |
fail-fast: false | |
matrix: | |
branch: ${{fromJson(needs.trigger.outputs.version_pairs)}} | |
language: ${{fromJson(needs.trigger.outputs.languages)}} | |
steps: | |
- name: Check out main | |
uses: actions/checkout@v4.2.2 | |
- name: Check out branch ${{ matrix.branch.new }} | |
uses: actions/checkout@v4.2.2 | |
with: | |
ref: ${{ matrix.branch.new }} | |
path: ${{ matrix.branch.new }} | |
- name: Check out branch ${{ matrix.branch.prev }} | |
uses: actions/checkout@v4.2.2 | |
with: | |
ref: ${{ matrix.branch.prev }} | |
path: ${{ matrix.branch.prev }} | |
- name: Set up Python 3 | |
uses: actions/setup-python@v5.3.0 | |
with: | |
python-version: '3' | |
cache: 'pip' | |
cache-dependency-path: | | |
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: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install pomerge | |
- name: Merge ${{ matrix.language }} translations from ${{ matrix.branch.new }} into ${{ matrix.branch.prev }} | |
run: | | |
if test -d ${{ matrix.branch.prev }}/${{ matrix.language }}; then | |
shopt -s globstar | |
pomerge --from-files ${{ matrix.branch.new }}/${{ matrix.language }}/**/*.po --to-files ${{ matrix.branch.prev }}/${{ matrix.language }}/**/*.po | |
else | |
echo "Branch ${{ matrix.branch.prev }} has no lang code ${{ matrix.language }}." | |
fi | |
- name: Push ${{ matrix.language }} translations for Python ${{ matrix.branch.prev }} documentation to Transifex | |
if: ${{ github.event_name == 'schedule' || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true') }} | |
working-directory: ${{ matrix.branch.prev }} | |
run: | | |
tx push -t -l ${{ matrix.language }} | |
env: | |
TX_TOKEN: ${{ secrets.TX_TOKEN }} | |