From 5ca36a784d804842c53ff6ba5e1eea64e0c6dce6 Mon Sep 17 00:00:00 2001 From: Carles Pina i Estany Date: Mon, 25 Oct 2021 23:55:36 +0100 Subject: [PATCH] If no directory to be deleted avoids... deleting the directory --- action.yml | 2 +- entrypoint.sh | 45 ++++++++++++++++++++++----------------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/action.yml b/action.yml index 2195505..5237bb6 100644 --- a/action.yml +++ b/action.yml @@ -46,7 +46,7 @@ inputs: required: false target-directory: description: '[Optional] The directory to wipe and replace in the target repository' - default: . + default: '' required: false runs: diff --git a/entrypoint.sh b/entrypoint.sh index 3ad65e4..3fdad50 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,31 +41,30 @@ TEMP_DIR=$(mktemp -d) # including "." and with the exception of ".git/" mv "$CLONE_DIR/.git" "$TEMP_DIR/.git" -echo "[+] Checking if $TARGET_DIRECTORY exist in git repo $DESTINATION_REPOSITORY_NAME" - -# Remove contents of target directory and create a new empty one -if [ -d "$CLONE_DIR/$TARGET_DIRECTORY/" ] +if [ -n "$TARGET_DIRECTORY" ] then - echo "[+] Deleting files from $TARGET_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME" - rm -R "$CLONE_DIR/$TARGET_DIRECTORY/" + echo "[+] Checking if $TARGET_DIRECTORY exist in git repo $DESTINATION_REPOSITORY_NAME" + + # Remove contents of target directory and create a new empty one + if [ -d "$CLONE_DIR/$TARGET_DIRECTORY/" ] + then + echo "[+] Deleting files from $TARGET_DIRECTORY in git repo $DESTINATION_REPOSITORY_NAME" + rm -R "$CLONE_DIR/$TARGET_DIRECTORY/" + fi + echo "[+] Creating $TARGET_DIRECTORY if doesnt already exist" + mkdir -p "$CLONE_DIR/$TARGET_DIRECTORY" + + mv "$TEMP_DIR/.git" "$CLONE_DIR/.git" + + echo "[+] Listing Current Directory Location" + ls -al + + echo "[+] Listing root Location" + ls -al / + + echo "[+] Listing /home Location" + ls -al /home fi -echo "[+] Creating $TARGET_DIRECTORY if doesnt already exist" -mkdir -p "$CLONE_DIR/$TARGET_DIRECTORY" - -mv "$TEMP_DIR/.git" "$CLONE_DIR/.git" - -echo "[+] Listing Current Directory Location" -ls -al -#echo "[+] Listing home+ Directory Location" -#ls -al /home/runner/work/Action_OpenWRT_AutoBuild_Linksys_Devices/Action_OpenWRT_AutoBuild_Linksys_Devices/openwrt -echo "[+] Listing root Location" -ls -al / -echo "[+] Listing /home Location" -ls -al /home - -# echo "[+] Changing to $SOURCE_BEFORE_DIRECTORY" -# cd "$SOURCE_BEFORE_DIRECTORY" - echo "[+] List contents of $SOURCE_DIRECTORY" ls "$SOURCE_DIRECTORY"