1
0
Fork 0

ci: Always perform git cloning as user

We are now building and testing mutter as user, but the clone may happen
as root, before the docker image takes place.

This may create troubles to git, causing errors such as:
 fatal: detected dubious ownership in repository at ...

And we can't fix this using safe.directory option because we have no
control on the system at this scope.

So, let's just handle the cloning manually so that the meta-user is
always the owner of the repository.

This fixes the dist job, but also other jobs that may fail because of
this reason.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3024>
This commit is contained in:
Marco Trevisan (Treviño) 2023-05-26 11:16:15 +02:00
parent aef3ee4e61
commit 3c975f78bc

View file

@ -19,10 +19,57 @@ variables:
variables: variables:
GIT_STRATEGY: none GIT_STRATEGY: none
.mutter.git-clone:
extends:
- .skip-git-clone
variables:
MUTTER_CLONE_PATH: $CI_BUILDS_DIR/$CI_PROJECT_PATH
MUTTER_CLONE_DEPTH: 1
before_script: |
if [ -n "$MUTTER_CLONE_PATH" ]; then
set -x
uri="$CI_REPOSITORY_URL"
if [ -n "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" ]; then
uri="$CI_MERGE_REQUEST_SOURCE_PROJECT_URL.git"
branch="$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
elif [ -n "$CI_COMMIT_BRANCH" ]; then
branch="$CI_COMMIT_BRANCH"
else
branch="$CI_DEFAULT_BRANCH"
fi
if [ ! -d "$MUTTER_CLONE_PATH" ] || [ -z "$(ls -A "$MUTTER_CLONE_PATH")" ]; then
git clone --depth $MUTTER_CLONE_DEPTH "$uri" "$MUTTER_CLONE_PATH" -b "$branch"
elif [ ! -d "$MUTTER_CLONE_PATH/.git" ]; then
git clone --bare --depth $MUTTER_CLONE_DEPTH "$uri" "$MUTTER_CLONE_PATH/.git" -b "$branch"
if git -C "$MUTTER_CLONE_PATH" config --unset core.bare; then
git -C "$MUTTER_CLONE_PATH" checkout
else
# For some weird reasons sometimes the fast-path could fail with
# "fatal: not in a git directory" error, so handle it manually
tmpdir=$(mktemp --directory --tmpdir mutter-XXXXXX)
mkdir "$tmpdir/repo"
mv "$MUTTER_CLONE_PATH/.git" "$tmpdir/repo/"
git clone "$tmpdir/repo" "$tmpdir/src"
mv "$tmpdir"/src/* "$tmpdir"/src/.* "$MUTTER_CLONE_PATH"
rm -r "$tmpdir/repo"
rm -rv "$tmpdir"
fi
fi
set +x
fi
.mutter.skip-git-clone:
extends:
- .skip-git-clone
variables:
MUTTER_CLONE_PATH: ''
.mutter.fedora@common: .mutter.fedora@common:
extends:
- .skip-git-clone
variables: variables:
FDO_DISTRIBUTION_VERSION: 38 FDO_DISTRIBUTION_VERSION: 38
BASE_TAG: '2023-05-24.1' BASE_TAG: '2023-05-29.0'
FDO_USER: 'meta-user' FDO_USER: 'meta-user'
FDO_DISTRIBUTION_PACKAGES: FDO_DISTRIBUTION_PACKAGES:
asciidoc asciidoc
@ -72,8 +119,21 @@ variables:
# Replace pkexec with sudo, to make meson use it if needed # Replace pkexec with sudo, to make meson use it if needed
ln -sfv /usr/bin/sudo /usr/bin/pkexec ln -sfv /usr/bin/sudo /usr/bin/pkexec
# Ensure that we mark the project clone dir as safe directory
git config --system --add safe.directory "$CI_PROJECT_DIR"
if [[ x"$(uname -m )" = "xx86_64" ]] ; then if [[ x"$(uname -m )" = "xx86_64" ]] ; then
meson setup build -Dkvm_tests=true if [ -n "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME" ]; then
git clone --depth $MUTTER_CLONE_DEPTH \
$CI_MERGE_REQUEST_SOURCE_PROJECT_URL.git mutter-src \
-b "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
elif [ -n "$CI_COMMIT_BRANCH" ]; then
git clone --depth $MUTTER_CLONE_DEPTH \
$CI_REPOSITORY_URL mutter-src -b "$CI_COMMIT_BRANCH"
else
git clone --depth $MUTTER_CLONE_DEPTH $CI_REPOSITORY_URL mutter-src
fi
meson setup build mutter-src -Dkvm_tests=true
ninja -C build src/tests/kvm/bzImage ninja -C build src/tests/kvm/bzImage
mkdir -p /opt/mutter mkdir -p /opt/mutter
cp build/src/tests/kvm/bzImage /opt/mutter/bzImage cp build/src/tests/kvm/bzImage /opt/mutter/bzImage
@ -86,6 +146,7 @@ variables:
./setup.py install --prefix=/usr ./setup.py install --prefix=/usr
cd .. cd ..
rm -rf virtme rm -rf virtme
rm -rf build mutter-src
fi fi
retry: retry:
max: 2 max: 2
@ -105,12 +166,16 @@ default:
- 'api_failure' - 'api_failure'
.mutter.fedora@x86_64: .mutter.fedora@x86_64:
extends: .mutter.fedora@common extends:
- .mutter.fedora@common
- .mutter.git-clone
variables: variables:
FDO_DISTRIBUTION_TAG: "x86_64-${BASE_TAG}" FDO_DISTRIBUTION_TAG: "x86_64-${BASE_TAG}"
.mutter.fedora@aarch64: .mutter.fedora@aarch64:
extends: .mutter.fedora@common extends:
- .mutter.fedora@common
- .mutter.git-clone
variables: variables:
FDO_DISTRIBUTION_TAG: "aarch64-${BASE_TAG}" FDO_DISTRIBUTION_TAG: "aarch64-${BASE_TAG}"
tags: tags:
@ -191,7 +256,7 @@ build-fedora-container@x86_64:
extends: extends:
- .fdo.container-build@fedora@x86_64 - .fdo.container-build@fedora@x86_64
- .mutter.fedora@x86_64 - .mutter.fedora@x86_64
- .skip-git-clone - .mutter.skip-git-clone
stage: prepare stage: prepare
needs: needs:
- check-commit-log - check-commit-log
@ -201,16 +266,18 @@ build-fedora-container@aarch64:
extends: extends:
- .fdo.container-build@fedora@aarch64 - .fdo.container-build@fedora@aarch64
- .mutter.fedora@aarch64 - .mutter.fedora@aarch64
- .mutter.skip-git-clone
stage: prepare stage: prepare
needs: needs:
- check-commit-log - check-commit-log
- check-merge-request - check-merge-request
- .skip-git-clone
check-code-style: check-code-style:
extends: extends:
- .fdo.distribution-image@fedora - .fdo.distribution-image@fedora
- .mutter.fedora@x86_64 - .mutter.fedora@x86_64
variables:
MUTTER_CLONE_DEPTH: 200
stage: code-review stage: code-review
needs: needs:
- build-fedora-container@x86_64 - build-fedora-container@x86_64
@ -351,6 +418,7 @@ build-wayland-only@x86_64:
NO_AT_BRIDGE: "1" NO_AT_BRIDGE: "1"
GTK_A11Y: "none" GTK_A11Y: "none"
before_script: before_script:
- !reference [.mutter.git-clone, before_script]
# Disable e.g. audio support to not dead lock screen cast tests # Disable e.g. audio support to not dead lock screen cast tests
- mkdir -m 700 $XDG_RUNTIME_DIR - mkdir -m 700 $XDG_RUNTIME_DIR
- pipewire & sleep 2 - pipewire & sleep 2
@ -397,8 +465,8 @@ build-wayland-only@x86_64:
test-mutter@x86_64: test-mutter@x86_64:
extends: extends:
- .test-mutter
- .mutter.fedora@x86_64 - .mutter.fedora@x86_64
- .test-mutter
tags: tags:
- asan - asan
needs: needs:
@ -406,8 +474,8 @@ test-mutter@x86_64:
test-mutter-kvm@x86_64: test-mutter-kvm@x86_64:
extends: extends:
- .test-mutter-base
- .mutter.fedora@x86_64 - .mutter.fedora@x86_64
- .test-mutter-base
tags: tags:
- kvm - kvm
script: script:
@ -426,8 +494,8 @@ test-mutter-kvm@x86_64:
test-mutter@aarch64: test-mutter@aarch64:
extends: extends:
- .test-mutter
- .mutter.fedora@aarch64 - .mutter.fedora@aarch64
- .test-mutter
tags: tags:
- asan-aarch64 - asan-aarch64
needs: needs:
@ -470,6 +538,7 @@ can-build-gnome-shell@x86_64:
needs: needs:
- build-mutter@x86_64 - build-mutter@x86_64
before_script: before_script:
- !reference [.mutter.fedora@x86_64, before_script]
- meson install --no-rebuild -C build - meson install --no-rebuild -C build
script: script:
- .gitlab-ci/checkout-gnome-shell.sh - .gitlab-ci/checkout-gnome-shell.sh