mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 09:20:04 +01:00
Instead of doing the broken `podman run` and `podman start` approach,
build an image ("nm-code-format:f38"), cache it, and use it to run
"nm-code-format.sh" via `podman run`. We should build and keep a
container image, not a container.
The benefit is that this allows to hand over the command line arguments
to "nm-code-format.sh". In particular the "-u" and "-F" options, which
are life savers.
This means,
$ contrib/scripts/nm-code-format-container.sh -u
works.
Try also
$ contrib/scripts/nm-code-format-container.sh -h
which tells you that you are running inside the container, and how to
delete/renew the container image.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1798
46 lines
1.1 KiB
Bash
Executable file
46 lines
1.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
die() {
|
|
echo "$@" >&2
|
|
exit 1
|
|
}
|
|
|
|
DIR="$(realpath "$(dirname "$0")/../../")"
|
|
cd "$DIR"
|
|
|
|
# The correct clang-format version is the one from the Fedora version used in our
|
|
# gitlab-ci pipeline. Parse it from ".gitlab-ci/config.yml".
|
|
FEDORA_VERSION="$(sed '/^ tier: 1/,/^ - name/!d' .gitlab-ci/config.yml | sed -n "s/^ - '\([0-9]\+\)'$/\1/p" | sed -n 1p)"
|
|
|
|
test -n "$FEDORA_VERSION" || die "Could not detect the Fedora version in .gitlab-ci/config.yml"
|
|
|
|
IMAGENAME="nm-code-format:f$FEDORA_VERSION"
|
|
|
|
ARGS=( "$@" )
|
|
|
|
if ! podman image exists "$IMAGENAME" ; then
|
|
echo "Building image \"$IMAGENAME\"..."
|
|
podman build \
|
|
--squash-all \
|
|
--tag "$IMAGENAME" \
|
|
-f <(cat <<EOF
|
|
FROM fedora:$FEDORA_VERSION
|
|
RUN dnf upgrade -y
|
|
RUN dnf install -y git /usr/bin/clang-format
|
|
EOF
|
|
)
|
|
fi
|
|
|
|
CMD=( ./contrib/scripts/nm-code-format.sh "${ARGS[@]}" )
|
|
|
|
podman run \
|
|
--rm \
|
|
--name "nm-code-format-f$FEDORA_VERSION" \
|
|
-v "$DIR:/tmp/NetworkManager:Z" \
|
|
-w /tmp/NetworkManager \
|
|
-e "_NM_CODE_FORMAT_CONTAINER=$IMAGENAME" \
|
|
-ti \
|
|
"$IMAGENAME" \
|
|
"${CMD[@]}"
|