diff --git a/.github/workflows/verify-on-ubuntu-user-cache.yml b/.github/workflows/verify-on-ubuntu-user-cache.yml new file mode 100644 index 00000000..55c0a3a9 --- /dev/null +++ b/.github/workflows/verify-on-ubuntu-user-cache.yml @@ -0,0 +1,25 @@ +on: push +name: Hub Action test for user account +jobs: + run: + name: Run + runs-on: ubuntu-latest + steps: + - name: Checkout source codes + uses: actions/checkout@v1 + + - name: Cache src repos + uses: action/cache@v1 + with: + path: ~/.hub-mirror-action + key: ${{ runner.os }}-yikun + restore-keys: ${{ runner.os }}-yikun + + - name: Mirror Github to Gitee + uses: ./. + with: + src: github/Yikun + dst: gitee/yikunkero + dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} + dst_token: ${{ secrets.GITEE_TOKEN }} + cache_path: ~/.hub-mirror-action diff --git a/action.yml b/action.yml index 448e0843..663cbf50 100644 --- a/action.yml +++ b/action.yml @@ -23,6 +23,9 @@ inputs: clone_style: description: "The git clone style, https or ssh." default: 'https' + cache_path: + description: "The path to cache the src repos code." + default: '~/.hub-mirror-action' runs: using: "docker" image: "Dockerfile" @@ -33,3 +36,4 @@ runs: - ${{ inputs.dst }} - ${{ inputs.account_type }} - ${{ inputs.clone_style }} + - ${{ inputs.cache_path }} diff --git a/entrypoint.sh b/entrypoint.sh index a30d61a0..8fd73fb8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,6 +20,8 @@ DST_ACCOUNT=`basename $DST_HUB` CLONE_STYLE="${INPUT_CLONE_STYLE}" +CACHE_PATH="${INPUT_CACHE_PATH}" + if [[ "$ACCOUNT_TYPE" == "org" ]]; then SRC_LIST_URL_SUFFIX=orgs/$SRC_ACCOUNT/repos DST_LIST_URL_SUFFIX=orgs/$DST_ACCOUNT/repos @@ -102,6 +104,11 @@ function import_repo git push $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune } +if [ ! -d "$CACHE_PATH" ]; then + mkdir -p $CACHE_PATH +fi +cd $CACHE_PATH + for repo in $SRC_REPOS { echo -e "\n\033[31mBackup $repo ...\033[0m"