Skip to content

Commit

Permalink
Handle the empty repo sync
Browse files Browse the repository at this point in the history
Skip the empty repo backup and ++ the warning count
  • Loading branch information
Yikun committed Oct 31, 2020
1 parent 200747b commit d1abfcd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/verify-on-ubuntu-org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
- name: Mirror Github to Gitee
uses: ./.
with:
src: github/kunpengcompute
dst: gitee/kunpengcompute
src: github/hub-mirror-action
dst: gitee/hub-mirror-action
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
account_type: org
# Only sync Kunpeng
black_list: 'KAE'
white_list: 'KAE,Kunpeng,kunpengcompute.github.io'
# Sync normal and empty
white_list: 'normal,empty'
force_update: true
debug: true

37 changes: 27 additions & 10 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ STATIC_LIST="${INPUT_STATIC_LIST}"
FORCE_UPDATE="${INPUT_FORCE_UPDATE}"

DELAY_EXIT=false
WARNING_FLAG=false

function err_exit {
echo -e "\033[31m $1 \033[0m"
Expand All @@ -42,7 +43,12 @@ function err_exit {

function delay_exit {
echo -e "\033[31m $1 \033[0m"
DELAY_EXIT=true
if [[ "$WARNING_FLAG" == "true" ]]; then
warning=$(($warning + 1))
WARNING_FLAG=false
else
DELAY_EXIT=true
fi
}

if [[ "$ACCOUNT_TYPE" == "org" ]]; then
Expand Down Expand Up @@ -122,7 +128,12 @@ function clone_repo
{
echo -e "\033[31m(0/3)\033[0m" "Downloading..."
if [ ! -d "$1" ]; then
git clone $SRC_REPO_BASE_URL$SRC_ACCOUNT/$1.git
clone_res=`git clone $SRC_REPO_BASE_URL$SRC_ACCOUNT/$1.git 2>&1`
fi
is_empty=`echo $clone_res | grep "cloned an empty repository." | wc -l`
if [ $is_empty == 1 ]; then
WARNING_FLAG=true
return -1
fi
cd $1
}
Expand All @@ -134,9 +145,12 @@ function create_repo
if [ $has_repo == 0 ]; then
echo "Create non-exist repo..."
if [[ "$DST_TYPE" == "github" ]]; then
curl -s -H "Authorization: token $2" --data '{"name":"'$1'"}' $DST_REPO_CREATE_API > /dev/null
create_result=`curl -H "Authorization: token $2" --data '{"name":"'$1'"}' $DST_REPO_CREATE_API`
elif [[ "$DST_TYPE" == "gitee" ]]; then
curl -s -X POST --header 'Content-Type: application/json;charset=UTF-8' $DST_REPO_CREATE_API -d '{"name": "'$1'","access_token": "'$2'"}' > /dev/null
create_result=`curl -X POST --header 'Content-Type: application/json;charset=UTF-8' $DST_REPO_CREATE_API -d '{"name": "'$1'","access_token": "'$2'"}'`
fi
if [[ "$DEBUG" == "true" ]]; then
echo $create_result
fi
fi
git remote add $DST_TYPE git@$DST_TYPE.com:$DST_ACCOUNT/$1.git
Expand Down Expand Up @@ -194,28 +208,31 @@ cd $CACHE_PATH
all=0
success=0
skip=0
warning=0
for repo in $SRC_REPOS
{
all=$(($all + 1))
if test_black_white_list $repo ; then
echo -e "\n\033[31mBackup $repo ...\033[0m"

clone_repo $repo || echo "clone and cd failed"
cd $CACHE_PATH

clone_repo $repo || delay_exit "clone and cd failed" $repo || continue

create_repo $repo $DST_TOKEN || echo "create failed"
create_repo $repo $DST_TOKEN || delay_exit "create failed" $repo || continue

update_repo || echo "Update failed"
update_repo || delay_exit "Update failed" $repo || continue

import_repo && success=$(($success + 1)) || delay_exit "Push failed"
import_repo && success=$(($success + 1)) || delay_exit "Push failed" $repo || continue

cd ..
else
skip=$(($skip + 1))
fi
}

failed=$(($all - $skip - $success))
echo "Total: $all, skip: $skip, successed: $success, failed: $failed."
failed=$(($all - $skip - $success - $warning))
echo "Total: $all, skip: $skip, successed: $success, warning: $warning, failed: $failed."

if [[ "$DELAY_EXIT" == "true" ]]; then
exit 1
Expand Down

0 comments on commit d1abfcd

Please sign in to comment.