Skip to content

Commit 78733d4

Browse files
jinghuithamelvin03
authored andcommitted
Add boot tester workflow
Signed-off-by: jinghuitham <jing.hui.tham@intel.com>
1 parent 75ebad7 commit 78733d4

File tree

2 files changed

+184
-16
lines changed

2 files changed

+184
-16
lines changed

.github/workflows/boot_tester.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Boot Tester
2+
on:
3+
push:
4+
branches:
5+
- boot_workflow
6+
schedule:
7+
# Run twice a week: Tuesdays at 02:00 UTC and Fridays at 02:00 UTC
8+
- cron: '0 2 * * 2' # Tuesday at 2 AM UTC
9+
- cron: '0 2 * * 5' # Friday at 2 AM UTC
10+
workflow_dispatch: {}
11+
# Allow manual triggering of the workflow
12+
permissions:
13+
contents: read
14+
jobs:
15+
boot-test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
persist-credentials: false
22+
23+
- name: Set up Docker Buildx
24+
uses: docker/setup-buildx-action@v3
25+
26+
- name: Install Earthly
27+
uses: earthly/actions-setup@v1
28+
with:
29+
github-token: ${{ secrets.GITHUB_TOKEN }}
30+
version: "latest" # or pin to a specific version like "v0.8.0"
31+
32+
- name: Install system deps
33+
run: |
34+
sudo apt-get update
35+
sudo apt-get install -y qemu-system-x86 ovmf tree jq systemd-ukify mmdebstrap systemd-boot
36+
37+
- name: Set up Go
38+
uses: actions/setup-go@v5
39+
with:
40+
go-version: stable # or a pinned version you know exists
41+
42+
- name: Copy tester script
43+
run: |
44+
if [ ! -f validate.sh ]; then
45+
echo "validate.sh not found!"
46+
exit 1
47+
fi
48+
chmod +x validate.sh
49+
50+
- name: Run build-tester
51+
run: |
52+
echo "Starting validate.sh..."
53+
# Ensure script has access to docker group for Earthly
54+
sudo usermod -aG docker $USER
55+
# Run the validation script
56+
./validate.sh --qemu-test
57+
echo "Build and tests completed."

validate.sh

Lines changed: 127 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,78 @@
11
#!/bin/bash
22
set -e
33
# Expect to be run from the root of the PR branch
4+
5+
# Parse command line arguments
6+
RUN_QEMU_TESTS=false
7+
8+
while [[ $# -gt 0 ]]; do
9+
case $1 in
10+
--qemu-test|--with-qemu)
11+
RUN_QEMU_TESTS=true
12+
shift
13+
;;
14+
-h|--help)
15+
echo "Usage: $0 [--qemu-test|--with-qemu]"
16+
echo " --qemu-test, --with-qemu Run QEMU boot tests after each image build"
17+
echo " -h, --help Show this help message"
18+
exit 0
19+
;;
20+
*)
21+
echo "Unknown option $1"
22+
echo "Use -h or --help for usage information"
23+
exit 1
24+
;;
25+
esac
26+
done
27+
428
echo "Current working dir: $(pwd)"
29+
if [ "$RUN_QEMU_TESTS" = true ]; then
30+
echo "QEMU boot tests will be run after each image build"
31+
else
32+
echo "QEMU boot tests will be skipped"
33+
fi
534

