File: validate_seccomp.sh

package info (click to toggle)
golang-github-containers-common 0.62.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,436 kB
  • sloc: makefile: 131; sh: 102
file content (39 lines) | stat: -rwxr-xr-x 1,009 bytes parent folder | download | duplicates (5)
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
#!/bin/bash
#
# validate_seccomp.sh <gopath/to/pkg/seccomp>
#
# Validates that the seccomp.json file has been generated and matches the
# profile defined in the pkg/seccomp package.

set -Eeuo pipefail

PACKAGE_PATH="${1:-./pkg/seccomp}"
TARGET_FILE="$PACKAGE_PATH/seccomp.json"

# Stash a copy.
tmp_copy="$(mktemp --tmpdir podman-seccomp.json.XXXXXX)"
cp "$TARGET_FILE" "$tmp_copy"

# Generate it again and figure out if there was a difference.
go generate -tags seccomp "$PACKAGE_PATH" >/dev/null
diffs="$(diff -u "$tmp_copy" "$TARGET_FILE" ||:)"

if [ "$diffs" ]; then
	# Can we make a prettier diff?
	have_diffstat=1
	which diffstat || have_diffstat=
	if [ "$have_diffstat" ]; then
		diffs="$(echo "$diffs" | diffstat)"
	fi

	# Output an error message and fail the CI.
	cat >&2 <<-EOF
	The result of 'go generate -tags seccomp $PACKAGE_PATH' differs.

	$diffs

	Please re-run 'go generate -tags seccomp $PACKAGE_PATH' and then amend your
	commits to include the updated seccomp.json file.
	EOF
	exit 1
fi