diff --git a/.github/workflows/build_all.yml b/.github/workflows/build_all.yml index 10edec5aaa..f8d6bb8235 100644 --- a/.github/workflows/build_all.yml +++ b/.github/workflows/build_all.yml @@ -14,6 +14,7 @@ on: - 'localization/**' - 'resources/**' - ".github/workflows/build_*.yml" + - ".github/workflows/unit_tests*.yml" - 'scripts/build_preset_cache.*' - 'scripts/flatpak/**' - 'scripts/msix/**' @@ -30,6 +31,7 @@ on: - '**/CMakeLists.txt' - 'version.inc' - ".github/workflows/build_*.yml" + - ".github/workflows/unit_tests*.yml" - 'build_linux.sh' - 'build_release_vs.bat' - 'build_release_vs2022.bat' @@ -207,7 +209,7 @@ jobs: ./validator-bin/OrcaSlicer_profile_validator -p "${{ github.workspace }}/resources/profiles" -s -l 2 publish_test_results: name: Publish Test Results - needs: [unit_tests_linux_x86_64, unit_tests_linux_aarch64, unit_tests_windows_x64, unit_tests_windows_arm64, unit_tests_macos_arm64] + needs: [unit_tests_linux_x86_64, unit_tests_linux_aarch64, unit_tests_windows_x64, unit_tests_windows_arm64, unit_tests_macos_arm64, unit_tests_flatpak_x86_64, unit_tests_flatpak_aarch64] if: ${{ !cancelled() }} runs-on: ubuntu-latest steps: @@ -324,9 +326,16 @@ jobs: sed -i '/^build-options:/a\ no-debuginfo: true\n strip: true' \ scripts/flatpak/com.orcaslicer.OrcaSlicer.yml shell: bash - - name: Inject git commit hash into Flatpak manifest + # flatpak-builder reuses a module from its cache when the definition and + # sources are unchanged, so a re-run of the same commit would skip the + # OrcaSlicer module and ship no test asset. A per-run value in that module's + # env keeps it rebuilding; orca_deps stays cached, and the compiler cache + # still serves the rebuild. + - name: Inject commit hash and flatpak-builder cache buster into Flatpak manifest + env: + flatpak_builder_cache_buster: ${{ github.run_id }}-${{ github.run_attempt }} run: | - sed -i "/name: OrcaSlicer/{n;s|buildsystem: simple|buildsystem: simple\n build-options:\n env:\n git_commit_hash: \"$git_commit_hash\"|}" \ + sed -i "/name: OrcaSlicer/{n;s|buildsystem: simple|buildsystem: simple\n build-options:\n env:\n flatpak_builder_cache_buster: \"$flatpak_builder_cache_buster\"\n git_commit_hash: \"$git_commit_hash\"|}" \ scripts/flatpak/com.orcaslicer.OrcaSlicer.yml shell: bash # flatpak-builder's --ccache only wraps cc and gcc, and the manifest builds @@ -372,6 +381,10 @@ jobs: save-cache: false arch: ${{ matrix.variant.arch }} upload-artifact: false + # run-tests fires the module's build-only test-commands; keep-build-dirs + # retains the binaries for the packaging step below. + run-tests: true + keep-build-dirs: true # The build has just touched everything it can use, so an object untouched # for a week is dead, usually orphaned by a flag change. - name: Compiler cache statistics @@ -425,3 +438,46 @@ jobs: asset_name: OrcaSlicer-Linux-flatpak_nightly${{ env.nightly_suffix }}_${{ matrix.variant.arch }}.flatpak asset_content_type: application/octet-stream max_releases: 1 # optional, if there are more releases than this matching the asset_name, the oldest ones are going to be deleted + # The asset is /app (the exes link it at runtime) plus the build tree + # slimmed to what ctest needs. + - name: Package flatpak test asset + shell: bash + run: | + d=$(ls -d .flatpak-builder/build/OrcaSlicer-* | tail -1) + find "$d/build_flatpak" -mindepth 1 -maxdepth 1 ! -name tests -exec rm -rf {} + + # Strip debug info (the SDK builds with -g, only the app gets stripped); + # the bounds checks are compiled in, so a stripped exe still catches them. + find "$d/build_flatpak/tests" -type f -perm -u+x -exec strip --strip-unneeded {} + 2>/dev/null || true + # At runtime the tests read tests/ (TEST_DATA_DIR), scripts/, and under + # resources/ the shipped profiles (PROFILES_DIR) and the printers/ maps. + find "$d" -mindepth 1 -maxdepth 1 -type d \ + ! -name tests ! -name build_flatpak ! -name scripts ! -name resources -exec rm -rf {} + + find "$d/resources" -mindepth 1 -maxdepth 1 ! -name profiles ! -name printers -exec rm -rf {} + + tar -cf flatpak-test-asset.tar flatpak_app "$d" + - name: Upload flatpak test asset + uses: actions/upload-artifact@v7 + with: + name: ${{ github.sha }}-flatpak-tests-${{ matrix.variant.arch }} + path: flatpak-test-asset.tar + retention-days: 1 + # keep-build-dirs would otherwise land in the flatpak-builder cache saved post-job. + - name: Drop the kept build dirs before the flatpak-builder cache saves + if: always() + shell: bash + run: rm -rf .flatpak-builder/build + unit_tests_flatpak_x86_64: + name: Flatpak x86_64 + needs: flatpak + if: ${{ !cancelled() && success() }} + uses: ./.github/workflows/unit_tests_flatpak.yml + with: + os: ubuntu-24.04 + artifact: ${{ github.sha }}-flatpak-tests-x86_64 + unit_tests_flatpak_aarch64: + name: Flatpak aarch64 + needs: flatpak + if: ${{ !cancelled() && success() }} + uses: ./.github/workflows/unit_tests_flatpak.yml + with: + os: ubuntu-24.04-arm + artifact: ${{ github.sha }}-flatpak-tests-aarch64 diff --git a/.github/workflows/unit_tests_flatpak.yml b/.github/workflows/unit_tests_flatpak.yml new file mode 100644 index 0000000000..ce261c210c --- /dev/null +++ b/.github/workflows/unit_tests_flatpak.yml @@ -0,0 +1,67 @@ +name: Flatpak Unit Tests + +# Run the flatpak build's test asset inside the sandbox, once per arch. The +# GNOME SDK's _GLIBCXX_ASSERTIONS gives a bounds-checked STL that catches +# out-of-bounds reads no other test leg does. +on: + workflow_call: + inputs: + os: + required: true + type: string + artifact: + description: Test asset uploaded by the flatpak build leg + required: true + type: string + +jobs: + unit_tests_flatpak: + name: Flatpak Unit Tests + runs-on: ${{ inputs.os }} + container: + image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-50 + options: --privileged + steps: + - name: Restore test asset + uses: actions/download-artifact@v8 + with: + name: ${{ inputs.artifact }} + - name: Run unit tests (bounds-checked sandbox) + timeout-minutes: 20 + shell: bash + run: | + tar -xf flatpak-test-asset.tar + # Recreate the stable module symlink so /run/build/OrcaSlicer resolves. + d=$(ls -d .flatpak-builder/build/OrcaSlicer-* | tail -1) + ln -sfn "$(basename "$d")" .flatpak-builder/build/OrcaSlicer + # The runtime + SDK + the llvm extension the app metadata references, + # which `flatpak build` mounts; best-effort, the image may have them. + flatpak remote-add --if-not-exists --user flathub https://flathub.org/repo/flathub.flatpakrepo + flatpak install --user -y --noninteractive flathub \ + org.gnome.Platform//50 org.gnome.Sdk//50 org.freedesktop.Sdk.Extension.llvm21//25.08 || true + # `flatpak build` uses bwrap (no rofiles-fuse, which this container + # rejects); bind-mount the build tree so the baked TEST_DATA_DIR resolves. + flatpak build --die-with-parent --share=network \ + --bind-mount=/run/build="$PWD/.flatpak-builder/build" \ + flatpak_app \ + bash -c 'cd /run/build/OrcaSlicer && scripts/run_unit_tests.sh build_flatpak/tests' + - name: Collect test results + if: always() + shell: bash + run: | + d=$(ls -d .flatpak-builder/build/OrcaSlicer-* 2>/dev/null | tail -1 || true) + [ -n "$d" ] && [ -f "$d/ctest_results.xml" ] && cp "$d/ctest_results.xml" ctest_results.xml || true + - name: Upload Test Results + if: always() + uses: actions/upload-artifact@v7 + with: + name: test-results-${{ inputs.artifact }} + path: ctest_results.xml + retention-days: 5 + if-no-files-found: warn + - name: Delete Test Asset + if: success() + uses: geekyeggo/delete-artifact@v6 + with: + name: ${{ inputs.artifact }} + failOnError: false diff --git a/scripts/flatpak/com.orcaslicer.OrcaSlicer.yml b/scripts/flatpak/com.orcaslicer.OrcaSlicer.yml index 00aa430f84..668f51334b 100644 --- a/scripts/flatpak/com.orcaslicer.OrcaSlicer.yml +++ b/scripts/flatpak/com.orcaslicer.OrcaSlicer.yml @@ -378,6 +378,17 @@ modules: - cmake --build build_flatpak --target generate_system_cache -j$FLATPAK_BUILDER_N_JOBS - ./scripts/build_preset_cache.sh -n -b build_flatpak /app/share/OrcaSlicer/profiles + # Built (not run) here via the action's run-tests, then shipped to a separate + # test job. Only the test sources compile; nothing installs to /app. + test-commands: + - cmake . -B build_flatpak -DBUILD_TESTS=ON + # A suite missing from this list fails the leg loudly, since ctest registers a + # _NOT_BUILT test for it. (tests/all is a Ninja subdirectory target and + # this build uses the default Makefile generator, so it is not available here.) + - cmake --build build_flatpak -j"${FLATPAK_BUILDER_N_JOBS:-$(nproc)}" --target + libslic3r_tests fff_print_tests sla_print_tests libnest2d_tests slic3rutils_tests + filament_group_tests + cleanup: - /include @@ -414,6 +425,10 @@ modules: - type: dir path: ../../localization dest: localization + # For the post-build unit-test step (BUILD_TESTS=ON); not built by the app. + - type: dir + path: ../../tests + dest: tests - type: file path: ../../CMakeLists.txt @@ -427,6 +442,9 @@ modules: - type: file path: ../build_preset_cache.sh dest: scripts + - type: file + path: ../run_unit_tests.sh + dest: scripts # AppData metainfo for GNOME Software & Co. - type: file diff --git a/tests/slic3rutils/CMakeLists.txt b/tests/slic3rutils/CMakeLists.txt index 2ab78f56de..3ddacc5a1b 100644 --- a/tests/slic3rutils/CMakeLists.txt +++ b/tests/slic3rutils/CMakeLists.txt @@ -55,6 +55,18 @@ elseif (APPLE) COMMENT "Copying Python runtime for macOS plugin host API tests" VERBATIM ) +elseif (FLATPAK) + # Same /python home as WIN32/APPLE; symlink since /app/libpython + # already ships in the flatpak (the test exe links libpython3.12.so from it). + add_custom_command(TARGET ${_TEST_NAME}_tests POST_BUILD + COMMAND ${CMAKE_COMMAND} -E rm -rf + "$/python" + COMMAND ${CMAKE_COMMAND} -E create_symlink + "${CMAKE_PREFIX_PATH}/libpython" + "$/python" + COMMENT "Linking Python runtime for flatpak plugin host API tests" + VERBATIM + ) endif() orcaslicer_discover_tests(${_TEST_NAME}_tests)