File: nm-code-format-container.sh

package info (click to toggle)
network-manager 1.54.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 71,424 kB
  • sloc: ansic: 483,661; python: 11,632; xml: 8,546; sh: 5,555; perl: 596; cpp: 178; javascript: 130; ruby: 107; makefile: 60; lisp: 22
file content (46 lines) | stat: -rwxr-xr-x 1,121 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/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[@]}"