Update repo #26276
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Update repo | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- '.github/workflows/repo-update.yml' | |
schedule: | |
- cron: '0,30 0-23 * * *' | |
jobs: | |
update-repo: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Clone repository | |
run: | | |
git clone https://github.com/WTNLXTBL/termux-packages.git | |
mv termux-packages packages | |
- name: Clone root repository | |
run: git clone https://github.com/termux/termux-packages.git | |
- name: Update repo | |
run: | | |
info() { | |
echo "==> $1" | |
} | |
commit() { | |
echo "-> $1" | |
} | |
# Edit | |
info "Edit" | |
cd packages | |
rm -fr */ | |
cd ../termux-packages | |
cp -r * ../packages | |
# Get list pkg | |
info "Get list pkg" | |
cd ../packages | |
list_files=" " | |
for i in $(git status -s packages root-packages x11-packages | 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]} " | |
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 ../packages | |
#git config --global user.name "github-actions[bot]" | |
#git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "WTNLXTBL" | |
git config --global user.email "[email protected]" | |
git remote set-url origin "https://WTNLXTBL:${{ secrets.PAT }}@github.com/WTNLXTBL/termux-packages.git" | |
commit "Update system repo" | |
git add . | |
git reset packages root-packages x11-packages README.md | |
{ | |
git commit -m "Update repo" | |
git push origin master | |
} || true | |
commit "Update repo packages" | |
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 ../packages | |
git add $(echo ${i_sp[1]} | sed 's/&&/ /g') | |
{ | |
git commit -m "$commit_file" | |
git push origin master | |
} || true | |
done |