-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(json-schema-validation): validate manifest.json * feat(json-schema-validation): add dedicated commit/pr action * chore: fix file path for schema * chore: specify draft2020 for schema validation
- Loading branch information
1 parent
c8b8d3e
commit eb228c5
Showing
4 changed files
with
256 additions
and
7 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
.github/workflows/docs-as-code-pr-commit-validation.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
name: Docs as Code PR and Commit Validation | ||
|
||
on: | ||
push: | ||
branches: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- '*' | ||
workflow_dispatch: | ||
inputs: | ||
log_level: | ||
description: 'Log level: 1=DEBUG, 2=INFO, 3=WARNING, 4=ERROR' | ||
required: false | ||
default: '2' # Set the default log level to INFO | ||
skip_api_linting: | ||
description: 'Skip the API linting job' | ||
required: false | ||
default: 'false' | ||
|
||
env: | ||
SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_API_KEY }} | ||
LOG_LEVEL: ${{ github.event.inputs.log_level }} | ||
|
||
jobs: | ||
spell-check: | ||
runs-on: ubuntu-latest | ||
environment: Production | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install cspell | ||
run: npm install -g cspell | ||
|
||
- name: Run cspell | ||
run: cspell --config ./.cspell.json "./products/**/*.md" | ||
|
||
validate-manifests: | ||
runs-on: ubuntu-latest | ||
environment: Production | ||
needs: spell-check | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Install AJV CLI | ||
run: npm install -g ajv-cli | ||
|
||
- name: Validate manifests | ||
run: | | ||
# source the utility script | ||
. ./scripts/utilities.sh | ||
for product in ./products/*; do | ||
if [[ -d "$product" ]]; then | ||
product_name=${product#./products/} | ||
manifest="./products/$product_name/manifest.json" | ||
if [[ -f "$manifest" ]]; then | ||
# Further actions... | ||
log_message $INFO "Validating manifest in product: $product_name" | ||
log_message $DEBUG "Validating manifest: $manifest" | ||
ajv validate -s ./schemas/manifest.schema.json -d "$manifest" --spec=draft2020 | ||
fi | ||
fi | ||
done | ||
lint-api: | ||
runs-on: ubuntu-latest | ||
if: github.event.inputs.skip_api_linting != 'true' | ||
environment: Production | ||
needs: validate-manifests | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Install SwaggerHub CLI | ||
run: npm install -g swaggerhub-cli | ||
|
||
- name: Iterate over product folders and validate APIs | ||
shell: bash | ||
run: | | ||
# source the utility script | ||
. ./scripts/utilities.sh | ||
for product in ./products/*; do | ||
log_message $DEBUG "Product: $product" | ||
if [[ -d "$product" ]]; then | ||
log_message $DEBUG "Product is a directory" | ||
product_name=${product#./products/} | ||
log_message $DEBUG "Product name: $product_name" | ||
manifest="./products/$product_name/manifest.json" | ||
log_message $DEBUG "Manifest: $manifest" | ||
if [[ -f "$manifest" ]]; then | ||
log_message $DEBUG "Manifest is a file" | ||
validateAPIs=$(jq -r '.productMetadata.validateAPIs' "$manifest") | ||
if [[ "$validateAPIs" == "true" ]]; then | ||
log_message $INFO "Validating APIs for product: $product_name" | ||
contentMetadata=$(jq -c '.contentMetadata[] | select(.type | ascii_downcase == "apiurl")' "$manifest") | ||
echo "$contentMetadata" | jq -c '.' | while IFS= read -r contentMetadataItem; do | ||
slug=$(echo "$contentMetadataItem" | jq -r '.slug') | ||
log_message $INFO "Validating API: $slug" | ||
swaggerhub api:validate "${SWAGGERHUB_ORG_NAME}/$slug" --fail-on-critical | ||
done | ||
else | ||
log_message $WARNING "API validation is not enabled for product: $product_name" | ||
fi | ||
else | ||
log_message $ERROR "Manifest is not a file" | ||
fi | ||
else | ||
log_message $ERROR "Product is not a directory" | ||
fi | ||
done | ||
env: | ||
SWAGGERHUB_API_KEY: ${{ secrets.SWAGGERHUB_API_KEY }} | ||
SWAGGERHUB_ORG_NAME: ${{ vars.SWAGGERHUB_ORG_NAME }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"type": "object", | ||
"properties": { | ||
"productMetadata": { | ||
"type": "object", | ||
"properties": { | ||
"description": { | ||
"type": "string" | ||
}, | ||
"slug": { | ||
"type": "string" | ||
}, | ||
"public": { | ||
"type": "boolean" | ||
}, | ||
"hidden": { | ||
"type": "boolean" | ||
}, | ||
"logo": { | ||
"type": "string" | ||
}, | ||
"logoDark": { | ||
"type": "string" | ||
}, | ||
"autoPublish": { | ||
"type": "boolean" | ||
}, | ||
"validateAPIs": { | ||
"type": "boolean" | ||
} | ||
}, | ||
"required": [ | ||
"description", | ||
"slug", | ||
"public", | ||
"hidden", | ||
"logo", | ||
"autoPublish", | ||
"validateAPIs" | ||
] | ||
}, | ||
"contentMetadata": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"order": { | ||
"type": "integer" | ||
}, | ||
"parent": { | ||
"type": "string" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"slug": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"type": "string" | ||
}, | ||
"contentUrl": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"order", | ||
"name", | ||
"slug", | ||
"type", | ||
"contentUrl" | ||
] | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"productMetadata", | ||
"contentMetadata" | ||
] | ||
} |