-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathintegration_test.sh
More file actions
executable file
·100 lines (84 loc) · 2.38 KB
/
integration_test.sh
File metadata and controls
executable file
·100 lines (84 loc) · 2.38 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/sh
set -x
STATUS=0
# Require gh CLI to be installed
if ! command -v gh >/dev/null 2>&1; then
echo "ERROR: gh CLI is not installed"
echo "Install it from https://cli.github.com/"
exit 1
fi
# Require GITHUB_TOKEN to be set
if [ -z "$GITHUB_TOKEN" ]; then
echo "ERROR: GITHUB_TOKEN environment variable is not set"
echo "You can do the following to set it:"
echo " \`gh auth login\` and follow the prompts to authenticate with GitHub"
echo " export GITHUB_TOKEN=\$(gh auth token)"
exit 1
fi
# Run basic pvtr commands to verify installation
./pvtr completion || STATUS=1
./pvtr env || STATUS=1
./pvtr help || STATUS=1
./pvtr list || STATUS=1
./pvtr version || STATUS=1
# Detect OS and architecture
OS=$(uname -s)
ARCH=$(uname -m)
case "$OS" in
Linux) RELEASE_OS="Linux" ;;
Darwin) RELEASE_OS="Darwin" ;;
*)
echo "ERROR: Unsupported OS: $OS"
exit 1
;;
esac
case "$ARCH" in
x86_64) RELEASE_ARCH="x86_64" ;;
aarch64) RELEASE_ARCH="arm64" ;;
arm64) RELEASE_ARCH="arm64" ;;
i386) RELEASE_ARCH="i386" ;;
i686) RELEASE_ARCH="i386" ;;
*)
echo "ERROR: Unsupported architecture: $ARCH"
exit 1
;;
esac
# Darwin releases use "all" for architecture
if [ "$RELEASE_OS" = "Darwin" ]; then
RELEASE_ARCH="all"
fi
ASSET_PATTERN="pvtr-github-repo-scanner_${RELEASE_OS}_${RELEASE_ARCH}.tar.gz"
PLUGIN_DIR="./plugins"
CONFIG_FILE="./test_config.yml"
# Ensure cleanup happens even on unexpected exits or signals
trap 'rm -rf "$PLUGIN_DIR" "$CONFIG_FILE" "/tmp/$ASSET_PATTERN" evaluation_results' EXIT
# Download latest pvtr-github-repo-scanner release
mkdir -p "$PLUGIN_DIR"
gh release download \
--repo ossf/pvtr-github-repo-scanner \
--pattern "$ASSET_PATTERN" \
--dir /tmp \
--clobber || { echo "ERROR: Failed to download plugin release"; exit 1; }
tar xzf "/tmp/$ASSET_PATTERN" -C "$PLUGIN_DIR" || { echo "ERROR: Failed to extract plugin"; exit 1; }
# Generate config for testing against the repo
cat > "$CONFIG_FILE" <<EOF
loglevel: trace
write-directory: evaluation_results
write: true
output: yaml
services:
privateer:
plugin: pvtr-github-repo-scanner
policy:
catalogs:
- osps-baseline
applicability:
- Maturity Level 1
vars:
owner: privateerproj
repo: privateer
token: ${GITHUB_TOKEN}
EOF
# Run pvtr with the plugin
./pvtr run -b "$PLUGIN_DIR" -c "$CONFIG_FILE" || STATUS=1
exit $STATUS