Skip to content

Commit 362dec4

Browse files
committed
Add reusable E2E workflow, SSH helpers, and CI trigger for feature/e2e
- Add feature/e2e to docker-build.yml branch triggers so CI produces a custompios:feature-e2e container tag for development - Create shared ssh-helpers.sh with canonical ssh_cmd/scp_cmd functions to replace duplicated SSH boilerplate across distro test scripts - Create reusable e2e-test.yml workflow that distros can call with uses: guysoft/CustomPiOS/.github/workflows/e2e-test.yml@ref - Update test_boot.sh to source ssh-helpers.sh
1 parent b2024ad commit 362dec4

File tree

4 files changed

+115
-6
lines changed

4 files changed

+115
-6
lines changed

.github/workflows/docker-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- "docker-github-actions"
88
- "release/v1"
99
- "beta"
10+
- "feature/e2e"
1011
tags:
1112
- "*"
1213
jobs:

.github/workflows/e2e-test.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: E2E Test (reusable)
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image-artifact-name:
7+
required: true
8+
type: string
9+
distro-name:
10+
required: true
11+
type: string
12+
docker-context:
13+
required: false
14+
type: string
15+
default: 'testing/'
16+
timeout-minutes:
17+
required: false
18+
type: number
19+
default: 45
20+
poll-interval:
21+
required: false
22+
type: number
23+
default: 5
24+
max-poll-iterations:
25+
required: false
26+
type: number
27+
default: 360
28+
29+
jobs:
30+
e2e-test:
31+
runs-on: ubuntu-latest
32+
timeout-minutes: ${{ inputs.timeout-minutes }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Download image from build
37+
uses: actions/download-artifact@v4
38+
with:
39+
name: ${{ inputs.image-artifact-name }}
40+
path: image/
41+
42+
- name: Build test Docker image
43+
run: DOCKER_BUILDKIT=0 docker build -t e2e-test ${{ inputs.docker-context }}
44+
45+
- name: Start E2E test container
46+
run: |
47+
mkdir -p artifacts
48+
IMG=$(find image/ -name '*.img' | head -1)
49+
docker run -d --name e2e-test \
50+
-v "$PWD/artifacts:/output" \
51+
-v "$(realpath $IMG):/input/image.img:ro" \
52+
-e ARTIFACTS_DIR=/output \
53+
-e DISTRO_NAME="${{ inputs.distro-name }}" \
54+
e2e-test
55+
56+
- name: Wait for tests to complete
57+
run: |
58+
for i in $(seq 1 ${{ inputs.max-poll-iterations }}); do
59+
[ -f artifacts/exit-code ] && break
60+
sleep ${{ inputs.poll-interval }}
61+
done
62+
if [ ! -f artifacts/exit-code ]; then
63+
echo "ERROR: Tests did not complete within timeout"
64+
docker logs e2e-test 2>&1 | tail -80
65+
exit 1
66+
fi
67+
echo "Tests finished with exit code: $(cat artifacts/exit-code)"
68+
cat artifacts/test-results.txt 2>/dev/null || true
69+
70+
- name: Collect logs and stop container
71+
if: always()
72+
run: |
73+
docker logs e2e-test > artifacts/container.log 2>&1 || true
74+
docker stop e2e-test 2>/dev/null || true
75+
76+
- name: Check test result
77+
run: exit "$(cat artifacts/exit-code 2>/dev/null || echo 1)"
78+
79+
- uses: actions/upload-artifact@v4
80+
if: always()
81+
with:
82+
name: e2e-test-results
83+
path: artifacts/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Shared SSH helpers for E2E test scripts.
3+
# Source this file: source /test/scripts/ssh-helpers.sh
4+
#
5+
# Set E2E_SSH_HOST, E2E_SSH_PORT, E2E_SSH_USER, E2E_SSH_PASS before sourcing
6+
# to override defaults. Test scripts typically do:
7+
# export E2E_SSH_HOST="${1:-localhost}"
8+
# export E2E_SSH_PORT="${2:-2222}"
9+
# source /test/scripts/ssh-helpers.sh
10+
11+
E2E_SSH_HOST="${E2E_SSH_HOST:-localhost}"
12+
E2E_SSH_PORT="${E2E_SSH_PORT:-2222}"
13+
E2E_SSH_USER="${E2E_SSH_USER:-pi}"
14+
E2E_SSH_PASS="${E2E_SSH_PASS:-raspberry}"
15+
16+
SSH_OPTS="-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
17+
-o PreferredAuthentications=password -o PubkeyAuthentication=no \
18+
-o ConnectTimeout=10 -o LogLevel=ERROR"
19+
20+
ssh_cmd() {
21+
sshpass -p "$E2E_SSH_PASS" ssh $SSH_OPTS -p "$E2E_SSH_PORT" "${E2E_SSH_USER}@${E2E_SSH_HOST}" "$@"
22+
}
23+
24+
scp_cmd() {
25+
sshpass -p "$E2E_SSH_PASS" scp $SSH_OPTS -P "$E2E_SSH_PORT" "$@"
26+
}

src/distro_testing/tests/test_boot.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#!/bin/bash
22
set -e
33

4-
HOST="${1:-localhost}"
5-
PORT="${2:-2222}"
6-
USER="pi"
7-
PASS="raspberry"
4+
export E2E_SSH_HOST="${1:-localhost}"
5+
export E2E_SSH_PORT="${2:-2222}"
86

9-
SSH_CMD="sshpass -p $PASS ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password -o PubkeyAuthentication=no -o LogLevel=ERROR -p $PORT ${USER}@${HOST}"
7+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
8+
source "$(dirname "$SCRIPT_DIR")/scripts/ssh-helpers.sh"
109

1110
echo "Test: SSH login and run 'echo hello world'"
1211

13-
OUTPUT=$($SSH_CMD 'echo hello world' 2>/dev/null)
12+
OUTPUT=$(ssh_cmd 'echo hello world' 2>/dev/null)
1413

1514
if [ "$OUTPUT" = "hello world" ]; then
1615
echo " Output: '$OUTPUT'"

0 commit comments

Comments
 (0)