diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..cd58227 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,33 @@ +name: Validate Profiles + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Build profiles archive + run: bash make_profiles_archive.sh profiles.zip + + - name: Validate profiles + run: | + response=$(curl -sf -w "\n%{http_code}" \ + -X POST https://api.enapter.com/v3/blueprints/device_profiles/validate \ + -H "Content-Type: application/zip" \ + --data-binary @profiles.zip) + body=$(echo "$response" | head -n -1 | jq .) + status=$(echo "$response" | tail -n 1) + echo "$body" + if [ "$status" -lt 200 ] || [ "$status" -ge 300 ]; then + echo "Validation failed with HTTP $status" + exit 1 + fi + if [ "$(echo "$body" | jq '.validation_errors | length')" -gt 0 ]; then + exit 1 + fi diff --git a/make_profiles_archive.sh b/make_profiles_archive.sh new file mode 100755 index 0000000..b07d67d --- /dev/null +++ b/make_profiles_archive.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +REPO_ROOT="$(cd "$(dirname "$0")" && pwd)" +OUTPUT="${1:-profiles.zip}" + +# Use a temp dir for staging +STAGING=$(mktemp -d) +trap 'rm -rf "$STAGING"' EXIT + +find "$REPO_ROOT" -name "*.yml" -not -path '*/.github/*' | while read -r file; do + # Get path relative to repo root + rel="${file#"$REPO_ROOT"/}" + # Convert path to folder name: replace / with . and strip .yml + folder="${rel%.yml}" + folder="${folder//\//.}" + # Copy file as manifest.yml inside the folder + mkdir -p "$STAGING/$folder" + cp "$file" "$STAGING/$folder/manifest.yml" +done + +# Create the zip from the staging dir +(cd "$STAGING" && zip -r - .) > "$OUTPUT" + +echo "Created $OUTPUT"