Skip to content

Commit

Permalink
Add cache path (#17)
Browse files Browse the repository at this point in the history
Add a `cache_path` feature to allow user to set the specific cache_path to cache the git repos.

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
  • Loading branch information
Yikun authored Mar 18, 2020
1 parent e2d8722 commit c4dc341
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify-on-ubuntu-org.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on: push
name: Hub Action test for org account
name: Tests / test-org-mirror
jobs:
run:
name: Run
Expand Down
33 changes: 33 additions & 0 deletions .github/workflows/verify-on-ubuntu-user-cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
on: push
name: Tests / test-user-mirror (cached)
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: /home/runner/work/hub-mirror-action/hub-mirror-action/hub-mirror-cache
key: ${{ runner.os }}-yikun-repos-cache

- 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/Yikun
dst: gitee/yikunkero
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
cache_path: /github/workspace/hub-mirror-cache

- name: Print cache path
run: |
ls -la /home/runner/work/hub-mirror-action/hub-mirror-action/hub-mirror-cache
2 changes: 1 addition & 1 deletion .github/workflows/verify-on-ubuntu-user.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
on: push
name: Hub Action test for user account
name: Tests / test-user-mirror
jobs:
run:
name: Run
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 source repos code."
default: '/github/workspace/hub-mirror-cache'
runs:
using: "docker"
image: "Dockerfile"
Expand All @@ -33,3 +36,4 @@ runs:
- ${{ inputs.dst }}
- ${{ inputs.account_type }}
- ${{ inputs.clone_style }}
- ${{ inputs.cache_path }}
7 changes: 7 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit c4dc341

Please sign in to comment.