Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ ignore = true
[*.{bash,bats,sh}]
indent_style = space
indent_size = 4
space_redirects = true

# This is for shell scripts with shebang but no extensions.
# Not yes supported by editorconfig[1], only by shfmt.
# https://github.com/editorconfig/editorconfig/issues/404
[[shell]]
indent_style = space
indent_size = 4
space_redirects = true
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ BUILDTAGS += ${EXTRA_BUILDTAGS}
# possible, as long as they don't disturb the formatting
# (i.e. DO NOT ADD A 'v' prefix!)
GOLANGCI_LINT_VERSION := 2.12.2
SHFMT_VERSION := 3.13.1
PYTHON ?= $(shell command -v python3 python|head -n1)
PKG_MANAGER ?= $(shell command -v dnf yum|head -n1)
# ~/.local/bin is not in PATH on all systems
Expand Down Expand Up @@ -291,6 +292,11 @@ golangci-lint: .install.golangci-lint
CGO_ENABLED=0 GOOS=freebsd hack/golangci-lint.sh
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 hack/golangci-lint.sh

.PHONY: shfmt
shfmt: .install.shfmt
./bin/shfmt --version
./bin/shfmt -d -w ./hack/

.PHONY: test/checkseccomp/checkseccomp
test/checkseccomp/checkseccomp: $(wildcard test/checkseccomp/*.go)
$(GOCMD) build $(BUILDFLAGS) $(GO_LDFLAGS) '$(LDFLAGS_PODMAN)' -tags "$(BUILDTAGS)" -o $@ ./test/checkseccomp
Expand Down Expand Up @@ -319,7 +325,7 @@ codespell:

# Code validation target that **DOES NOT** require building podman binaries
.PHONY: validate-source
validate-source: lint .commit-subject-check swagger-check tests-expect-exit pr-removes-fixed-skips
validate-source: lint shfmt .commit-subject-check swagger-check tests-expect-exit pr-removes-fixed-skips

# Code validation target that **DOES** require building podman binaries
.PHONY: validate-binaries
Expand Down Expand Up @@ -1013,6 +1019,10 @@ install.tools: .install.golangci-lint ## Install needed tools
.install.golangci-lint:
VERSION=$(GOLANGCI_LINT_VERSION) ./hack/install_golangci.sh

.PHONY: .install.shfmt
.install.shfmt:
GOBIN=$(CURDIR)/bin $(GO) install mvdan.cc/sh/v3/cmd/shfmt@v$(SHFMT_VERSION)

.PHONY: .install.swagger
.install.swagger:
$(MAKE) -C test/tools build/swagger
Expand Down
4 changes: 2 additions & 2 deletions hack/apparmor_tag.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
if pkg-config libapparmor 2> /dev/null ; then
echo apparmor
if pkg-config libapparmor 2> /dev/null; then
echo apparmor
fi
67 changes: 36 additions & 31 deletions hack/bats
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,40 @@ declare -a bats_filter=()

declare -a TESTS

for i;do
value=`expr "$i" : '[^=]*=\(.*\)'`
for i; do
value=$(expr "$i" : '[^=]*=\(.*\)')
case "$i" in
-h|--help) echo "$usage"; exit 0;;
--root) TEST_ROOTLESS= ;;
--rootless) TEST_ROOT= ;;
--remote) REMOTE=remote ;;
--tap|-t) bats_opts+=("-t") ;;
--ts|-T) bats_opts+=("-T") ;;
--tag=*) bats_filter=("--filter-tags" "$value")
if [[ "$value" = "ci:parallel" ]]; then
bats_opts+=("--jobs" $(nproc))
fi;;
*/*.bats) TESTS+=("$i") ;;
*)
if [[ $i =~ : ]]; then
tname=${i%:*} # network:localhost -> network
filt=${i#*:} # network:localhost -> localhost
TESTS+=($(echo $TESTS_DIR/*$tname*.bats))
bats_filter=("--filter" "$filt")
else
TESTS+=($(echo $TESTS_DIR/*$i*.bats))
fi
;;
-h | --help)
echo "$usage"
exit 0
;;
--root) TEST_ROOTLESS= ;;
--rootless) TEST_ROOT= ;;
--remote) REMOTE=remote ;;
--tap | -t) bats_opts+=("-t") ;;
--ts | -T) bats_opts+=("-T") ;;
--tag=*)
bats_filter=("--filter-tags" "$value")
if [[ "$value" = "ci:parallel" ]]; then
bats_opts+=("--jobs" $(nproc))
fi
;;
*/*.bats) TESTS+=("$i") ;;
*)
if [[ $i =~ : ]]; then
tname=${i%:*} # network:localhost -> network
filt=${i#*:} # network:localhost -> localhost
TESTS+=($(echo $TESTS_DIR/*$tname*.bats))
bats_filter=("--filter" "$filt")
else
TESTS+=($(echo $TESTS_DIR/*$i*.bats))
fi
;;
esac
done

if [ ${#TESTS[@]} -eq 0 ] ; then
TESTS=("$TESTS_DIR")
if [ ${#TESTS[@]} -eq 0 ]; then
TESTS=("$TESTS_DIR")
fi

# With --remote, use correct binary and make sure daem--I mean server--is live
Expand Down Expand Up @@ -125,12 +130,12 @@ export PODMAN_BATS_LEAK_CHECK=1
# Root
if [[ "$TEST_ROOT" ]]; then
echo "# bats ${bats_opts[*]} ${bats_filter[*]} ${TESTS[*]}"
sudo --preserve-env=PODMAN \
--preserve-env=QUADLET \
--preserve-env=PODMAN_TEST_DEBUG \
--preserve-env=CONTAINERS_HELPER_BINARY_DIR \
--preserve-env=PODMAN_ROOTLESS_USER \
bats "${bats_opts[@]}" "${bats_filter[@]}" "${TESTS[@]}"
sudo --preserve-env=PODMAN \
--preserve-env=QUADLET \
--preserve-env=PODMAN_TEST_DEBUG \
--preserve-env=CONTAINERS_HELPER_BINARY_DIR \
--preserve-env=PODMAN_ROOTLESS_USER \
bats "${bats_opts[@]}" "${bats_filter[@]}" "${TESTS[@]}"
rc=$?
fi

Expand Down
4 changes: 2 additions & 2 deletions hack/btrfs_installed_tag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
${CPP:-${CC:-cc} -E} ${CPPFLAGS} - > /dev/null 2> /dev/null << EOF
#include <btrfs/ioctl.h>
EOF
if test $? -ne 0 ; then
echo exclude_graphdriver_btrfs
if test $? -ne 0; then
echo exclude_graphdriver_btrfs
fi
4 changes: 2 additions & 2 deletions hack/check_root.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
if ! [ $(id -u) = 0 ]; then
echo "Please run as root! '$*' requires root privileges."
exit 1
echo "Please run as root! '$*' requires root privileges."
exit 1
fi
20 changes: 10 additions & 10 deletions hack/commit-subject-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ set -euo pipefail
MAX=90

if [[ $# -ne 1 ]]; then
echo "Usage: $0 <git-range>" >&2
exit 2
echo "Usage: $0 <git-range>" >&2
exit 2
fi

range=$1
rc=0

while IFS=$'\t' read -r sha subject; do
len=${#subject}
if [[ $len -eq 0 ]]; then
echo "$sha: empty commit subject" >&2
rc=1
elif [[ $len -ge $MAX ]]; then
echo "$sha: subject is $len chars (must be < $MAX): $subject" >&2
rc=1
fi
len=${#subject}
if [[ $len -eq 0 ]]; then
echo "$sha: empty commit subject" >&2
rc=1
elif [[ $len -ge $MAX ]]; then
echo "$sha: subject is $len chars (must be < $MAX): $subject" >&2
rc=1
fi
done < <(git log --no-merges --format='%H%x09%s' "$range")

exit $rc
24 changes: 12 additions & 12 deletions hack/get_ci_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ REPO_DIRPATH=$(realpath "$SCRIPT_DIRPATH/../")
# Help detect what get_ci_vm container called this script
GET_CI_VM="${GET_CI_VM:-0}"
in_get_ci_vm() {
if ((GET_CI_VM==0)); then
if ((GET_CI_VM == 0)); then
echo "Error: $1 is not intended for use in this context"
exit 2
fi
Expand All @@ -27,10 +27,10 @@ in_get_ci_vm() {
# get_ci_vm APIv1 container entrypoint calls into this script
# to obtain required repo. specific configuration options.
if [[ "$1" == "--config" ]]; then
in_get_ci_vm "$1" # handles GET_CI_VM==0 case
in_get_ci_vm "$1" # handles GET_CI_VM==0 case
case "$GET_CI_VM" in
1)
cat <<EOF
1)
cat << EOF
DESTDIR="/var/tmp/go/src/github.com/containers/podman"
UPSTREAM_REPO="https://github.com/containers/podman.git"
CI_ENVFILE="/etc/ci_environment"
Expand All @@ -42,14 +42,14 @@ GCLOUD_CPUS="2"
GCLOUD_MEMORY="4Gb"
GCLOUD_DISK="200"
EOF
;;
2)
# get_ci_vm APIv2 configuration details
echo "AWS_PROFILE=containers"
;;
*)
echo "Error: Your get_ci_vm container image is too old."
;;
;;
2)
# get_ci_vm APIv2 configuration details
echo "AWS_PROFILE=containers"
;;
*)
echo "Error: Your get_ci_vm container image is too old."
;;
esac
elif [[ "$1" == "--setup" ]]; then
in_get_ci_vm "$1"
Expand Down
19 changes: 10 additions & 9 deletions hack/golangci-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ BIN="$(command -v golangci-lint || echo ./bin/golangci-lint)"

echo "Linting for GOOS=$GOOS"
case "$GOOS" in
windows|darwin)
windows | darwin)
# For Darwin and Windows, only "remote" linting is possible and required.
TAGS="remote,containers_image_openpgp"
;;
freebsd)
freebsd)
TAGS="containers_image_openpgp"
EXTRA_TAGS=(",remote")
;;
*)
*)
# Assume Linux: run linter for various sets of build tags.
TAGS="apparmor,seccomp,selinux"
EXTRA_TAGS=(",systemd" ",remote")
;;
esac

for EXTRA in "" "${EXTRA_TAGS[@]}"; do
# Use set -x in a subshell to make it easy for a developer to copy-paste
# the command-line to focus or debug a single, specific linting category.
(
set -x
"$BIN" run --build-tags="${TAGS}${EXTRA}" "$@"
)
# Use set -x in a subshell to make it easy for a developer to copy-paste
# the command-line to focus or debug a single, specific linting category.
(
set -x
"$BIN" run --build-tags="${TAGS}${EXTRA}" "$@"
)
done
5 changes: 4 additions & 1 deletion hack/install_golangci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# This script is intended to be a convenience, to be called from the
# Makefile `.install.golangci-lint` target. Any other usage is not recommended.

die() { echo "${1:-No error message given} (from $(basename "$0"))"; exit 1; }
die() {
echo "${1:-No error message given} (from $(basename "$0"))"
exit 1
}

[ -n "$VERSION" ] || die "\$VERSION is empty or undefined"

Expand Down
8 changes: 4 additions & 4 deletions hack/libsubid_tag.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
if test $(${GO:-go} env GOOS) != "linux" ; then
exit 0
if test $(${GO:-go} env GOOS) != "linux"; then
exit 0
fi
tmpdir="$PWD/tmp.$RANDOM"
mkdir -p "$tmpdir"
Expand All @@ -24,6 +24,6 @@ int main() {
return 0;
}
EOF
if test $? -eq 0 ; then
echo libsubid
if test $? -eq 0; then
echo libsubid
fi
14 changes: 7 additions & 7 deletions hack/make-and-check-size
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ function bloat_approved() {
}\"
}"

result=$(curl -s -H "Authorization: bearer $CIRRUS_REPO_CLONE_TOKEN" -H "Accept: application/vnd.github.antiope-preview+json" -H "Content-Type: application/json" -X POST --data @- https://api.github.com/graphql <<<"$query")
result=$(curl -s -H "Authorization: bearer $CIRRUS_REPO_CLONE_TOKEN" -H "Accept: application/vnd.github.antiope-preview+json" -H "Content-Type: application/json" -X POST --data @- https://api.github.com/graphql <<< "$query")

labels=$(jq -r '.data.repository.pullRequest.labels.nodes[].name' <<<"$result")
labels=$(jq -r '.data.repository.pullRequest.labels.nodes[].name' <<< "$result")

grep -q -w "$OVERRIDE_LABEL" <<<"$labels"
grep -q -w "$OVERRIDE_LABEL" <<< "$labels"
}

# ACTUAL CODE BEGINS HERE
Expand All @@ -101,21 +101,21 @@ make
# Determine size of each built file.
# - If this is our first time through, preserve that size in a tmpfile
# - On all subsequent runs, compare built size to initial size
for bin in bin/*;do
for bin in bin/*; do
size=$(stat -c %s $bin)

saved_size_file=$context_dir/$(basename $bin)
if [[ -e $saved_size_file ]]; then
# Not the first time through: compare to original size
size_orig=$(< $saved_size_file)
delta_size=$(( size - size_orig ))
delta_size=$((size - size_orig))

printf "%-20s size=%9d delta=%6d\n" $bin $size $delta_size
if [[ "$bin" = bin/podman-testing ]]; then
continue # We compute / list this for completeness, but size does not matter to users.
fi
if [[ $delta_size -gt $MAX_BIN_GROWTH ]]; then
separator=$(printf "%.0s*" {1..75}) # row of stars, for highlight
separator=$(printf "%.0s*" {1..75}) # row of stars, for highlight
echo "$separator"
echo "* $bin grew by $delta_size bytes; max allowed is $MAX_BIN_GROWTH."
echo "*"
Expand All @@ -133,7 +133,7 @@ for bin in bin/*;do
fi
else
# First time through: preserve original file size
echo $size >$saved_size_file
echo $size > $saved_size_file
printf "%-20s size=%9d\n" $bin $size
fi
done
Loading