From f2e54927ba74b44e4c52d62789d23de867f25b4a Mon Sep 17 00:00:00 2001 From: Marek Blaha Date: Wed, 8 Nov 2023 09:55:06 +0100 Subject: [PATCH] Workflow for *.po retrieval from weblate --- .../weblate-pull-translations/action.yml | 38 ++++++++++ .github/workflows/prepare-release.yml | 5 ++ .github/workflows/weblate-sync-po.yml | 70 +++++++++++++++++++ .github/workflows/weblate-sync-pot.yml | 2 +- 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 .github/actions/weblate-pull-translations/action.yml create mode 100644 .github/workflows/weblate-sync-po.yml diff --git a/.github/actions/weblate-pull-translations/action.yml b/.github/actions/weblate-pull-translations/action.yml new file mode 100644 index 000000000..8441cd56c --- /dev/null +++ b/.github/actions/weblate-pull-translations/action.yml @@ -0,0 +1,38 @@ +name: Retrieve *.po files from weblate repository + +runs: + using: "composite" + steps: + - name: Clone weblate repository + uses: actions/checkout@v4 + with: + repository: ${{ github.repository }}-l10n + path: .l10n + + - name: Copy *.po files from weblate repository + shell: bash + run: | + pushd .l10n + for component in $(find . -mindepth 1 -maxdepth 1 -type d -not -path './.*'); do + echo "XXX component: ${component}" + source_path="" + if [ -f "${component}/PATH" ]; then + read -r source_path < "${component}/PATH" + echo "XXX source_path: ${source_path}" + for po in "${component}"/*.po; do + if [ -f "$po" ]; then + echo "XXX po: ${po}" + cp "${po}" "../${source_path}/" + git add "../${source_path}/${po}" + fi + done + fi + done + popd + + - name: Commit *.po files + shell: bash + run: | + git config user.name "GitHub Workflow" + git config user.email "github-actions@github.com" + git commit -m "Update translations from weblate" diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml index 37f8d4e15..4b466d1d5 100644 --- a/.github/workflows/prepare-release.yml +++ b/.github/workflows/prepare-release.yml @@ -15,11 +15,16 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 + + - name: Update translations from weblate + uses: ./.github/actions/weblate-pull-translations + - name: Prepare release content uses: inknos/prepare-release@v1.1 with: version: ${{ inputs.version }} specfiles: dnf5.spec + - name: Create Pull Request uses: peter-evans/create-pull-request@v4 with: diff --git a/.github/workflows/weblate-sync-po.yml b/.github/workflows/weblate-sync-po.yml new file mode 100644 index 000000000..130c1781c --- /dev/null +++ b/.github/workflows/weblate-sync-po.yml @@ -0,0 +1,70 @@ +name: Weblate - retrieve translations +on: + schedule: + # Run every monday morning + #- cron: '30 3 * * 1' + - cron: '25 * * * *' + workflow_dispatch: + +jobs: + po-refresh: + name: Retrieve *.po files from dnf5-l10n repository + runs-on: ubuntu-latest + steps: + - name: Clone source repository + uses: actions/checkout@v4 + with: + ssh-key: ${{ secrets.L10N_SSH_KEY }} + path: src + + - name: Clone weblate repository + uses: actions/checkout@v4 + with: + repository: ${{ github.repository }}-l10n + path: l10n + +# - name: Get branche name +# id: branch-name +# run: echo "BRANCH_NAME=weblate-sync-$(date +"%Y-%m-%d-%H-%M-%S")" >> $GITHUB_OUTPUT + +# - name: Prepare a new branch +# run: git -C src checkout -b ${{ steps.branch-name.outputs.BRANCH_NAME }} + + - name: Copy .po files from weblate repository + run: | + pushd l10n + for component in $(find . -mindepth 1 -maxdepth 1 -type d -not -path './.*'); do + source_path="" + if [ -f "${component}/PATH" ]; then + read -r source_path < "${component}/PATH" + for po in "${component}"/*.po; do + if [ -f "$po" ]; then + cp "${po}" "../src/${source_path}/" + fi + done + fi + done + popd + + - name: Create a pull request + uses: peter-evans/create-pull-request@v4 + with: + commit-message: Update translations from Fedora Weblate + title: Update translations from Fedora Weblate + body: Created automatically by Github action + delete-branch: true + path: src + push-to-fork: rpmsoftwaremanagement-l10n/dnf5 + +# - name: Create a pull request +# env: +# GH_TOKEN: ${{ github.token }} +# run: | +# git config --global user.name "GitHub Workflow" +# git config --global user.email "mblaha@redhat.com" +# pushd src +# git add "*" +# git commit -m "Update translations from Fedora Weblate" +# git push -u origin ${{ steps.branch-name.outputs.BRANCH_NAME }} +# gh pr create -B main -H ${{ steps.branch-name.outputs.BRANCH_NAME }} --title 'Update translations from Fedora Weblate' --body 'Created automatically by Github action' +# popd diff --git a/.github/workflows/weblate-sync-pot.yml b/.github/workflows/weblate-sync-pot.yml index 5701b8635..7debcc059 100644 --- a/.github/workflows/weblate-sync-pot.yml +++ b/.github/workflows/weblate-sync-pot.yml @@ -36,7 +36,7 @@ jobs: - name: Commit .pot to weblate repo run: | git config --global user.name "GitHub Workflow" - git config --global user.email "mblaha@redhat.com" + git config --global user.email "github-actions@github.com" pushd src for f in $(find * -type f -name "*.pot"); do potfile=$(basename $f)