ci: make workflow robust — apt-get curl pre-step, local ajv install, OPA to user HOME, no setup-node reliance
This commit is contained in:
parent
baa8b61021
commit
81bc32e9c3
1 changed files with 27 additions and 16 deletions
|
|
@ -10,16 +10,20 @@ jobs:
|
||||||
name: JSON Schema (ajv)
|
name: JSON Schema (ajv)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Install prerequisites in container
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
command -v curl >/dev/null || { apt-get update && apt-get install -y curl ca-certificates; }
|
||||||
|
node --version
|
||||||
|
npm --version
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Install ajv-cli + ajv-formats
|
||||||
uses: actions/setup-node@v4
|
run: |
|
||||||
with:
|
set -euo pipefail
|
||||||
node-version: "22"
|
npm install --prefix /tmp/ajv ajv-cli@5 ajv-formats@3
|
||||||
|
|
||||||
- name: Install ajv
|
|
||||||
run: npm install -g ajv-cli@5 ajv-formats@3
|
|
||||||
|
|
||||||
- name: Validate every JSON Schema parses as JSON
|
- name: Validate every JSON Schema parses as JSON
|
||||||
run: |
|
run: |
|
||||||
|
|
@ -29,26 +33,26 @@ jobs:
|
||||||
node -e "require('./$f')"
|
node -e "require('./$f')"
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Validate each schema is itself valid against JSON Schema 2020-12
|
- name: Meta-validate each schema against JSON Schema 2020-12
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
export NODE_PATH=/tmp/ajv/node_modules
|
||||||
find schemas -type f -name '*.json' -print | while read -r f; do
|
find schemas -type f -name '*.json' -print | while read -r f; do
|
||||||
echo "--- meta-validate: $f"
|
echo "--- meta-validate: $f"
|
||||||
ajv compile --spec=draft2020 -c ajv-formats -s "$f"
|
node /tmp/ajv/node_modules/.bin/ajv compile --spec=draft2020 -c=ajv-formats -s "$f"
|
||||||
done
|
done
|
||||||
|
|
||||||
- name: Validate example payloads against their schemas
|
- name: Validate example payloads against their schemas (if any)
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
export NODE_PATH=/tmp/ajv/node_modules
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
# Convention: schemas/.../v<version>.json may have sibling
|
|
||||||
# examples/*.json documents to validate against the schema.
|
|
||||||
for schema in $(find schemas -type f -name '*.json'); do
|
for schema in $(find schemas -type f -name '*.json'); do
|
||||||
dir="$(dirname "$schema")/examples"
|
dir="$(dirname "$schema")/examples"
|
||||||
[ -d "$dir" ] || continue
|
[ -d "$dir" ] || continue
|
||||||
for example in "$dir"/*.json; do
|
for example in "$dir"/*.json; do
|
||||||
echo "--- validate example $example against $schema"
|
echo "--- validate example $example against $schema"
|
||||||
ajv validate --spec=draft2020 -c ajv-formats -s "$schema" -d "$example"
|
node /tmp/ajv/node_modules/.bin/ajv validate --spec=draft2020 -c=ajv-formats -s "$schema" -d "$example"
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
@ -56,15 +60,22 @@ jobs:
|
||||||
name: Rego (opa fmt + opa test)
|
name: Rego (opa fmt + opa test)
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Install prerequisites in container
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
command -v curl >/dev/null || { apt-get update && apt-get install -y curl ca-certificates; }
|
||||||
|
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install OPA
|
- name: Install OPA
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
curl -sSL -o /usr/local/bin/opa https://openpolicyagent.org/downloads/v1.9.0/opa_linux_amd64_static
|
mkdir -p "$HOME/.local/bin"
|
||||||
chmod +x /usr/local/bin/opa
|
curl -sSL -o "$HOME/.local/bin/opa" https://openpolicyagent.org/downloads/v1.9.0/opa_linux_amd64_static
|
||||||
opa version
|
chmod +x "$HOME/.local/bin/opa"
|
||||||
|
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
|
||||||
|
"$HOME/.local/bin/opa" version
|
||||||
|
|
||||||
- name: opa fmt (fail on any diff)
|
- name: opa fmt (fail on any diff)
|
||||||
run: opa fmt --list --diff policies/
|
run: opa fmt --list --diff policies/
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue