-
-
Notifications
You must be signed in to change notification settings - Fork 8
294 lines (279 loc) · 11.5 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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
name: Update repo
on:
push:
branches:
- master
paths:
- '.github/workflows/repo-update.yml'
schedule:
- cron: '0,30 0-23 * * *'
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true
jobs:
check-repo:
runs-on: ubuntu-latest
strategy:
matrix:
target_repo: [main@aarch64, main@arm, main@i686, main@x86_64, x11@aarch64, x11@arm, x11@i686, x11@x86_64, root@aarch64, root@arm, root@i686, root@x86_64]
fail-fast: false
steps:
- name: Clone check-tools
run: git clone "https://termux-pacman-bot:${{ secrets.TOKEN }}@github.com/termux-pacman/check-tools"
- name: Import key of Termux-Pacman
run: gpg --keyserver keyserver.ubuntu.com --recv-keys 998de27318e867ea976ba877389ceed64573dfca
- name: Clone termux-packages
run: |
cd check-tools
bash ./clone_repos.sh
- name: Running a scan
run: |
target_repo='${{ matrix.target_repo }}'
REPO="${target_repo%%@*}"
ARCH="${target_repo#*@}"
TOTAL="RESULT.${REPO}.${ARCH}"
DIR_REPO="termux-packages-repo/"
case "$REPO" in
"main") DIR_REPO+="packages";;
"x11") DIR_REPO+="x11-packages";;
"root") DIR_REPO+="root-packages";;
*)
echo "Error: repo '${REPO}' is unknown"
exit 0;;
esac
cd check-tools
if [ ! -d "$DIR_REPO" ]; then
echo "Error: '$DIR_REPO' not found."
exit 0
fi
bash ./check_pkgs_by_repo.sh "$REPO" "$ARCH" "$DIR_REPO"
# Removing packages...
DELETED_FILE="./output/$(date +%s)-deleted_termux-${REPO}_packages.txt"
for reason in NOTSUPPORTARCH UNKNOWN; do
infofile="./output/${reason}.${REPO}.${ARCH}"
if [ -f "${infofile}" ]; then
cat "${infofile}" >> "${DELETED_FILE}"
fi
done
if [ -f "${DELETED_FILE}" ]; then
# Install aws-cli
git clone https://github.com/termux-pacman/aws-cli-action
./aws-cli-action/setup.sh '${{ secrets.AWS_ACCESS_KEY_ID }}' '${{ secrets.AWS_ACCESS_KEY }}' '${{ secrets.AWS_REGION }}'
# Import gpg key
mkdir gk
echo "${{ secrets.SF_GPG_BOT }}" > gk/termux-pacman-bot.gpg
gpg --pinentry-mode=loopback --passphrase '${{ secrets.PW_GPG_BOT }}' --import gk/termux-pacman-bot.gpg
rm -fr gk
# Upload file
echo "$(sed '/^[[:space:]]*$/d' ${DELETED_FILE} | sort | uniq)" > "${DELETED_FILE}"
gpg --batch --pinentry-mode=loopback --passphrase '${{ secrets.PW_GPG_BOT }}' --detach-sign --use-agent -u '${{ secrets.KEY_GPG_BOT }}' --no-armor "${DELETED_FILE}"
for format_file in "" ".sig"; do
aws s3 cp "${DELETED_FILE}${format_file}" s3://'${{ secrets.SFPU }}'/${REPO}/${ARCH}/"${DELETED_FILE##*/}${format_file}"
done
rm "${DELETED_FILE}.sig"
fi
mkdir total
touch ./total/${TOTAL}
for RESULT in "./output/"{NOTFOUND,DOESNOTMATCH}".${REPO}.${ARCH}"; do
if [ -f ${RESULT} ]; then
cat ${RESULT} | awk '{printf $1 "\n"}' >> ./total/${TOTAL}
fi
done
tar cf total-${{ matrix.target_repo }}-${{ github.sha }}.tar.gz ./total
- name: Store RESULT.* files
if: always()
uses: actions/upload-artifact@v4
with:
name: total-${{ matrix.target_repo }}-${{ github.sha }}
path: ./check-tools/total-${{ matrix.target_repo }}-${{ github.sha }}.tar.gz
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-pacman/termux-packages.git termux-packages-pacman
- name: Get RESULT.* files
uses: actions/[email protected]
with:
path: ./
- name: Creating a REBUILD-LIST-BUILD
run: |
for i in ./total-*/total-*.tar.gz; do
tar xf $i -C ./
done
rm -fr ./total-*/
touch ./REBUILD-LIST-BUILD
cd termux-packages-pacman
for i in $(sort ../total/RESULT.* | uniq); do
BUILD_SOURCE=$(ls */${i}/build.sh 2> /dev/null) || true
if [ -z "${BUILD_SOURCE}" ]; then
BUILD_SOURCE=$(ls */*/${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-BUILD) && [ $(($(expr $(expr $(date +%s) - $(git log -n 1 --date=format:'%s' --format=%cd -- $(dirname ${BUILD_SOURCE}))) / 3600) > 8)) = 1 ]; then
echo "${BUILD_SOURCE}" >> ../REBUILD-LIST-BUILD
fi
done
cd ..
- name: Clone root repository
run: git clone https://github.com/termux/termux-packages.git
- 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 termux-packages-pacman
rm -fr */
cd ../termux-packages
cp -r * ../termux-packages-pacman
# Get list pkg
info "Get list pkg"
cd ../termux-packages-pacman
list_files=" "
for i in $(git status -s packages root-packages x11-packages | awk '{print $2}'); do
dir_sp=(${i//// })
if ! grep -q " ${dir_sp[0]}/${dir_sp[1]} " <<< "$list_files"; then
list_files+="${dir_sp[0]}/${dir_sp[1]} "
source_build="${dir_sp[0]}/${dir_sp[1]}/build.sh"
if $(grep -q '^'${source_build}'$' ../REBUILD-LIST-BUILD); then
sed -i "/^${source_build////'\/'}$/d" ../REBUILD-LIST-BUILD
fi
fi
done
list_files=($list_files)
# Sort list pkg
info "Sort list pkg"
cd ../termux-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 ../termux-packages-pacman
needbuild=false
if $(git log -1 --pretty=%B | grep -q '%needbuild'); then
needbuild=true
fi
git config --global user.name "termux-pacman-bot"
git config --global user.email "[email protected]"
git remote set-url origin "https://termux-pacman-bot:${{ secrets.TOKEN }}@github.com/termux-pacman/termux-packages.git"
commit "Update system repo"
git add .
git reset packages root-packages x11-packages README.md SECURITY.md repo.json
{
git commit -m "Update repo"
git push origin master
} || true
commit "Update repo packages"
install_list_issues
for i in $sort_list_files; do
i_sp=(${i//###/ })
commit " ${i_sp[1]}"
cd ../termux-packages
commit_file="$(git show -s --format=%B ${i_sp[0]})"
cd ../termux-packages-pacman
git add $(sed 's/&&/ /g' <<< "${i_sp[1]}")
{
if $needbuild; then
git commit -m "$(sed 's/%ci:no-build//g; s/\[skip ci\]//g' <<< $commit_file)"
else
git commit -m "$commit_file"
fi
git push origin master
} || true
for j in $(sed 's/&&/ /g' <<< "${i_sp[1]}"); do
while read LINE; do
USER=$(awk -F ' // ' '{printf $1}' <<< "$LINE")
STATE=$(awk -F ' // ' '{printf $2}' <<< "$LINE")
TITLE=$(awk -F ' // ' '{printf $4}' <<< "$LINE")
if [ $STATE != "open" ] || [ $USER != "termux-pacman-bot" ] || [[ $TITLE != "[AUTO-CHECK]: failed to recompile ${j}" ]]; then
continue
fi
NUMBER=$(awk -F ' // ' '{printf $3}' <<< "$LINE")
GH_TOKEN="${{ secrets.TOKEN }}" gh issue close ${NUMBER} \
-c "The package has been updated - https://github.com/termux-pacman/termux-packages/commit/$(git log -n 1 --format=%H -- ${j})."
install_list_issues
break
done <<< $(jq -r '.[] | "\(.user.login) \("//") \(.state) \("//") \(.number) \("//") \(.title)"' ../LIST-ISSUES)
done
done
# Recompile packages if necessary
if [ -n "$(cat ../REBUILD-LIST-BUILD)" ]; then
info "Rebuild packages"
listchanged=""
for i in $(cat ../REBUILD-LIST-BUILD); do
# It is necessary to create an issue because the package has
# a compilation error even after recompilation.
if [[ $(git log -n 1 --format=%B -- "${i}") = "rebuild($(dirname ${i})): auto check by @termux-pacman-bot" ]] && \
[[ $(git log -n 1 --format=%an -- "${i}") = "termux-pacman-bot" ]] && \
[[ $(git log -n 1 --format=%ae -- "${i}") = "[email protected]" ]]; then
if ! $(jq -r '.[] | "\(.user.login) \("/") \(.state) \("/") \(.title)"' ../LIST-ISSUES | grep -q "^termux-pacman-bot / open / \[AUTO-CHECK\]:.*$(dirname ${i})$"); then
commit "Create an issue on $(dirname ${i})"
GH_TOKEN="${{ secrets.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/termux-pacman/termux-packages/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-pacman/auto-check-repo: preparing to recompile packages\n[skip ci]")"
git push origin master
for i in ${listchanged}; do
sed -i '$d' ./${i}
git add ./${i}
git commit -m "rebuild($(dirname ${i})): auto check by @termux-pacman-bot"
git push origin master
done
fi
fi