Skip to content

Commit

Permalink
Add timeout support
Browse files Browse the repository at this point in the history
  • Loading branch information
Yikun committed Oct 31, 2020
1 parent 200747b commit 6a75f23
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,19 @@ steps:
debug: true
```

#### 设置命令行超时时间为1小时
```yaml
- name: Mirror with force push (git push -f)
uses: Yikun/hub-mirror-action@master
with:
src: github/Yikun
dst: gitee/yikunkero
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
force_update: true
timeout: '1h'
```

## FAQ

- 如何在secrets添加dst_token和dst_key?
Expand Down
13 changes: 13 additions & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,19 @@ Here is a workflow to mirror the kunpengcompute org repos from Github to Gitee,
debug: true
```

#### Set command timeout to an hour
```yaml
- name: Mirror with force push (git push -f)
uses: Yikun/hub-mirror-action@master
with:
src: github/Yikun
dst: gitee/yikunkero
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
force_update: true
timeout: '1h'
```

## FAQ
- How to use `secrets` to add token and key?

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ inputs:
debug:
description: "Enable the debug flag to show detail log"
default: false
timeout:
description: "Set the timeout for every git command, like '600'=>600s, '1m'=>1 mins, '1h'=>1 hours"
default: '600'
runs:
using: "docker"
image: "Dockerfile"
Expand Down
10 changes: 6 additions & 4 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ FORCE_UPDATE="${INPUT_FORCE_UPDATE}"

DELAY_EXIT=false

TIME_OUT="${INPUT_TIMEOUT}"

function err_exit {
echo -e "\033[31m $1 \033[0m"
exit 1
Expand Down Expand Up @@ -122,7 +124,7 @@ 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
timeout $TIME_OUT git clone $SRC_REPO_BASE_URL$SRC_ACCOUNT/$1.git
fi
cd $1
}
Expand All @@ -145,17 +147,17 @@ function create_repo
function update_repo
{
echo -e "\033[31m(1/3)\033[0m" "Updating..."
git pull -p
timeout $TIME_OUT git pull -p
}

function import_repo
{
echo -e "\033[31m(2/3)\033[0m" "Importing..."
git remote set-head origin -d
if [[ "$FORCE_UPDATE" == "true" ]]; then
git push -f $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
timeout $TIME_OUT git push -f $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
else
git push $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
timeout $TIME_OUT git push $DST_TYPE refs/remotes/origin/*:refs/heads/* --tags --prune
fi
}

Expand Down

0 comments on commit 6a75f23

Please sign in to comment.