name: Weblate Merge PO permissions: # it merges the updated translations and creates a pull request with the changes contents: write pull-requests: write on: schedule: # run every Monday at 2:42AM UTC - cron: "42 2 * * Mon" # allow running manually workflow_dispatch: jobs: merge-po: # allow pushing and creating pull requests permissions: contents: write pull-requests: write # do not run in forks if: ${{ !github.event.repository.fork }} runs-on: ubuntu-latest container: image: registry.opensuse.org/opensuse/tumbleweed:latest volumes: # bind mount the GitHub CLI tool from the Ubuntu host, # it is a statically linked binary so it should work also in TumbleWeed - /usr/bin/gh:/usr/bin/gh steps: - name: Configure and refresh repositories run: | # disable unused repositories to have a faster refresh zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && \ zypper --non-interactive ref - name: Install tools run: zypper --non-interactive install --no-recommends nodejs npm git gettext-tools python3-langtable - name: Configure Git run: | git config --global user.name "YaST Bot" git config --global user.email "yast-devel@opensuse.org" - name: Checkout sources uses: actions/checkout@v6 with: path: agama - name: Checkout Agama-weblate sources uses: actions/checkout@v6 with: path: agama-weblate repository: ${{ github.repository_owner }}/agama-weblate - name: Install NPM packages working-directory: ./agama/web/share/po run: npm ci - name: Validate the PO files working-directory: ./agama-weblate run: ls web/*.po | xargs -n1 msgfmt --check-format -o /dev/null - name: Update JS translations working-directory: ./agama run: | mkdir -p web/src/po # delete the current translations find web/src/po -name '*.js' -exec git rm '{}' ';' # update the list of supported languages, it is used by the PO->JS converter in the next step web/share/update-languages.py --po-directory ../agama-weblate/web > web/src/languages.json # rebuild the JS files (cd web/src/po && SRCDIR=../../../../agama-weblate/web ../../share/po/po-converter.js) # stage the changes git add web/src/po/*.js web/src/languages.json # any changes detected? - name: Check changes id: check_changes working-directory: ./agama run: | git diff --staged web | tee tr.diff if [ -s tr.diff ]; then echo "Translations updated" # this is an Output Parameter # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter echo "updated=true" >> $GITHUB_OUTPUT else echo "Translations not changed" echo "updated=false" >> $GITHUB_OUTPUT fi rm tr.diff - name: Push updated PO files # run only when a PO file has been updated if: steps.check_changes.outputs.updated == 'true' working-directory: ./agama run: | # use an unique branch to avoid possible conflicts with already existing branches git checkout -b "po_merge_${GITHUB_RUN_ID}" git commit -a -m "Update web translation files"$'\n\n'"Agama-weblate commit: `git -C ../agama-weblate rev-parse HEAD`" git push origin "po_merge_${GITHUB_RUN_ID}" - name: Create pull request # run only when a PO file has been updated if: steps.check_changes.outputs.updated == 'true' working-directory: ./agama run: | gh pr create -B master -H "po_merge_${GITHUB_RUN_ID}" \ --label translations --label bot \ --title "Update web translation files" \ --body "Updating the web translation files from the agama-weblate repository" env: GH_TOKEN: ${{ github.token }}