diff --git a/.github/workflows/live-test.yml b/.github/workflows/live-test.yml index 4a5fc17..003f118 100644 --- a/.github/workflows/live-test.yml +++ b/.github/workflows/live-test.yml @@ -35,7 +35,6 @@ jobs: e2e-pipeline: name: Slice -> p2pp -> lint -> P3 firmware runs-on: ubuntu-latest - if: false # disabled until Xvfb + Flatpak + Docker runtime is validated steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 diff --git a/profiles/prusaslicer/Palette3-cli.ini b/profiles/prusaslicer/Palette3-cli.ini index 64456e5..1717f0e 100644 --- a/profiles/prusaslicer/Palette3-cli.ini +++ b/profiles/prusaslicer/Palette3-cli.ini @@ -61,6 +61,7 @@ wipe_tower_x = 170 wipe_tower_y = 140 wipe_tower_width = 60 wipe_tower_rotation_angle = 0 +use_relative_e_distances = 1 # --- p2pp configuration ----------------------------------------------------- # Kept in sync with profiles/prusaslicer/Palette3.ini. Deliberately omits @@ -68,5 +69,8 @@ wipe_tower_rotation_angle = 0 # and those directives would make p2pp attempt network I/O. start_gcode = G28 ; home all axes\nG1 Z5 F5000\n;P2PP PALETTE3_PRO\n;P2PP PRINTERPROFILE=0123456789abcdef\n;P2PP LINEARPINGLENGTH=350\n;P2PP SPLICEOFFSET=30\n;P2PP MINSTARTSPLICE=100\n;P2PP MINSPLICE=70\n;P2PP EXTRAENDFILAMENT=200\n;P2PP MATERIAL_DEFAULT_0_0_0\n;P2PP MATERIAL_PLA_PLA_2_1_2 +# Required for use_relative_e_distances=1: reset extruder position each layer +layer_gcode = G92 E0 + # p2pp/psconfig.py:127 parses this block to recover the wipe tower position. end_gcode = ; EXTRA_CONFIG_VARIABLES\n; wipe_tower_x = {wipe_tower_x}\n; wipe_tower_y = {wipe_tower_y}\nM104 S0 ; turn off temperature\nM140 S0\nG28 X0\nM84 \ No newline at end of file diff --git a/scripts/e2e_pipeline.sh b/scripts/e2e_pipeline.sh index 476a30b..051b431 100644 --- a/scripts/e2e_pipeline.sh +++ b/scripts/e2e_pipeline.sh @@ -26,7 +26,25 @@ PROCESSED="${OUTDIR}/processed.gcode" # --- stage 1: slice --------------------------------------------------------- echo "==> [1/4] Slicing $(basename "${MODEL}") with ${SLICER}" -"${SLICER}" --export-gcode --load "${CONFIG}" --output "${RAW}" "${MODEL}" +# Flatpak PrusaSlicer needs a display even with QT_QPA_PLATFORM=offscreen — +# wrap in xvfb-run so it works headless in CI. +# The slicer may crash with Xlib errors after writing G-code (Flatpak sandbox +# cleanup), so don't use set -e for this command. +XVFB_WRAPPER="" +command -v xvfb-run >/dev/null 2>&1 && XVFB_WRAPPER="xvfb-run -a" +${XVFB_WRAPPER} "${SLICER}" --export-gcode --load "${CONFIG}" --output "${RAW}" "${MODEL}" || true + +# Give the filesystem a moment to flush (Flatpak sandbox can be slow) +sleep 2 + +# If the slicer didn't write to the expected path, check /tmp +if [ ! -s "${RAW}" ]; then + echo "WARNING: G-code not at ${RAW}, checking alternatives..." + found=$(find /tmp -name "raw.gcode" -newer "${MODEL}" 2>/dev/null | head -1) + if [ -n "${found}" ]; then + cp "${found}" "${RAW}" + fi +fi [ -s "${RAW}" ] || { echo "FAIL: slicer produced no G-code" >&2; exit 1; } # p2pp/psconfig.py:160 keys off this string; without it p2pp will not recognise @@ -46,10 +64,20 @@ echo " tool changes in raw G-code: ${TOOLCHANGES}" # --- stage 2: p2pp ---------------------------------------------------------- # NOTE: P2PP.py takes positional args (p2pp/main.py:100-104). There is no -i flag. echo "==> [2/4] Post-processing with p2pp" -XVFB="" -command -v xvfb-run >/dev/null 2>&1 && XVFB="xvfb-run -a" -QT_QPA_PLATFORM="${QT_QPA_PLATFORM:-offscreen}" \ - ${XVFB} python3 "${REPO_ROOT}/P2PP.py" "${RAW}" "${PROCESSED}" +# p2pp imports GUI modules (image_rc, gui) that need Qt/Xlib. +# In headless CI, create a mock image_rc module so p2pp can run without Qt. +MOCK_RC="$(mktemp -d)/image_rc.py" +cat > "${MOCK_RC}" << 'PYEOF' +# Mock Qt resource module for headless p2pp processing +class qInitResources: pass +class qCleanupResources: pass +PYEOF +export PYTHONPATH="${PYTHONPATH:-}:$(dirname "${MOCK_RC}")" +# p2pp.gui also needs to be importable without a display +export QT_QPA_PLATFORM="${QT_QPA_PLATFORM:-offscreen}" +XVFB2="" +command -v xvfb-run >/dev/null 2>&1 && XVFB2="xvfb-run -a" +${XVFB2} python3 "${REPO_ROOT}/P2PP.py" "${RAW}" "${PROCESSED}" [ -s "${PROCESSED}" ] || { echo "FAIL: p2pp produced no output" >&2; exit 1; } # --- stage 3: lint ---------------------------------------------------------- diff --git a/scripts/install_prusaslicer.sh b/scripts/install_prusaslicer.sh index 1156657..7c93ca8 100644 --- a/scripts/install_prusaslicer.sh +++ b/scripts/install_prusaslicer.sh @@ -37,8 +37,9 @@ flatpak info "${APP_ID}" | sed -n 's/^ *\(Version\|Commit\|Date\):/\1:/p' # read the model/config out of the workspace and write the G-code back. sudo tee /usr/local/bin/prusa-slicer >/dev/null <<'SHIM' #!/usr/bin/env bash -exec flatpak run --filesystem=host \ +exec flatpak run --filesystem=host --filesystem=/tmp \ --env=QT_QPA_PLATFORM=offscreen \ + --env=DISPLAY="${DISPLAY:-:99}" \ com.prusa3d.PrusaSlicer "$@" SHIM sudo chmod +x /usr/local/bin/prusa-slicer