Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Action: Create a pull request with updated translations #675

Merged
merged 3 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions .github/workflows/weblate-merge-po.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Weblate Merge PO

on:
schedule:
# run every Monday at 2:42AM UTC
- cron: "42 2 * * 0"

# 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.repository == 'openSUSE/agama'

runs-on: ubuntu-latest

container:
image: registry.opensuse.org/opensuse/tumbleweed:latest

steps:
- name: Configure and refresh repositories
run: |
# install the GitHub command line tool "gh"
zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo
# disable unused repositories to have a faster refresh
zypper modifyrepo -d repo-non-oss repo-openh264 repo-update && \
zypper --non-interactive --gpg-auto-import-keys ref

- name: Install tools
run: zypper --non-interactive install --no-recommends gh git gettext-tools

- 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@v3
with:
path: agama

- name: Checkout Agama-weblate sources
uses: actions/checkout@v3
with:
path: agama-weblate
repository: openSUSE/agama-weblate

- name: Update PO files
working-directory: ./agama
run: |
mkdir -p web/po
# delete the current translations
find web/po -name '*.po' -exec git rm '{}' ';'

# copy the new ones
cp -a ../agama-weblate/web/*.po web/po
git add web/po/*.po

- name: Validate the PO files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails I hope it is visible enough that we notice sooner than after a month :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point... I'll add a badge to the README.md so it is more visible...

working-directory: ./agama
run: msgfmt --check-format -o /dev/null web/po/*.po

# any changes besides the timestamps in the PO files?
- name: Check changes
id: check_changes
working-directory: ./agama
run: |
git diff --staged --ignore-matching-lines="POT-Creation-Date:" \
--ignore-matching-lines="PO-Revision-Date:" web/po > po.diff

if [ -s po.diff ]; then
echo "PO files updated"
# this is an Output Parameter
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
echo "po_updated=true" >> $GITHUB_OUTPUT
lslezak marked this conversation as resolved.
Show resolved Hide resolved
else
echo "PO files unchanged"
echo "po_updated=false" >> $GITHUB_OUTPUT
fi

rm po.diff

- name: Push updated PO files
# run only when a PO file has been updated
if: steps.check_changes.outputs.po_updated == 'true'
working-directory: ./agama
run: |
# use a unique branch to avoid possible conflicts with already existing branches
git checkout -b "po_merge_${GITHUB_RUN_ID}"
git commit -a -m "Update PO 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.po_updated == 'true'
working-directory: ./agama
run: |
gh pr create -B master -H "po_merge_${GITHUB_RUN_ID}" \
--label translations --label bot \
--title "Update PO files" \
--body "Updating the translation files from the agama-weblate repository"
env:
GH_TOKEN: ${{ github.token }}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
**Checks**

[![CI Status](https://github.com/openSUSE/agama/actions/workflows/ci.yml/badge.svg)](https://github.com/openSUSE/agama/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/openSUSE/agama/badge.svg?branch=master)](https://coveralls.io/github/openSUSE/agama?branch=master)
[![GitHub Pages](https://github.com/openSUSE/agama/actions/workflows/github-pages.yml/badge.svg)](https://github.com/openSUSE/agama/actions/workflows/github-pages.yml)

**Translations**

[![Weblate Update POT](https://github.com/openSUSE/agama/actions/workflows/weblate-update-pot.yml/badge.svg)](https://github.com/openSUSE/agama/actions/workflows/weblate-update-pot.yml)
[![Weblate Merge PO](https://github.com/openSUSE/agama/actions/workflows/weblate-merge-po.yml/badge.svg)](https://github.com/openSUSE/agama/actions/workflows/weblate-merge-po.yml)
[![Translation Status](https://l10n.opensuse.org/widgets/agama/-/agama-web/svg-badge.svg)](https://l10n.opensuse.org/engage/agama/)

**[OBS systemsmanagement:Agama:Staging](https://build.opensuse.org/project/show/systemsmanagement:Agama:Staging)**

[![Submit agama-cli](https://github.com/openSUSE/agama/actions/workflows/obs-staging-rust.yml/badge.svg)](https://github.com/openSUSE/agama/actions/workflows/obs-staging-rust.yml)
Expand Down
39 changes: 0 additions & 39 deletions web/po/de.po

This file was deleted.

Loading
Loading