Skip to content

Update

Update #401

Workflow file for this run

name: Update
on:
workflow_dispatch:
inputs:
BRANCH:
description: CPython branch to use
required: false
type: string
default: '3.12'
pull_request:
paths:
- '.github/workflows/update.yml'
- 'Makefile'
- 'requirements.txt'
branches:
- '3.12'
push:
paths:
- '.github/workflows/update.yml'
- 'Makefile'
- 'requirements.txt'
branches:
- '3.12'
- '3.11'
- '3.10'
- '3.9'
- '3.8'
- '3.7'
schedule:
- cron: '0 23 * * *'
permissions:
contents: read
jobs:
# Download translations from Transifex, keep PO and Logs artifacts
pull:
name: Pull from Transifex
runs-on: ubuntu-latest
steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v3.5.3
- name: Get branch name on push or schedule
if: |
github.event_name == 'push' ||
github.event_name == 'schedule'
run: echo "BRANCH=${GITHUB_REF_NAME}" >>$GITHUB_ENV
- name: Get branch name on pull
if: github.event_name == 'pull_request'
run: echo "BRANCH=${GITHUB_BASE_REF}" >>$GITHUB_ENV
- name: Get branch name on manual run
if: github.event_name == 'workflow_dispatch'
run: echo "BRANCH=${{ github.event.inputs.BRANCH }}" >> $GITHUB_ENV
- name: Check out CPython
uses: actions/checkout@v3.5.3
with:
repository: python/cpython
ref: ${{ env.BRANCH }}
path: cpython
- name: Set up Python 3
uses: actions/setup-python@v4.7.0
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: |
'requirements.txt'
'cpython/requirements.txt'
- name: Install dependencies
run: sudo apt update -y && sudo apt install gettext tree -y
- name: Pull translations
run: |
make tx-config TX_CLI_DIR=/usr/local/bin
if [ "${{ github.event_name }}" != 'pull_request' ]; then
make pull -o tx-config TX_CLI_DIR=/usr/local/bin
fi
env:
TX_TOKEN: ${{ secrets.TX_TOKEN }}
- name: Upload artifact - po files
uses: actions/upload-artifact@v3.1.2
with:
name: translations
path: |
*.po
**/*.po
.tx/
- name: Upload artifact - log files
if: always()
uses: actions/upload-artifact@v3.1.2
with:
name: pull-logs
path: |
logs/*
/tmp/*.log
# Job for getting po files downloaded and storing this repository
push:
name: Push to repo
needs: [pull]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out ${{ github.repository }}
uses: actions/checkout@v3.5.3
- name: Download PO files
uses: actions/download-artifact@v3.0.2
with:
name: translations
# Exclude file with only changes in POT-Creation-Date
- name: Changed files
shell: bash
run: |
git diff -I'^"POT-Creation-Date: ' --numstat *.po **/*.po | cut -f3
git ls-files -o --exclude-standard *.po **/*.po
- name: Commit and push changes
if: |
github.repository == 'python/python-docs-pt-br' &&
github.event_name != 'pull_request'
run: |
git config user.name github-actions
git config user.email github-actions@github.com
make push
# Merge translations previously updated into older branches to make sure
# older versions of Python Docs gets translated as well.
# 'overwrite=true' means strings previously translated will get overwritten;
# other branches will preserve translated strings, only filling in new
# translations.
merge:
name: Merge into ${{ matrix.branch }}
needs: [push]
runs-on: ubuntu-latest
permissions:
contents: write
strategy:
fail-fast: false
max-parallel: 3
matrix:
branch: ['3.11', '3.10', '3.9', '3.8', '3.7', '3.6', '2.7']
include:
- branch: 3.11
overwrite: true
steps:
- name: Get branch name on push or schedule
if: |
github.event_name == 'push' ||
github.event_name == 'schedule'
run: echo "CURRENT_BRANCH=${GITHUB_REF_NAME}" >>$GITHUB_ENV
- name: Get branch name on pull
if: github.event_name == 'pull_request'
run: echo "CURRENT_BRANCH=${GITHUB_BASE_REF}" >>$GITHUB_ENV
- name: Get branch name on manual run
if: github.event_name == 'workflow_dispatch'
run: echo "CURRENT_BRANCH=${{ github.event.inputs.BRANCH }}" >> $GITHUB_ENV
- name: Check out source branch (${{ env.CURRENT_BRANCH }})
uses: actions/checkout@v3.5.3
with:
path: ${{ env.CURRENT_BRANCH }}
persist-credentials: false
- name: Check out target branch (${{ matrix.branch }})
uses: actions/checkout@v3.5.3
with:
ref: ${{ matrix.branch }}
path: ${{ matrix.branch }}
- name: Set up Python 3
uses: actions/setup-python@v4.7.0
with:
python-version: '3'
cache: 'pip'
cache-dependency-path: "${{ env.CURRENT_BRANCH }}/requirements.txt"
- name: Install dependencies
run: |
sudo apt update -y && sudo apt install gettext -y
pip3 install pomerge powrap
- name: Merge overwriting on stable release branch
if: ${{ matrix.overwrite == true }}
run: |
pomerge --from ${{ env.CURRENT_BRANCH }}/**/*.po --to ${{ matrix.branch }}/**/*.po
- name: Merge without overwriting on EOL or security-fix release branch
if: ${{ matrix.overwrite != true }}
run: |
pomerge --no-overwrite --from ${{ env.CURRENT_BRANCH }}/**/*.po --to ${{ matrix.branch }}/**/*.po
- name: Wrap catalog message files
run: |
powrap --modified -C ${{ matrix.branch }}
#TODO: Solve make push to work with merge scenario
- name: Commit and push changes
if: |
github.repository == 'python/python-docs-pt-br' &&
github.event_name != 'pull_request'
run: |
git config user.name github-actions
git config user.email github-actions@github.com
git diff -I'^"POT-Creation-Date: ' --numstat *.po **/*.po | cut -f3 | xargs -r git add
git add $(git ls-files -o --exclude-standard *.po **/*.po) .tx/config
git diff-index --cached --quiet HEAD || git commit -m "Merge ${{ env.CURRENT_BRANCH }} into ${{ matrix.branch }}"
working-directory: ${{ matrix.branch }}
# Call the check.yml workflow after updating to run some tests
call-build:
name: call
needs: push
if: github.event_name != 'pull_request'
uses: ./.github/workflows/check.yml
secrets: inherit