Skip to content

Commit

Permalink
add: ignore_error
Browse files Browse the repository at this point in the history
  • Loading branch information
k8scat committed Jan 6, 2022
1 parent 194776c commit 57fc312
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
echo "::set-output name=repo_list::${repo_list}"
- name: action-git-mirror
uses: k8scat/[email protected].26
uses: k8scat/[email protected].27
with:
source_protocol: https
source_host: github.com
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
os = $(shell uname -s)

version = 0.0.26
version = 0.0.27
image = mirror-git:$(version)

cr_user = gigrator
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ docker run \
-e INPUT_FORCE_PUSH="false" \
-e INPUT_NOTIFY_PREFIX="Mirror Git" \
-e INPUT_NOTIFY_SUFFIX="Powered by https://github.com/k8scat/action-mirror-git" \
gigrator/mirror-git:0.0.26
gigrator/mirror-git:0.0.27
```

## LICENSE
Expand Down
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ inputs:
description: "Push the repository's Git Large File Storage objects"
required: false
default: "false"
ignore_error:
description: "Ignore error, true or false"
required: false
default: "false"
runs:
using: "docker"
image: "docker://ghcr.io/k8scat/mirror-git:0.0.26"
image: "docker://ghcr.io/k8scat/mirror-git:0.0.27"
41 changes: 39 additions & 2 deletions mirror.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function init_env() {
export INPUT_NOTIFY_PREFIX="${INPUT_NOTIFY_PREFIX:-Mirror Git}"
export INPUT_NOTIFY_SUFFIX="${INPUT_NOTIFY_SUFFIX:-Powered by https://github.com/k8scat/action-mirror-git}"
export INPUT_ENABLE_GIT_LFS="${INPUT_ENABLE_GIT_LFS:-false}"
export INPUT_IGNORE_ERROR="${INPUT_IGNORE_ERROR:-false}"
}

function init_git() {
Expand Down Expand Up @@ -204,13 +205,19 @@ function mirror() {

if ! git clone --bare "${source_addr}" "${REPO_NAME}"; then
notify "Failed to clone ${source_addr}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi

if [[ -n "${INPUT_DEST_CREATE_REPO_SCRIPT}" ]]; then
echo "Creating repo: ${REPO_NAME}"
if ! create_repo; then
notify "Failed to create repo: ${REPO_NAME}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi
fi
Expand All @@ -225,17 +232,26 @@ function mirror() {
echo "Deleting repo: ${REPO_NAME}"
if ! delete_repo; then
notify "Failed to delete repo: ${REPO_NAME}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi

echo "Creating repo: ${REPO_NAME}"
if ! create_repo; then
notify "Failed to create repo: ${REPO_NAME}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi

if ! git push --all -f "${dest_addr}"; then
notify "Still failed to push ${REPO_NAME} to ${dest_addr} with --all flag"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi
fi
Expand All @@ -247,17 +263,26 @@ function mirror() {
echo "Deleting repo: ${REPO_NAME}"
if ! delete_repo; then
notify "Failed to delete repo: ${REPO_NAME}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi

echo "Creating repo: ${REPO_NAME}"
if ! create_repo; then
notify "Failed to create repo: ${REPO_NAME}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi

if ! git push --mirror -f "${dest_addr}"; then
notify "Still failed to push ${REPO_NAME} to ${dest_addr} with --mirror flag"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi
fi
Expand All @@ -266,8 +291,20 @@ function mirror() {

if [[ "${INPUT_ENABLE_GIT_LFS}" = "true" ]]; then
cd "${REPO_NAME}" || return 1
git lfs fetch --all
git lfs push --all "${dest_addr}"
if ! git lfs fetch --all; then
notify "Failed to fetch lfs for ${REPO_NAME}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi
if ! git lfs push --all "${dest_addr}"; then
notify "Failed to push lfs for ${dest_addr}"
if [[ "${INPUT_IGNORE_ERROR}" = "true" ]]; then
continue
fi
return 1
fi
fi
done
}
Expand Down

0 comments on commit 57fc312

Please sign in to comment.