2026-10-25 15:28:19 +00:00
|
|
|
name: validate
|
|
|
|
|
on:
|
|
|
|
|
push:
|
|
|
|
|
branches: [main]
|
|
|
|
|
pull_request:
|
|
|
|
|
branches: [main]
|
|
|
|
|
|
2026-10-25 15:36:59 +00:00
|
|
|
# The repository uses the sha256 git object format. Git < 2.42 cannot speak
|
2026-10-25 15:40:01 +00:00
|
|
|
# the sha256 wire protocol, and actions/checkout@v4 does `git init` without
|
|
|
|
|
# --object-format=sha256, which produces `fatal: mismatched algorithms:
|
|
|
|
|
# client sha1; server sha256`. We therefore skip actions/checkout entirely
|
|
|
|
|
# and clone manually from a trixie-based container (git 2.47+).
|
2026-10-25 15:28:19 +00:00
|
|
|
jobs:
|
|
|
|
|
json-schema:
|
|
|
|
|
name: JSON Schema (ajv)
|
|
|
|
|
runs-on: ubuntu-latest
|
2026-10-25 15:36:59 +00:00
|
|
|
container:
|
|
|
|
|
image: node:24-trixie-slim
|
2026-10-25 15:28:19 +00:00
|
|
|
steps:
|
2026-10-25 15:36:59 +00:00
|
|
|
- name: Install git + curl in container
|
2026-10-25 15:30:57 +00:00
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-10-25 15:36:59 +00:00
|
|
|
apt-get update
|
|
|
|
|
apt-get install -y --no-install-recommends git curl ca-certificates
|
|
|
|
|
git --version
|
2026-10-25 16:19:37 +00:00
|
|
|
node --version
|
2026-10-25 15:30:57 +00:00
|
|
|
|
2026-10-25 15:40:01 +00:00
|
|
|
- name: Clone repository (sha256-aware)
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
git clone --depth=1 --branch="${GITHUB_REF_NAME}" \
|
|
|
|
|
"https://x-access-token:${GITHUB_TOKEN}@forgejo.basicstack.de/${GITHUB_REPOSITORY}.git" "${GITHUB_WORKSPACE}"
|
|
|
|
|
cd "${GITHUB_WORKSPACE}"
|
|
|
|
|
git log -1 --oneline
|
2026-10-25 15:28:19 +00:00
|
|
|
|
2026-10-25 15:30:57 +00:00
|
|
|
- name: Install ajv-cli + ajv-formats
|
2026-10-25 15:40:01 +00:00
|
|
|
working-directory: ${{ github.workspace }}
|
2026-10-25 15:30:57 +00:00
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
npm install --prefix /tmp/ajv ajv-cli@5 ajv-formats@3
|
2026-10-25 15:28:19 +00:00
|
|
|
|
|
|
|
|
- name: Validate every JSON Schema parses as JSON
|
2026-10-25 15:40:01 +00:00
|
|
|
working-directory: ${{ github.workspace }}
|
2026-10-25 15:28:19 +00:00
|
|
|
run: |
|
2026-10-25 16:19:37 +00:00
|
|
|
set -eu
|
|
|
|
|
find schemas -type f -name 'v*.json' -print | while IFS= read -r f; do
|
2026-10-25 15:28:19 +00:00
|
|
|
echo "--- parse: $f"
|
|
|
|
|
node -e "require('./$f')"
|
|
|
|
|
done
|
|
|
|
|
|
2026-10-25 15:30:57 +00:00
|
|
|
- name: Meta-validate each schema against JSON Schema 2020-12
|
2026-10-25 15:40:01 +00:00
|
|
|
working-directory: ${{ github.workspace }}
|
2026-10-25 15:28:19 +00:00
|
|
|
run: |
|
2026-10-25 16:19:37 +00:00
|
|
|
set -eu
|
2026-10-25 15:30:57 +00:00
|
|
|
export NODE_PATH=/tmp/ajv/node_modules
|
2026-10-25 16:19:37 +00:00
|
|
|
find schemas -type f -name 'v*.json' -print | while IFS= read -r f; do
|
2026-10-25 15:28:19 +00:00
|
|
|
echo "--- meta-validate: $f"
|
2026-10-25 15:30:57 +00:00
|
|
|
node /tmp/ajv/node_modules/.bin/ajv compile --spec=draft2020 -c=ajv-formats -s "$f"
|
2026-10-25 15:28:19 +00:00
|
|
|
done
|
|
|
|
|
|
2026-10-25 16:19:37 +00:00
|
|
|
- name: Validate per-version example payloads against their schemas
|
2026-10-25 15:40:01 +00:00
|
|
|
working-directory: ${{ github.workspace }}
|
2026-10-25 15:28:19 +00:00
|
|
|
run: |
|
2026-10-25 15:41:18 +00:00
|
|
|
set -eu
|
2026-10-25 15:30:57 +00:00
|
|
|
export NODE_PATH=/tmp/ajv/node_modules
|
2026-10-25 16:19:37 +00:00
|
|
|
# Each schema file is <path>/vX.Y.Z.json; example payloads for that version
|
|
|
|
|
# live under <path>/examples/vX.Y.Z/*.json. This keeps v1.0.0 examples from
|
|
|
|
|
# being validated against v1.1.0 and vice-versa.
|
2026-10-25 15:41:18 +00:00
|
|
|
find schemas -type f -name 'v*.json' -print | while IFS= read -r schema; do
|
2026-10-25 16:19:37 +00:00
|
|
|
version="$(basename "$schema" .json)"
|
|
|
|
|
dir="$(dirname "$schema")/examples/$version"
|
2026-10-25 15:28:19 +00:00
|
|
|
[ -d "$dir" ] || continue
|
2026-10-25 15:41:18 +00:00
|
|
|
find "$dir" -type f -name '*.json' -print | while IFS= read -r example; do
|
2026-10-25 15:28:19 +00:00
|
|
|
echo "--- validate example $example against $schema"
|
2026-10-25 15:30:57 +00:00
|
|
|
node /tmp/ajv/node_modules/.bin/ajv validate --spec=draft2020 -c=ajv-formats -s "$schema" -d "$example"
|
2026-10-25 15:28:19 +00:00
|
|
|
done
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
rego:
|
|
|
|
|
name: Rego (opa fmt + opa test)
|
|
|
|
|
runs-on: ubuntu-latest
|
2026-10-25 15:36:59 +00:00
|
|
|
container:
|
|
|
|
|
image: debian:trixie-slim
|
2026-10-25 15:28:19 +00:00
|
|
|
steps:
|
2026-10-25 15:36:59 +00:00
|
|
|
- name: Install git + curl in container
|
2026-10-25 15:30:57 +00:00
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-10-25 15:36:59 +00:00
|
|
|
apt-get update
|
|
|
|
|
apt-get install -y --no-install-recommends git curl ca-certificates
|
|
|
|
|
git --version
|
2026-10-25 15:30:57 +00:00
|
|
|
|
2026-10-25 15:40:01 +00:00
|
|
|
- name: Clone repository (sha256-aware)
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
git clone --depth=1 --branch="${GITHUB_REF_NAME}" \
|
|
|
|
|
"https://x-access-token:${GITHUB_TOKEN}@forgejo.basicstack.de/${GITHUB_REPOSITORY}.git" "${GITHUB_WORKSPACE}"
|
|
|
|
|
cd "${GITHUB_WORKSPACE}"
|
|
|
|
|
git log -1 --oneline
|
2026-10-25 15:28:19 +00:00
|
|
|
|
|
|
|
|
- name: Install OPA
|
|
|
|
|
run: |
|
|
|
|
|
set -euo pipefail
|
2026-10-25 15:30:57 +00:00
|
|
|
mkdir -p "$HOME/.local/bin"
|
|
|
|
|
curl -sSL -o "$HOME/.local/bin/opa" https://openpolicyagent.org/downloads/v1.9.0/opa_linux_amd64_static
|
|
|
|
|
chmod +x "$HOME/.local/bin/opa"
|
|
|
|
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
|
|
|
|
"$HOME/.local/bin/opa" version
|
2026-10-25 15:28:19 +00:00
|
|
|
|
|
|
|
|
- name: opa fmt (fail on any diff)
|
2026-10-25 15:40:01 +00:00
|
|
|
working-directory: ${{ github.workspace }}
|
2026-10-25 15:28:19 +00:00
|
|
|
run: opa fmt --list --diff policies/
|
|
|
|
|
|
|
|
|
|
- name: opa test
|
2026-10-25 15:40:01 +00:00
|
|
|
working-directory: ${{ github.workspace }}
|
2026-10-25 15:28:19 +00:00
|
|
|
run: opa test policies/ -v
|