Skip to content

Commit be8c0e8

Browse files
committed
Github Action to detect Stage3 releases, run and then create a GH release
This serves as information about the build still working, at least on a basic level. Relates to #33 Resolves #56
1 parent 846c885 commit be8c0e8

3 files changed

Lines changed: 258 additions & 0 deletions

File tree

.github/workflows/check-stage3.yml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
name: Check and verify Stage3 builds
2+
3+
on:
4+
schedule:
5+
- cron: '45 15-20 * * 0'
6+
- cron: '55 */6 * * *'
7+
push:
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
env:
14+
CACHE_PATHS: |
15+
pxe/ipxe.efi
16+
pxe/online_boot.ipxe
17+
18+
jobs:
19+
generate:
20+
runs-on: ubuntu-latest
21+
outputs:
22+
latest_version: ${{ steps.get-version.outputs.version }}
23+
tag_exists: ${{ steps.check-tag.outputs.exists }}
24+
steps:
25+
- name: Checkout Repository
26+
uses: actions/checkout@v7
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Determine Latest Gentoo Version
31+
id: get-version
32+
run: |
33+
. ./list_latest.sh
34+
VERSION="${FILE_STAGE3%.tar.xz}"
35+
echo "LATEST_VERSION=$VERSION" >> $GITHUB_ENV
36+
echo "version=$VERSION" >> $GITHUB_OUTPUT
37+
38+
- name: Check if Git Tag Already Exists
39+
id: check-tag
40+
run: |
41+
if git rev-parse "refs/tags/${{ env.LATEST_VERSION }}" >/dev/null 2>&1; then
42+
echo "exists=true" >> $GITHUB_OUTPUT
43+
echo "TAG_EXISTS=true" >> $GITHUB_ENV
44+
echo "Version ${{ env.LATEST_VERSION }} has already been tagged and released."
45+
else
46+
echo "exists=false" >> $GITHUB_OUTPUT
47+
echo "TAG_EXISTS=false" >> $GITHUB_ENV
48+
fi
49+
50+
test:
51+
runs-on: ubuntu-latest
52+
needs: generate
53+
if: needs.generate.outputs.tag_exists == 'false'
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
mode: [pcbios, efi]
58+
include:
59+
- mode: pcbios
60+
run_args: ""
61+
- mode: efi
62+
run_args: "useefi usenvme"
63+
64+
name: Test VM (${{ matrix.mode }})
65+
steps:
66+
- name: Checkout Repository
67+
uses: actions/checkout@v7
68+
69+
- name: Initialize QEMU and System Dependencies
70+
run: |
71+
sudo apt-get update
72+
sudo apt-get install -y qemu-system-x86 ovmf
73+
sudo chmod 666 /dev/kvm
74+
[[ "${{ matrix.mode }}" == "efi" ]] && sudo ln -s /usr/share/OVMF /usr/share/edk2-ovmf || true
75+
[[ "${{ matrix.mode }}" == "efi" ]] && sudo ln -s /usr/share/edk2-ovmf/OVMF_CODE_4M.fd /usr/share/edk2-ovmf/OVMF_CODE.fd || true
76+
[[ "${{ matrix.mode }}" == "efi" ]] && sudo ln -s /usr/share/edk2-ovmf/OVMF_VARS_4M.fd /usr/share/edk2-ovmf/OVMF_VARS.fd || true
77+
78+
- name: Restore Work Directory Cache
79+
uses: actions/cache@v5
80+
with:
81+
path: ${{ env.CACHE_PATHS }}
82+
key: gentoo-ipxe-${{ needs.generate.outputs.latest_version }}
83+
84+
- name: Execute VM
85+
run: |
86+
LOGPFX=${{ matrix.mode }}
87+
RUNOPTS=${{ matrix.test_args }}
88+
./run_test_published_auto.sh
89+
90+
- name: Upload Run Artifacts
91+
uses: actions/upload-artifact@v7
92+
with:
93+
name: vmrun-${{ matrix.mode }}
94+
if-no-files-found: error
95+
path: |
96+
run_full.log
97+
run_metadata.txt
98+
run_vars.sh
99+
100+
publish-release:
101+
runs-on: ubuntu-latest
102+
needs: [generate, test]
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
steps:
106+
- name: Download All Run Artifacts
107+
uses: actions/download-artifact@v5
108+
with:
109+
pattern: vmrun-*
110+
path: vmruns/
111+
112+
- name: Create Release
113+
run: |
114+
VERSION="${{ needs.generate.outputs.latest_version }}"
115+
echo "Tagging repository and creating release: $VERSION"
116+
set -x
117+
ls -l vmruns vmruns/*
118+
echo todo grab versions and include some verions info in notes, also make sure the artifacts are available.
119+
120+
RELEASE_FILES=()
121+
RELEASE_FILES+=("$expanded")
122+
123+
ls -l "${RELEASE_FILES[@]}"
124+
echo gh release create "$VERSION" "${RELEASE_FILES[@]}" \
125+
--repo "${{ github.repository }}" \
126+
--title "Gentoo $VERSION" \
127+
--notes "Automated test ok of Gentoo $VERSION"

run_test_published_auto.sh

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#!/bin/bash
2+
[[ -d pxe ]] || mkdir -p pxe
3+
if [[ ! -f pxe/online_boot.ipxe ]]; then
4+
minimal_latest_json=$(curl -s "https://api.github.com/repos/NiKiZe/Gentoo-iPXE/releases/latest")
5+
tag_name=$(grep '"tag_name":' <<< "$minimal_latest_json" | head -n 1 | sed -E 's/.*"tag_name":\s*"([^"]+)".*/\1/')
6+
if [[ -z "$tag_name" ]]; then
7+
echo "Error: tag not found"
8+
exit 1
9+
fi
10+
ipxe_url=$(grep "${tag_name}.ipxe" <<< "$minimal_latest_json" | grep '"browser_download_url":' | head -n 1 | sed -E 's/.*"browser_download_url":\s*"([^"]+)".*/\1/')
11+
12+
if [[ -z "$ipxe_url" ]]; then
13+
echo "Error: ${tag_name}.ipxe asset not found in release"
14+
exit 1
15+
fi
16+
17+
base_url="${ipxe_url%/*}/"
18+
filtered_ipxe=$(curl -sL "$ipxe_url" | grep -E '^(kernel|initrd)' | sed "s| ${tag_name}-| ${base_url}${tag_name}-|g")
19+
cat << EOF > pxe/online_boot.ipxe
20+
#!ipxe
21+
set keymap keymap=us net.ifnames=0 autoinstall
22+
${filtered_ipxe}
23+
initrd ../updates/root/.bashrc /updates/root/.bashrc mkdir=2 mode=644
24+
initrd ../updates/etc/motd /updates/etc/motd mkdir=1 mode=644
25+
imgstat
26+
boot
27+
EOF
28+
29+
fi
30+
31+
# replace if unset oor empty
32+
: "${LOGPFX:=HAI}"
33+
# replace if unset
34+
: "${RUNOPTS="useefi usenvme"}"
35+
36+
rm kvm_lxgentootest.qcow2 || true
37+
38+
cat pxe/online_boot.ipxe
39+
LOG_FILE=run_full.log
40+
META_FILE=run_metadata.txt
41+
ENV_FILE=run_vars.sh
42+
> $META_FILE
43+
> $ENV_FILE
44+
date > $LOG_FILE
45+
46+
FIFO_PIPE=$(mktemp -u)
47+
mkfifo "$FIFO_PIPE"
48+
bash test_w_qemu.sh -bootfile pxe/online_boot.ipxe auto ${RUNOPTS} > "$FIFO_PIPE" 2>&1 &
49+
QEMU_RUN_PID=$!
50+
51+
{
52+
buffer=""
53+
NEED_PREFIX=1
54+
MSGQUEUE=()
55+
while IFS= read -r -d '' -n 1 char; do
56+
if [ "$NEED_PREFIX" -eq 1 ]; then
57+
[ ${#MSGQUEUE[@]} -gt 0 ] && printf "%s\n" "${MSGQUEUE[@]}" >&2 && MSGQUEUE=()
58+
printf "[%s %02d:%02d] " "${LOGPFX}" $((SECONDS / 60)) $((SECONDS % 60))
59+
NEED_PREFIX=0
60+
fi
61+
printf "%s" "$char"
62+
if [[ "$char" == $'\n' ]]; then
63+
NEED_PREFIX=1
64+
fi
65+
if [[ "$char" != $'\r' && "$char" != $'\n' ]]; then
66+
buffer+="$char"
67+
continue
68+
fi
69+
line="$buffer"
70+
buffer=""
71+
72+
line=$(sed 's/\x1b\[[0-9;]*[mKHP]//g' <<< "$line")
73+
case "$line" in
74+
*" -- Open Source Network Boot Firmware -- https://ipxe.org"*)
75+
IPXE=$(grep -o "iPXE [0-9.+ a-fg()]*[^ -]" <<< "$line")
76+
declare -p IPXE >> $ENV_FILE
77+
MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x8C\x90 '"$(date) iPXE Version: ${IPXE}")")
78+
;;
79+
*"Welcome to Gentoo-HAI Dracut"*)
80+
MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x8E\xAF '"$(date) Initial boot OK")")
81+
;;
82+
"+ "[a-z0-9]*"_emerge"*|"+ make_"*)
83+
CURRENT_TIMER=$(grep -o -E '[a-z0-9_]+' <<< "$line")
84+
;;
85+
real[[:space:]]*)
86+
ELAPSED=$(grep -o '[0-9][0-9hms.]*' <<< "$line")
87+
MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xE2\x8F\xB1\xEF\xB8\x8F '"$(date) ${CURRENT_TIMER} Time: ${ELAPSED}")")
88+
CURRENT_TIMER=""
89+
;;
90+
*"Snapshot"*"gentoo-"*".sqfs "*)
91+
SNAPSHOT=$(grep -o 'gentoo-[^[:space:]]*sqfs' <<< "$line")
92+
declare -p SNAPSHOT >> $ENV_FILE
93+
MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x93\xB8 '"$(date) Snapshot Used: ${SNAPSHOT}")")
94+
;;
95+
*"download latest stage file stage3-"*".tar.xz"*)
96+
STAGE3=$(grep -o 'stage3-[^[:space:]]*xz' <<< "$line")
97+
declare -p STAGE3 >> $ENV_FILE
98+
MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x93\xA6 '"$(date) Stage3 Used: ${STAGE3}")")
99+
;;
100+
*"] "*"sys-kernel/gentoo-sources-"*)
101+
KERNEL=$(grep -o 'gentoo-sources-[0-9.]*' <<< "$line")
102+
declare -p KERNEL >> $ENV_FILE
103+
MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x90\xA7 '"$(date) Kernel: ${KERNEL}")")
104+
;;
105+
"This is gtestinst (Linux"*)
106+
MSGQUEUE+=("$(tee -a $META_FILE <<< $'\xF0\x9F\x8E\xAF '"$(date) All good after reboot")")
107+
pkill -P $QEMU_RUN_PID 2>/dev/null || true
108+
exit 0
109+
;;
110+
esac
111+
done
112+
exit 1
113+
} < "$FIFO_PIPE" | tee -a $LOG_FILE &
114+
JOB_PID=$!
115+
116+
(sleep 45m; kill $JOB_PID 2>/dev/null) &
117+
TIMEOUT_PID=$!
118+
wait $JOB_PID
119+
job_rc=$?
120+
121+
echo
122+
date >> $LOG_FILE
123+
kill $TIMEOUT_PID 2>/dev/null || true
124+
pkill -P $QEMU_RUN_PID 2>/dev/null || true
125+
pkill -P $JOB_PID 2>/dev/null || true
126+
rm -f "$FIFO_PIPE" 2>/dev/null || true
127+
[[ $job_rc -ne 0 ]] && echo "❌ FAIL timeout" || true
128+
[[ -s "$META_FILE" ]] && cat "$META_FILE" || true
129+
exit $job_rc

