Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle the empty repo sync #73

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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