Update repo #11075
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: | |
- main | |
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-app.git | |
- name: Clone root repository | |
run: git clone https://github.com/termux/termux-app.git termux-app-sync | |
- name: Update repo | |
run: | | |
info() { | |
echo "==> $1" | |
} | |
commit() { | |
echo "-> $1" | |
} | |
# Edit | |
info "Edit" | |
cd termux-app | |
rm -fr */ | |
cd ../termux-app-sync | |
cp -r * ../termux-app | |
cd ../termux-app | |
# Get list pkg | |
info "Get list pkg" | |
cd ../termux-app | |
list_files=" " | |
for i in $(git status -s app art docs fastlane gradle terminal-emulator terminal-view termux-shared | 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-app-sync | |
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-app | |
#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-app.git" | |
commit "Update system repo" | |
git add . | |
git reset app art docs fastlane gradle terminal-emulator terminal-view termux-shared | |
{ | |
git branch -M main | |
git commit -m "Update repo" | |
git push origin main | |
} || true | |
commit "Update repo packages" | |
for i in $sort_list_files; do | |
i_sp=(${i//###/ }) | |
commit " ${i_sp[1]}" | |
cd ../termux-app-sync | |
commit_file="$(git show -s --format=%B ${i_sp[0]})" | |
cd ../termux-app | |
git add $(echo ${i_sp[1]} | sed 's/&&/ /g') | |
{ | |
git commit -m "$commit_file" | |
git push origin master | |
} || true | |
done |