Skip to content

Commit f31073c

Browse files
committed
fix: Enhance error handling and notices in SSH setup scripts
- Added `set -e` to `action.sh` for immediate exit on error. - Improved log notices for created known hosts files. - Adjusted conditional checks in `check.sh` and `post_check.sh` to use `[[` for better compatibility.
1 parent 017b206 commit f31073c

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

action.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
set -e
4+
35
mkdir -p "$(dirname "${SSH_KNOWN_HOSTS_FILE}")"
46

57
if [ -z "${SSH_HOST}" ] && [ -z "${SSH_KNOWN_HOSTS}" ]; then
@@ -13,6 +15,7 @@ else
1315
Both 'ssh-host' and 'ssh-known-hosts' inputs are set. Using 'ssh-known-hosts'."
1416
fi
1517
echo "${SSH_KNOWN_HOSTS}" >> "${SSH_KNOWN_HOSTS_FILE}"
18+
echo "::notice file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Notice::${SSH_KNOWN_HOSTS_FILE} has been created."
1619
else
1720
echo "::warning file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Security risk::\
1821
If an ssh_known_hosts file is constructed using ssh-keyscan without verifying the keys, \
@@ -33,5 +36,6 @@ Failed to scan SSH host keys for ${SSH_HOST}"
3336
exit 1
3437
fi
3538
fi
39+
echo "::notice file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Notice::${SSH_KNOWN_HOSTS_FILE} has been created."
3640
fi
3741
fi

check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
if [ ! -s ~/.ssh/known_hosts ]; then
3+
if [[ ! -s ~/.ssh/known_hosts ]]; then
44
echo "::error file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Assertion Error::\
55
~/.ssh/known_hosts is missing or empty."
66
exit 1

post_check.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
if [ -s ~/.ssh/known_hosts ]; then
3+
if [[ -s ~/.ssh/known_hosts ]]; then
44
echo "::error file=$(basename "$0"),line=${LINENO},endLine=${LINENO},title=Assertion Error::\
55
~/.ssh/known_hosts file should not exist after the job."
66
exit 1

0 commit comments

Comments
 (0)