-
Notifications
You must be signed in to change notification settings - Fork 7
248 lines (241 loc) · 9.3 KB
/
repo-update.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
name: Update repo
on:
push:
branches:
- main
paths:
- '.github/workflows/repo-update.yml'
- 'scripts-checking/**'
pull_request:
paths:
- '.github/workflows/repo-update.yml'
- 'scripts-checking/**'
schedule:
- cron: '0,30 0-23 * * *'
jobs:
check-repo:
runs-on: ubuntu-latest
strategy:
matrix:
arch: [aarch64, arm, i686, x86_64]
fail-fast: false
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 1000
- name: Running a scan
run: ./scripts-checking/start.sh '${{ matrix.arch }}'
- name: Creating a result list
run: |
result_file="./result-checking/RESULT-${{ matrix.arch }}"
touch "${result_file}"
for i in PKG_NOT_FOUND VER_NOT_FOUND; do
path_log_file="./result-checking/${i}.${{ matrix.arch }}"
if [ -f "${path_log_file}" ]; then
cat "${path_log_file}" >> "${result_file}"
fi
done
- name: Store RESULT-* files
if: always()
uses: actions/upload-artifact@v4
with:
name: result-${{ matrix.arch }}-${{ github.sha }}
path: ./result-checking/RESULT-${{ matrix.arch }}
if-no-files-found: error
update-repo:
needs: check-repo
runs-on: ubuntu-latest
steps:
- name: Clone repository
run: git clone https://github.com/termux/glibc-packages.git glibc-packages-mirror
- name: Clone root repository
run: git clone https://github.com/termux-pacman/glibc-packages.git
- name: Get RESULT-* files
uses: actions/download-artifact@v4
with:
path: ./
- name: Creating a REBUILD-LIST
run: |
touch REBUILD-LIST
cd glibc-packages-mirror
for i in $(sort ../result-*/RESULT-* | uniq); do
BUILD_SOURCE=$(ls gpkg/${i}/build.sh 2> /dev/null) || true
if [ -z "${BUILD_SOURCE}" ]; then
BUILD_SOURCE=$(ls gpkg/*/${i}.subpackage.sh 2> /dev/null) || true
if [ -n "${BUILD_SOURCE}" ]; then
BUILD_SOURCE="$(dirname ${BUILD_SOURCE})/build.sh"
else
echo "Source package '${i}' was not found, skip"
continue
fi
fi
if ! $(grep -q "^${BUILD_SOURCE}$" ../REBUILD-LIST) && [ $(($(expr $(expr $(date +%s) - $(git log -n 1 --date=format:'%s' --format=%cd -- $(dirname ${BUILD_SOURCE}))) / 3600) > 7)) = 1 ]; then
echo "${BUILD_SOURCE}" >> ../REBUILD-LIST
fi
done
cd ..
cat REBUILD-LIST
- name: Update repo
run: |
info() {
echo "==> $1"
}
commit() {
echo "-> $1"
}
install_list_issues() {
if [ -f ../LIST-ISSUES ]; then
rm ../LIST-ISSUES
fi
curl --header "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s -X GET -G \
"https://api.github.com/repos/${{ github.repository }}/issues" -o ../LIST-ISSUES
}
# Edit
info "Edit"
cd glibc-packages-mirror
rm -fr */
git checkout -- scripts-checking/
cd ../glibc-packages
cp -r * ../glibc-packages-mirror
# Get list pkg
info "Get list pkg"
cd ../glibc-packages-mirror
list_files=" "
for i in $(git status -s gpkg | awk '{print $2}'); do
dir_sp=(${i//// })
if [[ ! $(echo "$list_files" | grep " ${dir_sp[0]}/${dir_sp[1]} ") ]]; then
list_files+="${dir_sp[0]}/${dir_sp[1]} "
source_build="${dir_sp[0]}/${dir_sp[1]}/build.sh"
echo "${source_build}"
if $(grep -q '^'${source_build}'$' ../REBUILD-LIST); then
sed -i "/^${source_build////'\/'}$/d" ../REBUILD-LIST
fi
fi
done
list_files=($list_files)
# Sort list pkg
info "Sort list pkg"
cd ../glibc-packages
declare -A list_values
list_sort=""
list_sha=""
for i in ${list_files[@]}; do
sha_file=$(git log -n 1 --pretty=format:%H -- $i)
value="$(git rev-list --count $sha_file)"
list_values[${value}]=$((${list_values[${value}]}+1))
list_sort+="${value}-${list_values[${value}]} "
list_sha+="${sha_file} "
done
list_sort=($list_sort)
list_sha=($list_sha)
copy_list_sort=($(sort -n <(printf "%s\n" "${list_sort[@]}")))
search_index() {
for i in "${!list_sort[@]}"; do
if [[ "${list_sort[$i]}" = "${1}" ]]; then
echo "${i}";
fi
done
}
sort_list_files=""
for i in ${copy_list_sort[@]}; do
index=$(search_index "$i")
if [[ "${i#*-}" = "1" ]]; then
sort_list_files+=" ${list_sha[$index]}###"
else
sort_list_files+="&&"
fi
sort_list_files+="${list_files[$index]}"
done
# Start upload
info "Start upload"
cd ../glibc-packages-mirror
needbuild=false
if $(git log -1 --pretty=%B | grep -q '%needbuild'); then
needbuild=true
fi
git config --global user.name "Termux Github Actions"
git config --global user.email "[email protected]"
git remote set-url origin "https://termuxbot2:${{ secrets.TERMUXBOT2_TOKEN }}@github.com/${{ github.repository }}.git"
commit "Update system repo"
git add .
git reset README.md README-old.md repo.json cgct scripts-cgct gpkg
{
git commit -m "update repo contents"
if [ "${{ github.event_name }}" != "pull_request" ]; then
git push origin main
fi
} || true
commit "Update repo packages"
install_list_issues
for i in $sort_list_files; do
i_sp=(${i//###/ })
commit " ${i_sp[1]}"
cd ../glibc-packages
commit_file="$(git show -s --format=%B ${i_sp[0]})"
cd ../glibc-packages-mirror
git add $(echo ${i_sp[1]} | sed 's/&&/ /g')
{
# TEST
commit "$commit_file"
if $needbuild; then
git commit -m "$(echo $commit_file | sed '/%ci:no-build/d; /\[skip ci\]/d')"
else
git commit -m "$commit_file"
fi
if [ "${{ github.event_name }}" != "pull_request" ]; then
git push origin main
fi
} || true
for j in $(echo ${i_sp[1]} | sed 's/&&/ /g'); do
while read LINE; do
USER=$(echo "$LINE" | awk -F ' // ' '{printf $1}')
STATE=$(echo "$LINE" | awk -F ' // ' '{printf $2}')
TITLE=$(echo "$LINE" | awk -F ' // ' '{printf $4}')
if [ $STATE != "open" ] || [ $USER != "termuxbot2" ] || [[ $TITLE != "[AUTO-CHECK]: failed to recompile ${j}" ]]; then
continue
fi
NUMBER=$(echo "$LINE" | awk -F ' // ' '{printf $3}')
GH_TOKEN="${{ secrets.TERMUXBOT2_TOKEN }}" gh issue close ${NUMBER} \
-c "The package has been updated - https://github.com/${{ github.repository }}/commit/$(git log -n 1 --format=%H -- ${j})."
install_list_issues
break
done <<< $(jq -r '.[] | "\(.user.login) \("//") \(.state) \("//") \(.number) \("//") \(.title)"' ../LIST-ISSUES)
done
done
if [ -n "$(cat ../REBUILD-LIST)" ]; then
info "Rebuild packages"
listchanged=""
for i in $(cat ../REBUILD-LIST); do
if [[ $(git log -n 1 --format=%B -- "${i}") = "rebuild($(dirname ${i})): auto check by @termuxbot2" ]] && \
[[ $(git log -n 1 --format=%an -- "${i}") = "Termux Github Actions" ]] && \
[[ $(git log -n 1 --format=%ae -- "${i}") = "[email protected]" ]]; then
if ! $(jq -r '.[] | "\(.user.login) \("/") \(.state) \("/") \(.title)"' ../LIST-ISSUES | grep -q "^termuxbot2 / open / \[AUTO-CHECK\]:.*$(dirname ${i})$"); then
commit "Create an issue on $(dirname ${i})"
GH_TOKEN="${{ secrets.TERMUXBOT2_TOKEN }}" gh issue create \
--title "[AUTO-CHECK]: failed to recompile $(dirname ${i})" \
--body "$(echo -e "This issue was automatically generated because the '$(dirname ${i})' package was not recompiled successfully.\n\nCommit by recompilation - https://github.com/${{ github.repository }}/commit/$(git log -n 1 --format=%H -- ${i})")" \
--label "auto recompilation failed" \
--assignee Maxython
fi
continue
fi
echo "" >> ./${i}
git add ./${i}
listchanged+=" ${i}"
done
if [ -n "${listchanged}" ]; then
git commit -m "$(echo -e "termux/auto-check-repo: do not rebuild these packages again\n[skip ci]")"
if [ "${{ github.event_name }}" != "pull_request" ]; then
git push origin main
fi
for i in ${listchanged}; do
sed -i '$d' ./${i}
git add ./${i}
git commit -m "rebuild($(dirname ${i})): auto check by @termuxbot2"
if [ "${{ github.event_name }}" != "pull_request" ]; then
git push origin main
fi
done
fi
fi