Skip to content

Commit 44a65d0

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 44a65d0

2 files changed

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

0 commit comments

Comments
 (0)