-
Notifications
You must be signed in to change notification settings - Fork 43
109 lines (90 loc) · 3.53 KB
/
weblate-merge-po.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 "[email protected]"
- 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
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
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 }}