From f3e6715af1083475a188f9329c39dc91e9f0992d Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Sun, 6 Dec 2026 03:35:22 +0300 Subject: [PATCH] ci(windows): stabilize the workspace path so artifacts are reusable Every job gets a different workspace directory, which invalidates the absolute paths inside restored build artifacts. The Windows lane now works through one junction per run+variant (C:/vbs-ci//), so build, test and package share identical paths and the artifact is reused instead of rebuilt. If the junction is unavailable the cache mismatch is detected and the build is redone, never silently wrong. --- .gitea/scripts/windows-native.sh | 60 ++++++++++++++++++++------------ .gitea/workflows/ci.yml | 6 +--- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/.gitea/scripts/windows-native.sh b/.gitea/scripts/windows-native.sh index e3899bd..65a54b9 100644 --- a/.gitea/scripts/windows-native.sh +++ b/.gitea/scripts/windows-native.sh @@ -16,12 +16,25 @@ build_type="${3:?build type}" # The script is piped through `bash -s`, so $0 is "bash": locate the checkout # through GITHUB_WORKSPACE (set by the runner) instead of the script path. -if [ -n "${GITHUB_WORKSPACE:-}" ]; then - root="$(cygpath -u "${GITHUB_WORKSPACE}" 2>/dev/null || printf '%s' "${GITHUB_WORKSPACE}")" -else - root="$(pwd)" +workspace="${GITHUB_WORKSPACE:-$(pwd)}" +if command -v cygpath >/dev/null 2>&1; then + workspace="$(cygpath -u "${workspace}")" + # The runner gives every job a different workspace directory while build + # artifacts embed absolute paths. Work through one stable junction per + # run+variant so the build, test and package jobs share identical paths and + # artifacts can be reused instead of rebuilt. + stable_win="C:/vbs-ci/${GITHUB_RUN_ID:-local}/${variant}" + stable="$(cygpath -u "${stable_win}")" + if mkdir -p "$(dirname "${stable}")" 2>/dev/null; then + cmd //c "rmdir \"$(cygpath -w "${stable_win}")\"" >/dev/null 2>&1 || true + cmd //c "mklink /J \"$(cygpath -w "${stable_win}")\" \"$(cygpath -w "${workspace}")\"" \ + >/dev/null 2>&1 || true + if [ -d "${stable}" ]; then + workspace="${stable}" + fi + fi fi -cd "${root}" +cd "${workspace}" echo "workspace: $(pwd)" build="build/windows-${variant}" @@ -43,16 +56,6 @@ if [ "${variant}" = "sanitizers" ]; then linker_flags="-fsanitize=address,undefined" fi -# Drops the stale build state (absolute paths from another workspace) while -# keeping the materialized dependency sources carried over in the artifact. -clean_build_state() { - if [ -d "${build}/_deps" ]; then - find "${build}" -mindepth 1 -maxdepth 1 ! -name '_deps' -exec rm -rf {} + - else - rm -rf "${build}" - fi -} - configure() { cmake -S . -B "${build}" -G Ninja \ -DCMAKE_BUILD_TYPE="${build_type}" \ @@ -62,23 +65,36 @@ configure() { -DCMAKE_EXPORT_COMPILE_COMMANDS=ON } +# Reuses a restored build only when it was generated at this exact path; +# otherwise drops it (a CMake cache cannot be moved) and configures fresh. +prepare_build() { + if [ -f "${build}/CMakeCache.txt" ]; then + cached_root="$(sed -n 's/^CMAKE_HOME_DIRECTORY:INTERNAL=//p' "${build}/CMakeCache.txt" | head -n1)" + current_root="$(cygpath -m "$(pwd)" 2>/dev/null || pwd)" + cached_lower="$(printf '%s' "${cached_root}" | tr '[:upper:]' '[:lower:]')" + current_lower="$(printf '%s' "${current_root}" | tr '[:upper:]' '[:lower:]')" + if [ -n "${cached_root}" ] && [ "${cached_lower}" != "${current_lower}" ]; then + echo "discarding a build generated at '${cached_root}' (now '${current_root}')" + rm -rf "${build}" + fi + fi + if [ ! -f "${build}/CMakeCache.txt" ]; then + configure + fi +} + case "${phase}" in build) configure cmake --build "${build}" --parallel 4 ;; test) - # The runner uses a different workspace directory per job, so a restored - # build's absolute paths cannot be reused: rebuild from source (only the - # dependency sources are carried over in the artifact). - clean_build_state - configure + prepare_build cmake --build "${build}" --parallel 4 ctest --test-dir "${build}" --output-on-failure --no-tests=error ;; package) - clean_build_state - configure + prepare_build cmake --build "${build}" --parallel 4 out="dist-windows-${variant}" label="${VBS_RELEASE_TAG:-}" diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4343965..b436d08 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -387,12 +387,8 @@ jobs: if: always() uses: actions/upload-artifact@v3 with: - # Downstream jobs rebuild (the runner's workspace path differs per job), - # so only the materialized dependency sources are worth carrying over. name: vbs-windows-build-${{ matrix.variant }} - path: | - build/windows-${{ matrix.variant }}/_deps/voidlibrary-src/ - !build/windows-${{ matrix.variant }}/_deps/voidlibrary-src/.git/ + path: build/windows-${{ matrix.variant }}/ if-no-files-found: ignore retention-days: 7