-
Notifications
You must be signed in to change notification settings - Fork 1
153 lines (150 loc) · 6.15 KB
/
git-pot.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# CI workflows for po/git.pot: generate "po/git.pot" from git.git
# repository and show diffs on a daily basis.
#
# NOTE: must define the secret "PUSH_TOKEN" for this repository on GitHub.
#
name: git-pot
on:
# Schedule only works when the pipeline.yaml file is defined in default
# branch, i.e. the "main" branch.
schedule:
- cron: '51 */1 * * *'
# We can also trigger using manual event by an external schedule, when
# the schedule not works for some reasons, such as: the CI pipeline is
# not defined in the default branch.
workflow_dispatch:
push:
branches:
- main
jobs:
git-pot:
strategy:
matrix:
# Check the following branches of the git.git repository.
branch: [master, next, seen]
runs-on: ubuntu-latest
env:
AUTHOR_NAME: GotGit
AUTHOR_EMAIL: [email protected]
LOGIN_NAME: togtig
steps:
- name: skip if the commit was already tested
id: skip-if-redundant
run: |
git -c protocol.version=2 ls-remote https://github.com/git/git.git \
refs/heads/${{ matrix.branch }} >footprint.remote &&
(
wget -O footprint.last \
https://raw.githubusercontent.com/${{ github.repository }}/pot/${{ matrix.branch }}/.latest-footprint ||
true
) &&
if diff footprint.remote footprint.last
then
echo "status=skip" >> $GITHUB_OUTPUT
else
echo "status=no" >> $GITHUB_OUTPUT
fi
- name: clone pot/${{ matrix.branch }} branch of current repository
if: steps.skip-if-redundant.outputs.status != 'skip'
run: |
( git -c protocol.version=2 clone \
--depth 1 \
--single-branch --branch pot/${{ matrix.branch }} \
https://github.com/${{ github.repository }} pot-changes ||
( git init --initial-branch "pot/${{ matrix.branch }}" pot-changes &&
git -C pot-changes remote add origin \
https://github.com/${{ github.repository }}
)
) &&
cd pot-changes &&
git config user.name "${{ env.AUTHOR_NAME }}" &&
git config user.email "${{ env.AUTHOR_EMAIL }}" &&
mkdir -p po &&
if test ! -f README.md
then
echo "[![Build status](https://github.com/${{ github.repository }}/actions/workflows/git-pot.yml/badge.svg)](https://github.com/${{ github.repository }}/actions/workflows/git-pot.yml)" >README.md &&
echo >>README.md &&
echo "# Changes of \"po/git.pot\" in the ${{ matrix.branch }} branch" >>README.md &&
echo >>README.md &&
echo "This branch will be updated regularly by a robot. See:" >>README.md &&
echo >>README.md &&
echo " - \`po/git.pot\`: generated from the corresponding branch of the git.git repository." >>README.md &&
echo " - \`<YYYY-mm-dd>.diff\`: changes of \"po/git.pot\" since last update." >>README.md &&
git add README.md &&
git commit -m "doc: add README"
fi
- name: install dependencies
if: steps.skip-if-redundant.outputs.status != 'skip'
run: |
if ! type xgettext
then
sudo apt-get update -q &&
sudo apt-get install -q -y gettext
fi
- name: clone git repository
if: steps.skip-if-redundant.outputs.status != 'skip'
run: |
git -c protocol.version=2 clone \
--depth 1 \
--single-branch --branch ${{ matrix.branch }} \
https://github.com/git/git.git git
- name: generate po/git.pot
if: steps.skip-if-redundant.outputs.status != 'skip'
run: |
make -C git pot &&
if test ! -f pot-changes/po/git.pot; then
cp git/po/git.pot pot-changes/po/git.pot &&
cd pot-changes &&
git add po/git.pot &&
git commit -m "Initialize po/git.pot"
fi
- uses: actions/setup-go@v5
if: steps.skip-if-redundant.outputs.status != 'skip'
with:
go-version: '^1.18'
cache: false
- name: Install git-po-helper
if: steps.skip-if-redundant.outputs.status != 'skip'
run: go install github.com/git-l10n/git-po-helper@main
- name: upload changes and report
if: steps.skip-if-redundant.outputs.status != 'skip'
run: |
report_msg="" &&
cd pot-changes &&
mv ../footprint.remote .latest-footprint &&
mkdir -p po/ &&
if test -f po/git.pot
then
msgcat --no-location --sort-output --no-wrap po/git.pot |
sed -e '1,/^$/d' >po/git.pot.old
else
touch po/git.pot.old
fi &&
cp ../git/po/git.pot po/git.pot &&
msgcat --no-location --sort-output --no-wrap po/git.pot |
sed -e '1,/^$/d' >po/git.pot.new &&
date=$(date "+%Y-%m-%d") &&
diff=${date}.diff &&
if ! diff -q po/git.pot.old po/git.pot.new
then
printf "\n\n#################### $(date -R) ####################\n\n" >>"$diff"
( diff -u po/git.pot.old po/git.pot.new >>"$diff" || true ) &&
( cd ../git && git-po-helper check-pot 2>&1 || true ) >check-pot.txt &&
if test -s check-pot.txt
then
printf -- "\n\n-------------------- git-po-helper check-pot --------------------\n\n" >>"$diff" &&
cat check-pot.txt >>"$diff"
fi &&
git add po/git.pot "$diff" .latest-footprint &&
git commit -m "l10n: ${{ matrix.branch }}: changes of git.pot in $diff" &&
report_msg="** changes of 'po/git.pot' is reported in $diff **"
else
echo >&2 "** po/git.pot is not changed **"
git add .latest-footprint &&
( git commit -m "no l10n changes on $date" || true ) &&
report_msg="** nothing changed in 'po/git.pot' on $date **"
fi &&
git push \
https://${{ env.LOGIN_NAME }}:${{ secrets.PUSH_TOKEN }}@github.com/${{ github.repository }} \
HEAD &&
printf >&2 "\n$report_msg\n"