Update Translations #39
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: Update Translations | |
on: | |
workflow_dispatch: | |
schedule: | |
# Runs at 20:00 UTC on every day-of-week from Sunday through Thursday. | |
- cron: '0 20 * * 0-4' | |
env: | |
BASE_BRANCH: master | |
jobs: | |
setup: | |
runs-on: ubuntu-latest | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set matrix for translation updates | |
id: set-matrix | |
run: | | |
echo "MATRIX=$(find . -name 'google_sheets_id.txt' -exec dirname {} \; | xargs -I {} basename {} | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
sanity: | |
runs-on: ubuntu-latest | |
needs: setup | |
steps: | |
- run: | | |
echo "${{needs.setup.outputs.MATRIX}}" | |
check-updates: | |
runs-on: ubuntu-latest | |
needs: setup | |
strategy: | |
matrix: | |
dir: ${{fromJson(needs.setup.outputs.MATRIX)}} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m venv venv | |
. venv/bin/activate | |
git clone --depth 1 https://github.com/adventurebrew/re-quest.git | |
echo "PYTHONPATH=$PYTHONPATH:$(pwd)/re-quest/tools" >> $GITHUB_ENV | |
- name: Setup git | |
run: | | |
# git config --global core.autocrlf input | |
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | |
git config --global user.name "${{ github.actor }}" | |
git fetch origin $base_branch | |
echo "basename=$(basename ${{ matrix.dir }})" >> $GITHUB_ENV | |
echo "base_branch=${{ env.BASE_BRANCH }}" >> $GITHUB_ENV | |
echo "new_branch=ci-update-translation-${{ matrix.dir }}" >> $GITHUB_ENV | |
- name: Checkout new branch | |
run: | | |
git checkout -b $new_branch origin/$base_branch | |
- name: Update translation files | |
working-directory: ${{ matrix.dir }} | |
run: | | |
GOOGLE_SHEETS_ID=$(cat google_sheets_id.txt) | |
curl -L -o messages.csv "https://docs.google.com/spreadsheets/d/$GOOGLE_SHEETS_ID/export?format=csv" | |
python -m sci.tradusci_import -t PATCHES > /dev/null | |
- name: Persist translation updates | |
env: | |
GH_TOKEN: ${{ github.token }} | |
working-directory: ${{ matrix.dir }} | |
run: | | |
# Add and commit changes, skip if there are no changes | |
git add PATCHES messages.csv | |
message="${basename^^}: update translation" | |
git commit -m "$message" || echo "No changes" | |
# Force push changes to the same branch, replacing any existing commits | |
git push --force origin HEAD:$new_branch | |
gh pr edit $new_branch -b "$message" -t "$message" \ | |
&& gh pr reopen $new_branch \ | |
|| gh pr create --fill -B $base_branch -H $new_branch --label automated \ | |
|| echo "No need to open PR" |