fix(ci): prevent update-translations push races #260
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: Update Translations and Wiki Status | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'cps/**' | |
| - 'scripts/compile_translations.sh' | |
| - 'scripts/update_translations.sh' | |
| - 'scripts/generate_translation_status.py' | |
| - '.github/workflows/update-translations.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| actions: write | |
| concurrency: | |
| group: update-translations-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| update-translations: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: true | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.13' | |
| - name: Install dependencies | |
| run: pip install Babel polib jinja2 | |
| - name: Install gettext | |
| run: sudo apt-get update && sudo apt-get install -y gettext | |
| - name: Regenerate, commit, and push translation updates | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| for i in 1 2 3 4 5; do | |
| git fetch origin main | |
| git reset --hard origin/main | |
| bash scripts/update_translations.sh | |
| git add -f messages.pot cps/translations/*/LC_MESSAGES/messages.po | |
| if git diff --cached --quiet; then | |
| echo "No translation changes to commit" | |
| echo "TRANSLATION_COMMITTED=0" >> $GITHUB_ENV | |
| exit 0 | |
| fi | |
| git commit -m "Update translations [skip ci]" | |
| if git push; then | |
| echo "TRANSLATION_COMMITTED=1" >> $GITHUB_ENV | |
| echo "TRANSLATION_COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV | |
| exit 0 | |
| fi | |
| echo "Push rejected, retrying against latest main (attempt $i)" | |
| done | |
| echo "Push failed after retries" >&2 | |
| exit 1 | |
| - name: Select dev build SHA | |
| run: | | |
| if [ "${{ env.TRANSLATION_COMMITTED }}" = "1" ]; then | |
| echo "DEV_BUILD_SHA=${{ env.TRANSLATION_COMMIT_SHA }}" >> $GITHUB_ENV | |
| else | |
| echo "DEV_BUILD_SHA=${{ github.sha }}" >> $GITHUB_ENV | |
| fi | |
| - name: Trigger dev build for main | |
| run: | | |
| curl -L -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/workflows/docker-image-build-dev.yml/dispatches \ | |
| -d "{\"ref\":\"main\",\"inputs\":{\"ref\":\"${DEV_BUILD_SHA}\",\"branch\":\"main\"}}" | |
| - name: Clone wiki repo | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_PAT }} | |
| run: | | |
| git clone https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.wiki.git wiki-tmp | |
| - name: Generate translation status table (in wiki repo) | |
| run: | | |
| python scripts/generate_translation_status.py wiki-tmp/Contributing-Translations.md | |
| - name: Commit and push wiki update | |
| run: | | |
| cd wiki-tmp | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add Contributing-Translations.md | |
| git commit -m "Update translation status table [skip ci]" || echo "No changes to commit" | |
| git push |