Skip to content

Commit 66aa4d3

Browse files
authored
ci: add SSH testing job to GitHub Actions workflow (#355)
* ci: add SSH testing job to GitHub Actions workflow #335 (comment) - Add a new job `testing-script-stop` to the GitHub Actions workflow - Set up an SSH server using a Docker container within the new job - Capture the container's IP address and store it in the GitHub environment - Add a step to run an SSH command with stdout capture - Include a script to test conditional logic within the SSH command - Add a step to check and print the captured stdout from the SSH command Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * ci: improve GitHub Actions workflow with conditional checks - Add conditional checks in GitHub Actions workflow to handle 'True' and 'False' outputs Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> * ci: standardize naming and validation of stdout steps - Rename `stdout` step to `stdout01` in the GitHub Actions workflow - Rename `check stdout` step to `check stdout 01` - Update references to `stdout` to `stdout01` in echo and grep commands - Add a new step `stdout02` for SSH command execution with stdout capture - Add a new step `check stdout 02` to validate the output of `stdout02` step Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com> --------- Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
1 parent 102c0d2 commit 66aa4d3

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

.github/workflows/main.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,3 +594,90 @@ jobs:
594594
- name: check stdout
595595
run: |
596596
echo "stdout: ${{ steps.stdout.outputs.stdout }}"
597+
598+
testing-script-stop:
599+
runs-on: ubuntu-latest
600+
steps:
601+
- name: Checkout code
602+
uses: actions/checkout@v4
603+
604+
- name: create new ssh server
605+
run: |
606+
docker run -d \
607+
--name=openssh-server \
608+
--hostname=openssh-server \
609+
-p 2222:2222 \
610+
-e SUDO_ACCESS=false \
611+
-e PASSWORD_ACCESS=true \
612+
-e USER_PASSWORD=password \
613+
-e USER_NAME=linuxserver.io \
614+
--restart unless-stopped \
615+
lscr.io/linuxserver/openssh-server:latest
616+
docker exec openssh-server sh -c "hostname -i" > ip.txt
617+
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV
618+
cat ip.txt >> $GITHUB_ENV
619+
echo "EOF" >> $GITHUB_ENV
620+
echo "======= container ip address ========="
621+
cat ip.txt
622+
echo "======================================"
623+
sleep 2
624+
625+
- id: stdout01
626+
name: ssh command with stdout 01
627+
uses: ./
628+
with:
629+
host: ${{ env.REMOTE_HOST }}
630+
username: linuxserver.io
631+
password: password
632+
port: 2222
633+
capture_stdout: true
634+
script: |
635+
#!/usr/bin/env bash
636+
set -e
637+
echo "TMP TESTING IF"
638+
if [[ "2" == "1" ]]; then
639+
echo "True"
640+
else
641+
echo "False"
642+
fi
643+
644+
- name: check stdout 01
645+
run: |
646+
echo "stdout: ${{ steps.stdout01.outputs.stdout }}"
647+
if echo "${{ steps.stdout01.outputs.stdout }}" | grep -q "True"; then
648+
echo "Output contains 'True'"
649+
exit 1
650+
fi
651+
if echo "${{ steps.stdout01.outputs.stdout }}" | grep -q "False"; then
652+
echo "Output contains 'False'"
653+
fi
654+
655+
- id: stdout02
656+
name: ssh command with stdout 01
657+
uses: ./
658+
with:
659+
host: ${{ env.REMOTE_HOST }}
660+
username: linuxserver.io
661+
password: password
662+
port: 2222
663+
capture_stdout: true
664+
script: |
665+
#!/usr/bin/env bash
666+
set -e
667+
echo "TMP TESTING IF"
668+
if [[ "1" == "1" ]]; then
669+
echo "True"
670+
else
671+
echo "False"
672+
fi
673+
674+
- name: check stdout 02
675+
run: |
676+
echo "stdout: ${{ steps.stdout02.outputs.stdout }}"
677+
if echo "${{ steps.stdout02.outputs.stdout }}" | grep -q "False"; then
678+
echo "Output contains 'False'"
679+
exit 1
680+
fi
681+
if echo "${{ steps.stdout02.outputs.stdout }}" | grep -q "True"; then
682+
echo "Output contains 'True'"
683+
fi

0 commit comments

Comments
 (0)