diff --git a/.github/workflows/verify-on-ubuntu-org.yml b/.github/workflows/verify-on-ubuntu-org.yml index 02040ec0..04867596 100644 --- a/.github/workflows/verify-on-ubuntu-org.yml +++ b/.github/workflows/verify-on-ubuntu-org.yml @@ -15,3 +15,6 @@ jobs: dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} dst_token: ${{ secrets.GITEE_TOKEN }} account_type: org + # Only sync Kunpeng + black_list: 'KAE' + white_list: 'KAE,Kunpeng' diff --git a/.github/workflows/verify-on-ubuntu-user-cache.yml b/.github/workflows/verify-on-ubuntu-user-cache.yml index 349f0c6d..51461ca6 100644 --- a/.github/workflows/verify-on-ubuntu-user-cache.yml +++ b/.github/workflows/verify-on-ubuntu-user-cache.yml @@ -19,7 +19,7 @@ jobs: if: steps.cache.outputs.cache-hit == 'true' run: echo "Cached successfully." - - name: Mirror Github to Gitee + - name: Mirror Github to Gitee with white list and cache uses: ./. with: src: github/Yikun @@ -27,6 +27,7 @@ jobs: dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} dst_token: ${{ secrets.GITEE_TOKEN }} cache_path: /github/workspace/hub-mirror-cache + white_list: 'hub-mirror-action, hexo-migrator-github-issue' - name: Print cache path run: | diff --git a/.github/workflows/verify-on-ubuntu-user.yml b/.github/workflows/verify-on-ubuntu-user.yml index ab76cc94..31feec6e 100644 --- a/.github/workflows/verify-on-ubuntu-user.yml +++ b/.github/workflows/verify-on-ubuntu-user.yml @@ -7,10 +7,11 @@ jobs: steps: - name: Checkout source codes uses: actions/checkout@v1 - - name: Mirror Github to Gitee + - name: Mirror Github to Gitee with white list uses: ./. with: src: github/Yikun dst: gitee/yikunkero dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} dst_token: ${{ secrets.GITEE_TOKEN }} + white_list: 'hub-mirror-action' \ No newline at end of file diff --git a/action.yml b/action.yml index 071037ad..806bde0a 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,12 @@ inputs: cache_path: description: "The path to cache the source repos code." default: '/github/workspace/hub-mirror-cache' + black_list: + description: "Hight priority, the back list of mirror repo. like 'repo1,repo2,repo3'" + default: '' + white_list: + description: "Low priority, the white list of mirror repo. like 'repo1,repo2,repo3'" + default: '' runs: using: "docker" image: "Dockerfile" @@ -37,3 +43,5 @@ runs: - ${{ inputs.account_type }} - ${{ inputs.clone_style }} - ${{ inputs.cache_path }} + - ${{ inputs.black_list }} + - ${{ inputs.white_list }} diff --git a/entrypoint.sh b/entrypoint.sh index 8fd73fb8..582e57e0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -22,6 +22,9 @@ CLONE_STYLE="${INPUT_CLONE_STYLE}" CACHE_PATH="${INPUT_CACHE_PATH}" +WHITE_LIST="${INPUT_WHITE_LIST}" +BLACK_LIST="${INPUT_BLACK_LIST}" + if [[ "$ACCOUNT_TYPE" == "org" ]]; then SRC_LIST_URL_SUFFIX=orgs/$SRC_ACCOUNT/repos DST_LIST_URL_SUFFIX=orgs/$DST_ACCOUNT/repos @@ -104,6 +107,33 @@ function import_repo git push $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune } +function _check_in_list () { + local e match="$1" + shift + for e; do [[ "$e" == "$match" ]] && return 0; done + return 1 +} + +function test_black_white_list +{ + WHITE_ARR=(`echo $WHITE_LIST | tr ',' ' '`) + BLACK_ARR=(`echo $BLACK_LIST | tr ',' ' '`) + _check_in_list $1 "${WHITE_ARR[@]}";in_white_list=$? + _check_in_list $1 "${BLACK_ARR[@]}";in_back_list=$? + + if [[ $in_back_list -ne 0 ]] ; then + if [[ -z $WHITE_LIST ]] || [[ $in_white_list -eq 0 ]] ; then + return 0 + else + echo "Skip, "$1" not in non-empty white list"$WHITE_LIST + return 1 + fi + else + echo "Skip, "$1 "in black list: "$BLACK_LIST + return 1 + fi +} + if [ ! -d "$CACHE_PATH" ]; then mkdir -p $CACHE_PATH fi @@ -111,20 +141,21 @@ cd $CACHE_PATH for repo in $SRC_REPOS { - echo -e "\n\033[31mBackup $repo ...\033[0m" + if test_black_white_list $repo ; then + echo -e "\n\033[31mBackup $repo ...\033[0m" - cd_src_repo $repo + cd_src_repo $repo - add_remote_repo $repo $DST_TOKEN + add_remote_repo $repo $DST_TOKEN - update_repo + update_repo - if [ $? -eq 0 ]; then - import_repo - else - echo -e "\033[31mUpdate failed.\033[0m" "" - fi + if [ $? -eq 0 ]; then + import_repo + else + echo -e "\033[31mUpdate failed.\033[0m" "" + fi - cd .. + cd .. + fi } -