diff --git a/.github/docker/linux-ci.Dockerfile b/.github/docker/linux-ci.Dockerfile new file mode 100644 index 00000000..3841e304 --- /dev/null +++ b/.github/docker/linux-ci.Dockerfile @@ -0,0 +1,26 @@ +# Toolchain of the Linux desktop CI job (GCC 16, WebKitGTK, lcov, Xvfb), prebuilt so that a job downloads one image from +# ghcr.io instead of dozens of packages from an Ubuntu mirror. BuildAndTest.yml tags it with the hash of this file: +# changing the file (for example to refresh the packages) is what rebuilds it. CMake is not part of it: the +# setup-cmake action installs an exact, checksummed release. +FROM ubuntu:26.04@sha256:c098726dd9b9733f3e885f8de0ef375206a311b0a317eadc40d347b1115fb944 + +LABEL org.opencontainers.image.source="https://github.com/ambroise-leclerc/WebFront" +LABEL org.opencontainers.image.description="WebFront CI: GCC 16, WebKitGTK 6, lcov and Xvfb on Ubuntu 26.04" + +ENV DEBIAN_FRONTEND=noninteractive + +# sudo: the composite actions of the repository call it, as they do on a hosted runner. build-essential: the CTest +# fixtures configure sub-projects with CMake's default generator and compiler, which a hosted runner also provides. +# libjson-xs-perl: a recommendation of lcov, which falls back to a pure-Perl parser about eight times slower without it. +RUN apt-get update \ + && apt-get install -y --no-install-recommends -o Acquire::Retries=3 \ + ca-certificates curl git sudo tar xz-utils build-essential \ + ninja-build pkg-config python3 \ + gcc-16 g++-16 libwebkitgtk-6.0-dev lcov libjson-xs-perl \ + xvfb xauth \ + && rm -rf /var/lib/apt/lists/* + +# The workspace is mounted from the host runner and owned by another user: let git (and the tests that call it) read it. +RUN git config --system --add safe.directory '*' + +ENV CC=gcc-16 CXX=g++-16 diff --git a/.github/workflows/BuildAndTest.yml b/.github/workflows/BuildAndTest.yml index c5d724d9..8cb6e1a0 100644 --- a/.github/workflows/BuildAndTest.yml +++ b/.github/workflows/BuildAndTest.yml @@ -28,9 +28,44 @@ env: # Third-party actions are pinned to commit SHAs; GitHub-owned actions/* use version tags. jobs: - desktop: - # Manual runs add extended checks; stability checks opt into desktops. + # The Linux toolchain image is tagged with the hash of its Dockerfile and built only when that tag is missing from ghcr.io, + # so a change of the Dockerfile is validated by the very run that carries it. A pull request from a fork cannot push it + # (read-only token): its Linux job then fails at the pull, which a maintainer re-run on a branch of this repository fixes. + linux-image: if: github.event_name != 'workflow_dispatch' || inputs.repeat_desktop_tests + runs-on: ubuntu-24.04 + timeout-minutes: 30 + permissions: + contents: read + packages: write + outputs: + image: ${{ steps.tag.outputs.image }} + steps: + - uses: actions/checkout@v7 + - name: Name the image after its Dockerfile + id: tag + run: | + hash=$(sha256sum .github/docker/linux-ci.Dockerfile | cut -c1-16) + echo "image=ghcr.io/${GITHUB_REPOSITORY,,}/linux-ci:$hash" >> "$GITHUB_OUTPUT" + - name: Log in to ghcr.io + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin + - name: Build and push the image if its tag does not exist + run: | + if docker manifest inspect "${{ steps.tag.outputs.image }}" > /dev/null 2>&1; then + echo "${{ steps.tag.outputs.image }} already exists" + else + docker build -f .github/docker/linux-ci.Dockerfile -t "${{ steps.tag.outputs.image }}" .github/docker + docker push "${{ steps.tag.outputs.image }}" + fi + + desktop: + needs: linux-image + permissions: + contents: read + packages: read + # Manual runs add extended checks; stability checks opt into desktops. The image job gates only the Linux leg: when it + # fails, Windows and macOS still run (a skipped `needs` would skip the whole matrix) and the Linux leg fails at its pull. + if: ${{ !cancelled() && (github.event_name != 'workflow_dispatch' || inputs.repeat_desktop_tests) }} # No `name:` expression: a skipped matrix job would display it unevaluated. timeout-minutes: 25 strategy: @@ -40,6 +75,7 @@ jobs: include: - platform: linux-gcc-webkitgtk os: ubuntu-26.04 + use_image: true build_type: Debug test_env: {WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS: '1'} options: -DWEBFRONT_EMBED_WEBKITGTK=ON -DWEBFRONT_WEBTEST_FRONTEND=WebKitGTK -DENABLE_COVERAGE=ON @@ -54,6 +90,8 @@ jobs: test_env: {} options: -DWEBFRONT_EMBED_WKWEBVIEW=ON -DWEBFRONT_WEBTEST_FRONTEND=WKWebView runs-on: ${{ matrix.os }} + # Only the Linux job runs in the prebuilt toolchain image; an empty value means no container. + container: ${{ matrix.use_image && fromJSON(format('{{"image":"{0}","credentials":{{"username":"{1}","password":"{2}"}},"options":"--shm-size=1g"}}', needs.linux-image.outputs.image, github.actor, github.token)) || '' }} steps: - uses: actions/checkout@v7 # No step of a build or of its tests needs a JavaScript runtime or package manager: the runner has none from here on. @@ -61,6 +99,10 @@ jobs: - uses: ./.github/actions/setup-cmake with: version: '4.4.4' + # In the container the workspace is mounted elsewhere than the host path that `github.workspace` expands to. + - name: Point the CPM cache at the workspace + if: matrix.use_image + run: echo "CPM_SOURCE_CACHE=$GITHUB_WORKSPACE/.cache/CPM" >> "$GITHUB_ENV" - uses: mozilla-actions/sccache-action@7d986dd989559c6ecdb630a3fd2557667be217ad # v0.0.9 - uses: actions/cache@v4 with: @@ -70,16 +112,7 @@ jobs: - name: Initialize MSVC environment if: runner.os == 'Windows' uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1 - # Ubuntu 26.04 ships GCC 16 in its main archive (no flaky toolchain PPA). The image already - # provides CMake, Ninja, pkg-config and Xvfb, so install only the missing pieces. - - name: Install GCC 16, WebKitGTK and coverage tools - if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends -o Acquire::Retries=3 \ - gcc-16 g++-16 libwebkitgtk-6.0-dev lcov - echo "CC=gcc-16" >> "$GITHUB_ENV" - echo "CXX=g++-16" >> "$GITHUB_ENV" + # GCC 16, WebKitGTK, lcov, Ninja and Xvfb come from the container image (.github/docker/linux-ci.Dockerfile). - name: Setup Xcode if: runner.os == 'macOS' uses: maxim-lobanov/setup-xcode@ed7a3b1fda3918c0306d1b724322adc0b8cc0a90 # v1 @@ -131,7 +164,7 @@ jobs: # Only Linux trusted fixtures need the sandbox opt-out on hosted runners. env: ${{ matrix.test_env }} run: >- - cmake -DBUILD_DIR=${{ github.workspace }}/build -DCONFIG=${{ matrix.build_type }} + cmake -DBUILD_DIR=build -DCONFIG=${{ matrix.build_type }} -DREPEAT=${{ github.event_name == 'workflow_dispatch' && inputs.repeat_desktop_tests && '3' || '1' }} -P test/cmake/RunTestSuite.cmake - name: Collect coverage diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1519d6f6..19389bc9 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,6 +7,10 @@ after it sent a browser message. A real-socket regression checks the option directly; the shared browser suite checks a callback sending a message before returning a value. +- The Linux desktop CI job runs in a prebuilt toolchain image (GCC 16, WebKitGTK, lcov, Xvfb; `.github/docker/linux-ci.Dockerfile`) + published to ghcr.io and tagged with the hash of its Dockerfile, instead of installing those packages from an Ubuntu mirror + on every run. Windows, macOS and the extended jobs are unchanged. + - HTTP status-line buffers belong to each response until its asynchronous send ends (#376). Ordinary responses announce `Connection: close`, matching the existing one-request-per-socket server behavior; WebSocket upgrades remain open. Unit and real-browser regressions cover diff --git a/test/cmake/CheckTestSuiteRepetition.cmake b/test/cmake/CheckTestSuiteRepetition.cmake index a7cf4dc5..33f8b277 100644 --- a/test/cmake/CheckTestSuiteRepetition.cmake +++ b/test/cmake/CheckTestSuiteRepetition.cmake @@ -53,6 +53,21 @@ if(NOT result EQUAL 0 OR EXISTS "${WORK}/build/test-results-2.xml" OR EXISTS "${ OR NOT EXISTS "${WORK}/build/test-results-manual.xml" OR NOT EXISTS "${WORK}/build/test-results-2-extra.xml") message(FATAL_ERROR "A shorter rerun must keep only its own numbered reports: ${output}${error}") endif() +# A relative build directory (the container jobs of the CI pass "build") designates the same directory for the reports as for CTest. +file(WRITE "${WORK}/build/test-results-3.xml" "stale") +execute_process(COMMAND "${CMAKE_COMMAND}" -DBUILD_DIR=build -DCONFIG=Release -DREPEAT=2 -P "${ROOT}/test/cmake/RunTestSuite.cmake" + WORKING_DIRECTORY "${WORK}" RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE error) +if(NOT result EQUAL 0) + message(FATAL_ERROR "Repetition with a relative build directory failed: ${output}${error}") +endif() +foreach(pass RANGE 1 2) + if(NOT EXISTS "${WORK}/build/test-results-${pass}.xml") + message(FATAL_ERROR "A relative build directory must keep the JUnit report of pass ${pass} in it") + endif() +endforeach() +if(EXISTS "${WORK}/build/build" OR EXISTS "${WORK}/build/test-results-3.xml") + message(FATAL_ERROR "A relative build directory must not nest its reports nor keep a stale numbered report") +endif() # Recreate the successful reports to exercise cleanup when the next invocation fails early. execute_process(COMMAND "${CMAKE_COMMAND}" -DBUILD_DIR=${WORK}/build -DCONFIG=Release -DREPEAT=3 -P "${ROOT}/test/cmake/RunTestSuite.cmake" RESULT_VARIABLE result OUTPUT_VARIABLE output ERROR_VARIABLE error) diff --git a/test/cmake/RunTestSuite.cmake b/test/cmake/RunTestSuite.cmake index dd99df59..55c446cc 100644 --- a/test/cmake/RunTestSuite.cmake +++ b/test/cmake/RunTestSuite.cmake @@ -9,6 +9,8 @@ endif() if(NOT REPEAT MATCHES "^[1-9][0-9]*$") message(FATAL_ERROR "REPEAT must be a positive integer") endif() +# CTest runs in the build directory: a relative path would place a relative report path inside it, and miss the cleanup below. +cmake_path(ABSOLUTE_PATH BUILD_DIR NORMALIZE) get_filename_component(cmake_bin "${CMAKE_COMMAND}" DIRECTORY) find_program(CTEST_EXECUTABLE ctest HINTS "${cmake_bin}" REQUIRED) set(options --test-dir "${BUILD_DIR}" --output-on-failure --no-tests=error --parallel 4)