Skip to content

Commit 4d698be

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

File tree

2 files changed

+172
-13
lines changed

2 files changed

+172
-13
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: 115 additions & 13 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 directory to allow access
55+
echo "Setting permissions for directory: $IMAGE_DIR"
56+
sudo chmod 777 "$IMAGE_DIR"
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

@@ -84,6 +136,15 @@ build_azl3_raw_image() {
84136
# Check for the success message in the output
85137
if echo "$output" | grep -q "image build completed successfully"; then
86138
echo "AZL3 raw Image build passed."
139+
if [ "$RUN_QEMU_TESTS" = true ]; then
140+
echo "Running QEMU boot test for AZL3 raw image..."
141+
if run_qemu_boot_test "azl3-x86_64-minimal"; then
142+
echo "QEMU boot test PASSED for AZL3 raw image"
143+
else
144+
echo "QEMU boot test FAILED for AZL3 raw image"
145+
exit 1
146+
fi
147+
fi
87148
else
88149
echo "AZL3 raw Image build failed."
89150
exit 1 # Exit with error if build fails
@@ -109,6 +170,15 @@ build_emt3_raw_image() {
109170
# Check for the success message in the output
110171
if echo "$output" | grep -q "image build completed successfully"; then
111172
echo "EMT3 raw Image build passed."
173+
if [ "$RUN_QEMU_TESTS" = true ]; then
174+
echo "Running QEMU boot test for EMT3 raw image..."
175+
if run_qemu_boot_test "emt3-x86_64-minimal"; then
176+
echo "QEMU boot test PASSED for EMT3 raw image"
177+
else
178+
echo "QEMU boot test FAILED for EMT3 raw image"
179+
exit 1
180+
fi
181+
fi
112182
else
113183
echo "EMT3 raw Image build failed."
114184
exit 1 # Exit with error if build fails
@@ -132,8 +202,16 @@ build_elxr12_raw_image() {
132202
output=$( sudo -S ./os-image-composer build image-templates/elxr12-x86_64-minimal-raw.yml 2>&1)
133203
# Check for the success message in the output
134204
if echo "$output" | grep -q "image build completed successfully"; then
135-
136205
echo "ELXR12 raw Image build passed."
206+
if [ "$RUN_QEMU_TESTS" = true ]; then
207+
echo "Running QEMU boot test for ELXR12 raw image..."
208+
if run_qemu_boot_test "elxr12-x86_64-minimal"; then
209+
echo "QEMU boot test PASSED for ELXR12 raw image"
210+
else
211+
echo "QEMU boot test FAILED for ELXR12 raw image"
212+
exit 1
213+
fi
214+
fi
137215
else
138216
echo "ELXR12 raw Image build failed."
139217
exit 1 # Exit with error if build fails
@@ -157,8 +235,16 @@ build_elxr12_immutable_raw_image() {
157235
output=$( sudo -S ./build/os-image-composer build image-templates/elxr12-x86_64-edge-raw.yml 2>&1)
158236
# Check for the success message in the output
159237
if echo "$output" | grep -q "image build completed successfully"; then
160-
161238
echo "ELXR12 immutable raw Image build passed."
239+
if [ "$RUN_QEMU_TESTS" = true ]; then
240+
echo "Running QEMU boot test for ELXR12 immutable raw image..."
241+
if run_qemu_boot_test "elxr12-x86_64-edge"; then
242+
echo "QEMU boot test PASSED for ELXR12 immutable raw image"
243+
else
244+
echo "QEMU boot test FAILED for ELXR12 immutable raw image"
245+
exit 1
246+
fi
247+
fi
162248
else
163249
echo "ELXR12 immutable raw Image build failed."
164250
exit 1 # Exit with error if build fails
@@ -170,8 +256,16 @@ build_emt3_immutable_raw_image() {
170256
output=$( sudo -S ./os-image-composer build image-templates/emt3-x86_64-edge-raw.yml 2>&1)
171257
# Check for the success message in the output
172258
if echo "$output" | grep -q "image build completed successfully"; then
173-
174259
echo "EMT3 immutable raw Image build passed."
260+
if [ "$RUN_QEMU_TESTS" = true ]; then
261+
echo "Running QEMU boot test for EMT3 immutable raw image..."
262+
if run_qemu_boot_test "emt3-x86_64-edge"; then
263+
echo "QEMU boot test PASSED for EMT3 immutable raw image"
264+
else
265+
echo "QEMU boot test FAILED for EMT3 immutable raw image"
266+
exit 1
267+
fi
268+
fi
175269
else
176270
echo "EMT3 immutable raw Image build failed."
177271
exit 1 # Exit with error if build fails
@@ -183,8 +277,16 @@ build_azl3_immutable_raw_image() {
183277
output=$( sudo -S ./build/os-image-composer build image-templates/azl3-x86_64-edge-raw.yml 2>&1)
184278
# Check for the success message in the output
185279
if echo "$output" | grep -q "image build completed successfully"; then
186-
187280
echo "AZL3 immutable raw Image build passed."
281+
if [ "$RUN_QEMU_TESTS" = true ]; then
282+
echo "Running QEMU boot test for AZL3 immutable raw image..."
283+
if run_qemu_boot_test "azl3-x86_64-edge"; then
284+
echo "QEMU boot test PASSED for AZL3 immutable raw image"
285+
else
286+
echo "QEMU boot test FAILED for AZL3 immutable raw image"
287+
exit 1
288+
fi
289+
fi
188290
else
189291
echo "AZL3 immutable raw Image build failed."
190292
exit 1 # Exit with error if build fails

0 commit comments

Comments
 (0)