635
run_qemu_boot_test() {
7-
IMAGE="azl3-default-x86_64.raw" # image file
36+
local IMAGE_PATTERN="$1"
37+
if [ -z "$IMAGE_PATTERN" ]; then
38+
echo "Error: Image pattern not provided to run_qemu_boot_test"
39+
return 1
40+
fi
41+
842
BIOS="/usr/share/OVMF/OVMF_CODE_4M.fd"
943
TIMEOUT=30
1044
SUCCESS_STRING="login:"
1145
LOGFILE="qemu_serial.log"
1246

13-
1447
ORIGINAL_DIR=$(pwd)
15-
# Find image path
16-
FOUND_PATH=$(find . -type f -name "$IMAGE" | head -n 1)
48+
# Find compressed raw image path using pattern, handle permission issues
49+
FOUND_PATH=$(sudo -S find . -type f -name "*${IMAGE_PATTERN}*.raw.gz" 2>/dev/null | head -n 1)
1750
if [ -n "$FOUND_PATH" ]; then
18-
echo "Found image at: $FOUND_PATH"
19-
IMAGE_DIR=$(dirname "$FOUND_PATH") # Extract directory path where image resides
20-
cd "$IMAGE_DIR" # Change to that directory
51+
echo "Found compressed image at: $FOUND_PATH"
52+
IMAGE_DIR=$(dirname "$FOUND_PATH")
53+
54+
# Fix permissions for the tmp directory recursively to allow access
55+
echo "Setting permissions recursively for ./tmp directory"
56+
sudo chmod -R 777 ./tmp
57+
58+
cd "$IMAGE_DIR"
59+
60+
# Extract the .raw.gz file
61+
COMPRESSED_IMAGE=$(basename "$FOUND_PATH")
62+
RAW_IMAGE="${COMPRESSED_IMAGE%.gz}"
63+
echo "Extracting $COMPRESSED_IMAGE to $RAW_IMAGE..."
64+
gunzip -c "$COMPRESSED_IMAGE" > "$RAW_IMAGE"
65+
66+
if [ ! -f "$RAW_IMAGE" ]; then
67+
echo "Failed to extract image!"
68+
cd "$ORIGINAL_DIR"
69+
return 1
70+
fi
71+
72+
IMAGE="$RAW_IMAGE"
2173
else
22-
echo "Image file not found!"
23-
exit 0 #returning exit status 0 instead of 1 until the code is fully debugged ERRRORRR.
74+
echo "Compressed raw image file matching pattern '*${IMAGE_PATTERN}*.raw.gz' not found!"
75+
return 1
2476
fi
2577

2678

@@ -54,14 +106,23 @@ run_qemu_boot_test() {
54106
kill $qemu_pid
55107
cat "'$LOGFILE'"
56108
57-
if grep -q "'$SUCCESS_STRING'" "'$LOGFILE'"; then
109+
if grep -q "$SUCCESS_STRING" "$LOGFILE"; then
58110
echo "Boot success!"
59111
result=0
60112
else
61113
echo "Boot failed or timed out"
62114
result=0 #setting return value 0 instead of 1 until fully debugged ERRRORRR
63-
fi
64-
exit $result
115+
fi
116+
117+
# Clean up extracted raw file
118+
if [ -f "$RAW_IMAGE" ]; then
119+
echo "Cleaning up extracted image file: $RAW_IMAGE"
120+
rm -f "$RAW_IMAGE"
121+
fi
122+
123+
# Return to original directory
124+
cd "$ORIGINAL_DIR"
125+
return $result
65126
'
66127
}
67128

@@ -84,6 +145,15 @@ build_azl3_raw_image() {
84145
# Check for the success message in the output
85146
if echo "$output" | grep -q "image build completed successfully"; then
86147
echo "AZL3 raw Image build passed."
148+
if [ "$RUN_QEMU_TESTS" = true ]; then
149+
echo "Running QEMU boot test for AZL3 raw image..."
150+
if run_qemu_boot_test "azl3-x86_64-minimal"; then
151+
echo "QEMU boot test PASSED for AZL3 raw image"
152+
else
153+
echo "QEMU boot test FAILED for AZL3 raw image"
154+
exit 1
155+
fi
156+
fi
87157
else
88158
echo "AZL3 raw Image build failed."
89159
exit 1 # Exit with error if build fails
@@ -109,6 +179,15 @@ build_emt3_raw_image() {
109179
# Check for the success message in the output
110180
if echo "$output" | grep -q "image build completed successfully"; then
111181
echo "EMT3 raw Image build passed."
182+
if [ "$RUN_QEMU_TESTS" = true ]; then
183+
echo "Running QEMU boot test for EMT3 raw image..."
184+
if run_qemu_boot_test "emt3-x86_64-minimal"; then
185+
echo "QEMU boot test PASSED for EMT3 raw image"
186+
else
187+
echo "QEMU boot test FAILED for EMT3 raw image"
188+
exit 1
189+
fi
190+
fi
112191
else
113192
echo "EMT3 raw Image build failed."
114193
exit 1 # Exit with error if build fails
@@ -132,8 +211,16 @@ build_elxr12_raw_image() {
132211
output=$( sudo -S ./os-image-composer build image-templates/elxr12-x86_64-minimal-raw.yml 2>&1)
133212
# Check for the success message in the output
134213
if echo "$output" | grep -q "image build completed successfully"; then
135-
136214
echo "ELXR12 raw Image build passed."
215+
if [ "$RUN_QEMU_TESTS" = true ]; then
216+
echo "Running QEMU boot test for ELXR12 raw image..."
217+
if run_qemu_boot_test "elxr12-x86_64-minimal"; then
218+
echo "QEMU boot test PASSED for ELXR12 raw image"
219+
else
220+
echo "QEMU boot test FAILED for ELXR12 raw image"
221+
exit 1
222+
fi
223+
fi
137224
else
138225
echo "ELXR12 raw Image build failed."
139226
exit 1 # Exit with error if build fails
@@ -157,8 +244,16 @@ build_elxr12_immutable_raw_image() {
157244
output=$( sudo -S ./build/os-image-composer build image-templates/elxr12-x86_64-edge-raw.yml 2>&1)
158245
# Check for the success message in the output
159246
if echo "$output" | grep -q "image build completed successfully"; then
160-
161247
echo "ELXR12 immutable raw Image build passed."
248+
if [ "$RUN_QEMU_TESTS" = true ]; then
249+
echo "Running QEMU boot test for ELXR12 immutable raw image..."
250+
if run_qemu_boot_test "elxr12-x86_64-edge"; then
251+
echo "QEMU boot test PASSED for ELXR12 immutable raw image"
252+
else
253+
echo "QEMU boot test FAILED for ELXR12 immutable raw image"
254+
exit 1
255+
fi
256+
fi
162257
else
163258
echo "ELXR12 immutable raw Image build failed."
164259
exit 1 # Exit with error if build fails
@@ -170,8 +265,16 @@ build_emt3_immutable_raw_image() {
170265
output=$( sudo -S ./os-image-composer build image-templates/emt3-x86_64-edge-raw.yml 2>&1)
171266
# Check for the success message in the output
172267
if echo "$output" | grep -q "image build completed successfully"; then
173-
174268
echo "EMT3 immutable raw Image build passed."
269+
if [ "$RUN_QEMU_TESTS" = true ]; then
270+
echo "Running QEMU boot test for EMT3 immutable raw image..."
271+
if run_qemu_boot_test "emt3-x86_64-edge"; then
272+
echo "QEMU boot test PASSED for EMT3 immutable raw image"
273+
else
274+
echo "QEMU boot test FAILED for EMT3 immutable raw image"
275+
exit 1
276+
fi
277+
fi
175278
else
176279
echo "EMT3 immutable raw Image build failed."
177280
exit 1 # Exit with error if build fails
@@ -183,8 +286,16 @@ build_azl3_immutable_raw_image() {
183286
output=$( sudo -S ./build/os-image-composer build image-templates/azl3-x86_64-edge-raw.yml 2>&1)
184287
# Check for the success message in the output
185288
if echo "$output" | grep -q "image build completed successfully"; then
186-
187289
echo "AZL3 immutable raw Image build passed."
290+
if [ "$RUN_QEMU_TESTS" = true ]; then
291+
echo "Running QEMU boot test for AZL3 immutable raw image..."
292+
if run_qemu_boot_test "azl3-x86_64-edge"; then
293+
echo "QEMU boot test PASSED for AZL3 immutable raw image"
294+
else
295+
echo "QEMU boot test FAILED for AZL3 immutable raw image"
296+
exit 1
297+
fi
298+
fi
188299
else
189300
echo "AZL3 immutable raw Image build failed."
190301
exit 1 # Exit with error if build fails

0 commit comments

Comments
 (0)