Skip to content

Commit 8276c0b

Browse files
authored
ci: add CI workflow to run plugin against itself (#267)
Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent 2415644 commit 8276c0b

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

.github/scripts/ci.sh

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
#!/bin/sh
2+
3+
# This script is used in the ci.yaml workflow
4+
# but can also be used locally to test the
5+
# plugin against a real GitHub repository.
6+
# Change lines 100-103 to test against a different repository.
7+
8+
set -x
9+
10+
STATUS=0
11+
12+
# Require gh CLI to be installed
13+
if ! command -v gh >/dev/null 2>&1; then
14+
echo "ERROR: gh CLI is not installed"
15+
echo "Install it from https://cli.github.com/"
16+
exit 1
17+
fi
18+
19+
# Require GITHUB_TOKEN to be set
20+
if [ -z "$GITHUB_TOKEN" ]; then
21+
echo "ERROR: GITHUB_TOKEN environment variable is not set"
22+
echo "You can do the following to set it:"
23+
echo " \`gh auth login\` and follow the prompts to authenticate with GitHub"
24+
echo " export GITHUB_TOKEN=\$(gh auth token)"
25+
exit 1
26+
fi
27+
28+
# Require plugin binary to be present in the current directory
29+
if [ ! -f "./github-repo" ]; then
30+
echo "ERROR: github-repo binary is not present in the current directory"
31+
echo "You can do the following to build it:"
32+
echo " make -B build"
33+
exit 1
34+
fi
35+
36+
# Detect OS and architecture
37+
OS=$(uname -s)
38+
ARCH=$(uname -m)
39+
40+
case "$OS" in
41+
Linux) RELEASE_OS="Linux" ;;
42+
Darwin) RELEASE_OS="Darwin" ;;
43+
*)
44+
echo "ERROR: Unsupported OS: $OS"
45+
exit 1
46+
;;
47+
esac
48+
49+
case "$ARCH" in
50+
x86_64) RELEASE_ARCH="x86_64" ;;
51+
aarch64) RELEASE_ARCH="arm64" ;;
52+
arm64) RELEASE_ARCH="arm64" ;;
53+
i386) RELEASE_ARCH="i386" ;;
54+
i686) RELEASE_ARCH="i386" ;;
55+
*)
56+
echo "ERROR: Unsupported architecture: $ARCH"
57+
exit 1
58+
;;
59+
esac
60+
61+
# Darwin releases use "all" for architecture
62+
if [ "$RELEASE_OS" = "Darwin" ]; then
63+
RELEASE_ARCH="all"
64+
fi
65+
66+
ASSET_PATTERN="privateer_${RELEASE_OS}_${RELEASE_ARCH}.tar.gz"
67+
PLUGIN_DIR="./tmp/plugins"
68+
CONFIG_FILE="./tmp/test_config.yml"
69+
70+
# Ensure cleanup happens even on unexpected exits or signals
71+
trap 'rm -rf "./tmp"' EXIT
72+
73+
# Set up plugin directory and copy the built plugin binary
74+
mkdir -p "$PLUGIN_DIR"
75+
cp github-repo "$PLUGIN_DIR/" || { echo "ERROR: Failed to copy plugin binary"; exit 1; }
76+
77+
# Download latest pvtr release
78+
gh release download \
79+
--repo privateerproj/privateer \
80+
--pattern "$ASSET_PATTERN" \
81+
--dir /tmp \
82+
--clobber || { echo "ERROR: Failed to download pvtr release"; exit 1; }
83+
84+
tar xzf "/tmp/$ASSET_PATTERN" -C "./tmp" || { echo "ERROR: Failed to extract plugin"; exit 1; }
85+
86+
# Generate config for testing against the repo
87+
cat > "$CONFIG_FILE" <<EOF
88+
loglevel: trace
89+
write-directory: evaluation_results
90+
write: true
91+
output: yaml
92+
services:
93+
privateer:
94+
plugin: github-repo
95+
policy:
96+
catalogs:
97+
- osps-baseline
98+
applicability:
99+
- Maturity Level 1
100+
vars:
101+
owner: ossf
102+
repo: pvtr-github-repo-scanner
103+
token: ${GITHUB_TOKEN}
104+
EOF
105+
106+
# Run pvtr with the plugin
107+
./tmp/pvtr run -b "$PLUGIN_DIR" -c "$CONFIG_FILE" || STATUS=1
108+
109+
exit $STATUS

.github/workflows/ci.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: CI
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
ci:
17+
name: CI
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
with:
22+
persist-credentials: false
23+
- uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
24+
with:
25+
go-version-file: go.mod
26+
- name: Build
27+
run: make -B build
28+
- name: Plugin Test
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
run: |
32+
set -o pipefail
33+
./.github/scripts/ci.sh 2>&1 | tee integration_output.txt
34+
- name: Verify test output
35+
run: |
36+
grep -E 'privateer_osps-baseline.*Passed.*Warnings.*Failed.*Possible' integration_output.txt

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ TODO.md
1717

1818
# ignore the local cache of claude
1919
.claude/
20+
21+
# ignore ci testing folder
22+
tmp/

0 commit comments

Comments
 (0)