ci: handle Windows-based CI jobs in GitLab CI

We try to abstract away any differences between different CI platforms in "ci/lib.sh", such that knowledge specific to e.g. GitHub Actions or GitLab CI is neatly encapsulated in a single place. Next to some generic variables, we also set up some variables that are specific to the actual platform that the CI operates on, e.g. Linux or macOS. We do not yet support Windows runners on GitLab CI. Unfortunately, those systems do not use the same "CI_JOB_IMAGE" environment variable as both Linux and macOS do. Instead, we can use the "OS" variable, which should have a value of "Windows_NT" on Windows platforms. Handle the combination of "$OS,$CI_JOB_IMAGE" and introduce support for Windows. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Oct 9, 2024 at 15:25 UTC b7a08e947eb42de6f272d60b68a2e30790e7c0d5
1 file changed +13 -5
ci/lib.sh
+13 -5
@@ -250,8 +250,13 @@ then
250 CI_TYPE=gitlab-ci
251 CI_BRANCH="$CI_COMMIT_REF_NAME"
252 CI_COMMIT="$CI_COMMIT_SHA"
253 - case "$CI_JOB_IMAGE" in
254 - macos-*)
253 +
254 + case "$OS,$CI_JOB_IMAGE" in
255 + Windows_NT,*)
256 + CI_OS_NAME=windows
257 + JOBS=$NUMBER_OF_PROCESSORS
258 + ;;
259 + *,macos-*)
260 # GitLab CI has Python installed via multiple package managers,
261 # most notably via asdf and Homebrew. Ensure that our builds
262 # pick up the Homebrew one by prepending it to our PATH as the
@@ -259,9 +264,12 @@ then
264 export PATH="$(brew --prefix)/bin:$PATH"
265
266 CI_OS_NAME=osx
267 + JOBS=$(nproc)
268 + ;;
269 + *,alpine:*|*,fedora:*|*,ubuntu:*)
270 + CI_OS_NAME=linux
271 + JOBS=$(nproc)
272 ;;
263 - alpine:*|fedora:*|ubuntu:*)
264 - CI_OS_NAME=linux;;
273 *)
274 echo "Could not identify OS image" >&2
275 env >&2
@@ -272,6 +280,7 @@ then
280 CI_JOB_ID="$CI_JOB_ID"
281 CC="${CC_PACKAGE:-${CC:-gcc}}"
282 DONT_SKIP_TAGS=t
283 +
284 handle_failed_tests () {
285 create_failed_test_artifacts
286 return 1
@@ -280,7 +289,6 @@ then
289 cache_dir="$HOME/none"
290
291 distro=$(echo "$CI_JOB_IMAGE" | tr : -)
283 - JOBS=$(nproc)
292 else
293 echo "Could not identify CI type" >&2
294 env >&2