From 7fe247c8f8d180a008d9b7d285d5643b81423f3d Mon Sep 17 00:00:00 2001 From: Yikun Jiang Date: Thu, 12 Mar 2020 20:19:09 +0800 Subject: [PATCH] Add cache path Add a `cache_path` feature to allow user set the secific cache_path to cache the git repo. And user can use it to set the cache path, coordinate with [action/cache](https://github.com/actions/cache) to speed up the mirror. Closes: #13 --- .../workflows/verify-on-ubuntu-org-cache.yml | 36 +++++++++++++++++++ .github/workflows/verify-on-ubuntu-org.yml | 2 +- .github/workflows/verify-on-ubuntu-user.yml | 2 +- action.yml | 4 +++ entrypoint.sh | 13 +++++++ 5 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/verify-on-ubuntu-org-cache.yml diff --git a/.github/workflows/verify-on-ubuntu-org-cache.yml b/.github/workflows/verify-on-ubuntu-org-cache.yml new file mode 100644 index 00000000..309ca614 --- /dev/null +++ b/.github/workflows/verify-on-ubuntu-org-cache.yml @@ -0,0 +1,36 @@ +on: push +name: cache-test +jobs: + run: + name: Run + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v1 + + - name: Cache src repos + uses: actions/cache@v1 + id: cache + with: + path: /hub-mirror-action + key: ${{ runner.os }}-cache-kunpeng-repos + restore-keys: | + ${{ runner.os }}-cache-kunpeng-repos + + - name: Prepare the cache path + run: | + sudo mkdir -p /hub-mirror-action + sudo chown -R $(whoami):$(id -ng) /hub-mirror-action + + - name: Print the cache status + if: steps.cache.outputs.cache-hit == 'true' + run: echo "Cached successfully." + + - name: Mirror Github to Gitee + uses: ./. + with: + src: github/kunpengcompute + dst: gitee/kunpengcompute + dst_key: ${{ secrets.GITEE_PRIVATE_KEY }} + dst_token: ${{ secrets.GITEE_TOKEN }} + cache_path: /hub-mirror-action diff --git a/.github/workflows/verify-on-ubuntu-org.yml b/.github/workflows/verify-on-ubuntu-org.yml index 3bbddb4b..f09172e6 100644 --- a/.github/workflows/verify-on-ubuntu-org.yml +++ b/.github/workflows/verify-on-ubuntu-org.yml @@ -1,5 +1,5 @@ on: push -name: Hub Action test for org account +name: account-test(org) jobs: run: name: Run diff --git a/.github/workflows/verify-on-ubuntu-user.yml b/.github/workflows/verify-on-ubuntu-user.yml index f5237555..ca0e2815 100644 --- a/.github/workflows/verify-on-ubuntu-user.yml +++ b/.github/workflows/verify-on-ubuntu-user.yml @@ -1,5 +1,5 @@ on: push -name: Hub Action test for user account +name: account-test(user) jobs: run: name: Run diff --git a/action.yml b/action.yml index 448e0843..8dc26022 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..8069281b 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,17 @@ 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 + +ls -la / + +sudo chown -R $(whoami):$(id -ng) + +ls -la / + for repo in $SRC_REPOS { echo -e "\n\033[31mBackup $repo ...\033[0m"