test_w_qemu.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ netscript="
4848
cp /usr/share/edk2-ovmf/OVMF_VARS.fd kvm_lxgentootest_VARS.fd
4949
efibios="-drive if=pflash,unit=0,format=raw,readonly=on,file=/usr/share/edk2-ovmf/OVMF_CODE.fd \
5050
-drive if=pflash,unit=1,format=raw,file=kvm_lxgentootest_VARS.fd"
51+
[[ -d pxe ]] || mkdir -p pxe
5152
cp $bootfile pxe/autoexec.ipxe
5253
[ -f pxe/ipxe.efi ] || (wget https://boot.ipxe.org/x86_64-efi/ipxe-legacy.efi && mv ipxe-legacy.efi pxe/ipxe.efi)
5354
bootfile=pxe/ipxe.efi
@@ -96,6 +97,7 @@ set -- "${POSITIONAL[@]}" # restore positional parameters
9697
[[ "$VNC" != "" ]] && (sleep 3; vncviewer :22) &
9798
if [[ -z "$VNC" ]]; then
9899
# if serial make sure autoexec.ipxe is set for serial console
100+
[[ -d pxe ]] || mkdir -p pxe
99101
[[ "$USEEFI" != "YES" ]] && cp $bootfile pxe/autoexec.ipxe && bootfile="pxe/autoexec.ipxe"
100102
sed -i 's/ cdroot/ cdroot console=ttyS0,115200/' pxe/autoexec.ipxe
101103
fi

0 commit comments

Comments
 (0)