CI #307
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' | |
env: | |
TX_CLI_VERSION: '1.6.10' | |
PYTHON_NEWEST: '3.12' # Latest Python version being translated | |
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 }} | |
old_versions: ${{ steps.version.outputs.old_versions }} | |
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' | |
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 "old_versions=$(scripts/manage_versions.py others)" >> $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 old_versions: ${{ steps.version.outputs.old_versions }} | |
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' | |
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 != env.PYTHON_NEWEST }} | |
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; git rm -r pot;) | |
sphinx-build -E -b gettext -D gettext_compact=0 -d build/.doctrees . locales/pot | |
# See issue #15 | |
- name: Patch POT files | |
working-directory: cpython/Doc/locales/pot | |
run: | | |
$GITHUB_WORKSPACE/scripts/remove-ilegal-strings.sh library/{codecs,re}.pot reference/lexical_analysis.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 | |
- 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 and push changes | |
working-directory: cpython/Doc/locales | |
if: ${{ contains(fromJSON('["schedule", "workflow_dispatch"]'), github.event_name) }} | |
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 | |
git add $(git ls-files -o --exclude-standard *.po *.pot) .tx/config | |
git diff-index --cached --quiet HEAD || { git commit -m "Update translations from ${{ env.BRANCH }}" && 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.old_versions)}} | |
language: ${{fromJson(needs.trigger.outputs.languages)}} | |
steps: | |
- name: Check out main | |
uses: actions/[email protected] | |
- name: Check out branch ${{ needs.trigger.outputs.current }} | |
uses: actions/[email protected] | |
with: | |
ref: ${{ needs.trigger.outputs.current }} | |
path: ${{ needs.trigger.outputs.current }} | |
- name: Check out branch ${{ matrix.branch }} | |
uses: actions/[email protected] | |
with: | |
ref: ${{ matrix.branch }} | |
path: ${{ matrix.branch }} | |
- name: Set up Python 3 | |
uses: actions/[email protected] | |
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 ${{ needs.trigger.outputs.current }} into ${{ matrix.branch }} | |
run: | | |
if test -d ${{ matrix.branch }}/${{ matrix.language }}; then | |
shopt -s globstar | |
pomerge --from-files ${{ needs.trigger.outputs.current }}/${{ matrix.language }}/**/*.po --to-files ${{ matrix.branch }}/${{ matrix.language }}/**/*.po | |
else | |
echo "Branch ${{ matrix.branch }} has no lang code ${{ matrix.language }}." | |
fi | |
- name: Push ${{ matrix.language }} translations for Python ${{ matrix.branch }} documentation to Transifex | |
if: ${{ github.event_name == 'schedule' || | |
(github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true') }} | |
working-directory: ${{ matrix.branch }} | |
run: | | |
tx push -t -l ${{ matrix.language }} | |
env: | |
TX_TOKEN: ${{ secrets.TX_TOKEN }} | |