# The Flatpak build and its unit tests, for build_all.yml and for a pull request # that asks for it (build_optional.yml). name: Build Flatpak on: workflow_call: jobs: flatpak: name: Build Flatpak container: image: ghcr.io/flathub-infra/flatpak-github-actions:gnome-50 options: --privileged volumes: - /usr/local/lib/android:/usr/local/lib/android - /usr/share/dotnet:/usr/share/dotnet - /opt/ghc:/opt/ghc1 - /usr/local/share/boost:/usr/local/share/boost1 - /opt/hostedtoolcache:/opt/hostedtoolcache1 # Updating a runtime renames its old deployment, which fails with # "Invalid cross-device link" on hosts whose Docker overlay cannot # rename directories from an image layer. A volume is not overlay. - /var/lib/flatpak strategy: fail-fast: false matrix: variant: - arch: x86_64 runner: ubuntu-24.04 - arch: aarch64 runner: ubuntu-24.04-arm runs-on: ${{ matrix.variant.runner }} env: date: ver: ver_pure: steps: - name: "Remove unneeded stuff to free disk space" run: rm -rf /usr/local/lib/android/* /usr/share/dotnet/* /opt/ghc1/* "/usr/local/share/boost1/*" /opt/hostedtoolcache1/* - uses: actions/checkout@v7 - name: Get the version and date run: | ver_pure=$(grep 'set(SoftFever_VERSION' version.inc | cut -d '"' -f2) if [[ "${{ github.event_name }}" == "pull_request" ]]; then ver="PR-${{ github.event.number }}" git_commit_hash="${{ github.event.pull_request.head.sha }}" else ver=V$ver_pure git_commit_hash="${{ github.sha }}" fi echo "ver=$ver" >> $GITHUB_ENV echo "ver_pure=$ver_pure" >> $GITHUB_ENV echo "date=$(date +'%Y%m%d')" >> $GITHUB_ENV echo "git_commit_hash=$git_commit_hash" >> $GITHUB_ENV shell: bash - name: Compute the flatpak-builder cache key id: fp_cache_key run: echo "key=flatpak-builder-${{ matrix.variant.arch }}-${{ hashFiles('deps/**', 'scripts/flatpak/com.orcaslicer.OrcaSlicer.yml', 'scripts/flatpak/make_deps_tar.sh') }}" >> "$GITHUB_OUTPUT" shell: bash # Manage flatpak-builder cache externally so PRs restore but never upload. # The compiler cache under it is keyed per run below, so it is left out. - name: Restore flatpak-builder cache if: github.event_name == 'pull_request' uses: actions/cache/restore@v6 with: path: | .flatpak-builder/* !.flatpak-builder/ccache key: ${{ steps.fp_cache_key.outputs.key }} restore-keys: flatpak-builder-${{ matrix.variant.arch }}- - name: Save/restore flatpak-builder cache if: github.event_name != 'pull_request' uses: actions/cache@v6 with: path: | .flatpak-builder/* !.flatpak-builder/ccache key: ${{ steps.fp_cache_key.outputs.key }} restore-keys: flatpak-builder-${{ matrix.variant.arch }}- # Compiler cache for the OrcaSlicer module, as in build_orca.yml. Pull # requests only restore it; every other run (main, release branches, the # nightly, a dispatch) saves it. orca_deps stays on the state cache above. - name: Name the compiler cache leg run: | leg="Flatpak-${{ matrix.variant.arch }}" echo "CCACHE_LEG=$leg" >> "$GITHUB_ENV" echo "CCACHE_ENTRY=ccache-$leg-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_ENV" shell: bash - name: Restore compiler cache id: ccache_restore uses: actions/cache/restore@v6 with: path: .flatpak-builder/ccache key: ${{ env.CCACHE_ENTRY }} restore-keys: ccache-${{ env.CCACHE_LEG }}- - name: Disable debug info for faster CI builds run: | sed -i '/^build-options:/a\ no-debuginfo: true\n strip: true' \ scripts/flatpak/com.orcaslicer.OrcaSlicer.yml shell: bash # 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. run-tests on the same module builds the test # binaries. - name: Inject commit hash, run-tests and 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 run-tests: true\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 # with clang, so CMake's launcher runs ccache instead; --ccache is still what # mounts the cache directory into the sandbox. The settings go into that # directory's own config file, which the sandbox reads too. - name: Enable compiler cache run: | printf ' %s\n' \ 'CMAKE_C_COMPILER_LAUNCHER: ccache' \ 'CMAKE_CXX_COMPILER_LAUNCHER: ccache' > "$RUNNER_TEMP/ccache-env.yml" sed -i "/^ git_commit_hash: /r $RUNNER_TEMP/ccache-env.yml" \ scripts/flatpak/com.orcaslicer.OrcaSlicer.yml grep -q '^ CMAKE_CXX_COMPILER_LAUNCHER: ccache$' scripts/flatpak/com.orcaslicer.OrcaSlicer.yml mkdir -p .flatpak-builder/ccache export CCACHE_DIR=$PWD/.flatpak-builder/ccache ccache --set-config=max_size=3G # The compiler is reinstalled every run, so its mtime means nothing. ccache --set-config=compiler_check=content # Headers a fresh checkout has just written, the few files that use # __DATE__ or __TIME__, and the precompiled header, whose macros ccache # cannot see. ccache --set-config=sloppiness=pch_defines,time_macros,include_file_mtime,include_file_ctime # Hash the includes the compiler reports instead of preprocessing every # miss before compiling it. ccache --set-config=depend_mode=true # The restored directory carries the previous run's counters. ccache -z shell: bash - name: Check the manifest keeps orca_deps cacheable run: ./scripts/flatpak/check_manifest_cacheable.sh shell: bash - name: Pack deps/ for the Flatpak manifest run: ./scripts/flatpak/make_deps_tar.sh shell: bash - uses: flatpak/flatpak-github-actions/flatpak-builder@master with: bundle: OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak manifest-path: scripts/flatpak/com.orcaslicer.OrcaSlicer.yml # cache only turns on flatpak-builder --ccache; the caching itself is above. cache: true restore-cache: false save-cache: false arch: ${{ matrix.variant.arch }} upload-artifact: false 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 if: always() run: | export CCACHE_DIR=$PWD/.flatpak-builder/ccache ccache --evict-older-than 7d ccache -s -v || ccache -s shell: bash # Save the new entry first, then drop the older ones for this leg on this # ref, so a failed save leaves the previous entry in place. A cancelled or # failed build saves too, since what it compiled is still valid; a restore # that did not finish does not, since the directory may be a truncated copy. - name: Save compiler cache id: ccache_save if: ${{ always() && steps.ccache_restore.outcome == 'success' && github.event_name != 'pull_request' }} uses: actions/cache/save@v6 with: path: .flatpak-builder/ccache key: ${{ env.CCACHE_ENTRY }} - name: Drop older compiler cache entries if: ${{ always() && steps.ccache_save.outcome == 'success' }} # The container has no gh, so this is the list and delete over the REST API. # Older means a lower run id, so two runs finishing close together keep # the newer entry whichever of them cleans up last. continue-on-error: true env: GH_TOKEN: ${{ github.token }} run: | api="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/caches" # The save step reports success even when its tar failed, so keep # the older entries unless the new one is listed. if ! curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ "$api?ref=$GITHUB_REF&key=$CCACHE_ENTRY" \ | jq -e --arg entry "$CCACHE_ENTRY" 'any(.actions_caches[]; .key == $entry)' > /dev/null; then echo "$CCACHE_ENTRY was not saved; keeping the older entries." exit 0 fi curl -sSf -H "Authorization: Bearer $GH_TOKEN" \ "$api?ref=$GITHUB_REF&key=ccache-$CCACHE_LEG-&per_page=100" \ | jq -r --arg prefix "ccache-$CCACHE_LEG-" --argjson run "$GITHUB_RUN_ID" \ '.actions_caches[] | select((.key | ltrimstr($prefix) | split("-")[0] | tonumber?) < $run) | .id' \ | while read -r id; do curl -sSf -X DELETE -H "Authorization: Bearer $GH_TOKEN" "$api/$id" done shell: bash - name: Upload artifacts Flatpak uses: actions/upload-artifact@v7 with: name: OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak path: '/__w/OrcaSlicer/OrcaSlicer/OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak' - name: Deploy Flatpak to nightly release if: github.repository == 'OrcaSlicer/OrcaSlicer' && github.ref == 'refs/heads/main' uses: ./.github/actions/deploy-nightly with: asset_path: /__w/OrcaSlicer/OrcaSlicer/OrcaSlicer-Linux-flatpak_${{ env.ver }}_${{ matrix.variant.arch }}.flatpak asset_name: OrcaSlicer-Linux-flatpak_nightly_${{ matrix.variant.arch }}.flatpak # 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), the printers/ maps, # the icon SVGs (NativeCommands icon names are checked against them), and # the MCP server's page agent (web/mcp). 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 ! -name images ! -name web -exec rm -rf {} + find "$d/resources/web" -mindepth 1 -maxdepth 1 ! -name mcp -exec rm -rf {} + # Only the SVGs are read; the png/ico/icns/gif assets are ~35MB of dead weight. find "$d/resources/images" -mindepth 1 -maxdepth 1 ! -name '*.svg' -exec rm -rf {} + 2>/dev/null || true 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