Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub workflow qa #160

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Freifunk-QA

on: [push]

jobs:
schemaValidation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Lint all shell scripts
run: ./pipeline/lintShellScripts.sh

- name: Extract `draft-03` schema (from "empty schema)
run: ./pipeline/extractJsonSchema.sh
env:
SOURCE_PATTERN: "./specs/*.json"

- name: Validate `draft-03` schema (extracted schema)
uses: docker://freifunkhamm/jsonschema:3.2.0
with:
entrypoint: /bin/sh
args: ./pipeline/validateJsonSchema.sh
env:
DRAFT: "draft-03"
SOURCE_PATTERN: "./specs_clean/*.json"

- name: Validate `draft-03` schema
uses: docker://freifunkhamm/jsonschema:3.2.0
with:
entrypoint: /bin/sh
args: ./pipeline/validateJsonSchema.sh
env:
DRAFT: "draft-03"
SOURCE_PATTERN: "./specs/draft-03/*.json"

- name: Validate `draft-04` schema
uses: docker://freifunkhamm/jsonschema:3.2.0
with:
entrypoint: /bin/sh
args: ./pipeline/validateJsonSchema.sh
env:
DRAFT: "draft-04"
SOURCE_PATTERN: "./specs/draft-04/*.json"

- name: Validate `draft-06` schema
uses: docker://freifunkhamm/jsonschema:3.2.0
with:
entrypoint: /bin/sh
args: ./pipeline/validateJsonSchema.sh
env:
DRAFT: "draft-06"
SOURCE_PATTERN: "./specs/draft-06/*.json"

- name: Validate `draft-07` schema
uses: docker://freifunkhamm/jsonschema:3.2.0
with:
entrypoint: /bin/sh
args: ./pipeline/validateJsonSchema.sh
env:
DRAFT: "draft-07"
SOURCE_PATTERN: "./specs/draft-07/*.json"
26 changes: 26 additions & 0 deletions pipeline/extractJsonSchema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

if [ -z "$SOURCE_PATTERN" ]; then
echo "Please define SOURCE_PATTERN environment variable"
exit 1
fi

if [ ! -d "$(dirname "$SOURCE_PATTERN")" ]; then
echo "Directory $(dirname "$SOURCE_PATTERN") do not exists!"
exit 1
fi

echo "Validating schema files for pattern: $SOURCE_PATTERN"

mkdir -p specs_clean/

for filename in $SOURCE_PATTERN; do

# extract "freifunk schema" from "emtpy schema"
# shellcheck disable=SC2094
jq '.schema' < "$filename" > "specs_clean/$(basename "$filename")"
filename="specs_clean/$(basename "$filename")"
echo "Extracted schema saved in: $filename"

done

8 changes: 8 additions & 0 deletions pipeline/lintShellScripts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

for filename in **/*.sh; do
echo "Linted shell scripts: $filename"
shellcheck "$filename"
done

56 changes: 56 additions & 0 deletions pipeline/validateJsonSchema.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

if [ -z "$SOURCE_PATTERN" ]; then
echo "Please define SOURCE_PATTERN environment variable"
exit 1
fi

if [ ! -d "$(dirname "$SOURCE_PATTERN")" ]; then
echo "Directory $(dirname "$SOURCE_PATTERN") do not exists!"
exit 1
fi

echo "Validating schema files for pattern: $SOURCE_PATTERN"

case $DRAFT in
draft-03)
VALIDATOR="Draft3Validator"
;;
draft-04)
VALIDATOR="Draft4Validator"
;;
draft-06)
VALIDATOR="Draft6Validator"
;;
draft-07)
VALIDATOR="Draft7Validator"
;;
*)
echo "Please define DRAFT environment variable. Supported values: draft-03, draft-04, draft-06, draft-07"
exit 1
;;
esac

echo "Draft: $DRAFT"
echo "Validator = $VALIDATOR"

PROBLEM=false

mkdir -p specs_clean/

for filename in $SOURCE_PATTERN; do
VALIDATIONERROR=""
VALIDATIONERROR=$(jsonschema --validator $VALIDATOR "$filename" 2>&1)
EXITCODE=$?
if [ $EXITCODE -eq 0 ]; then
echo "OK $filename"
else
echo "ERROR $filename $VALIDATIONERROR"
PROBLEM=true
fi
done

if [ $PROBLEM = true ]; then
echo "VALIDATION FAILED!"
exit 1
fi
20 changes: 20 additions & 0 deletions specs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# WARNING: draft-03 is DEPRECATED
JSON meta schema draft-03 has been deprecated by json-schema.org please migrate to a newer draft version as soon as
possible.

# Why files in this folder are bad (draft-03 with wrapper)
Files in <repo>/specs/*.json are, so called, "empty schema" files, where typical schema elements are missing
at root level of that JSON. Instead, these typical elements are below the "schema" key
(which is NOT an offical schema element). This key acts as a "wrapper". If you want to validate a JSON instance file
against these schema files, then you need to extract the JSON schema from "schema" key. If you do not extract, then
your JSON Instance will be evaluated against an "empty schema". Every possible JSON Instance would be valid against
these "empty schema" files, rendering the validation process useless.

# Update your implementation
As draft-03 is deprecated you should no longer use it. Update your implementation to use e.g. draft-07. You may update
to a newer library version or to other lib, validator, form UI vendors that support draft-07 schema files. See [draft-07](draft-07)

# If you are not able to migrate now
If you can not change your implementation to use a lib/validator/formUI that supports draft-07, then you should at
least switch to the files in <repo>/specs/draft-03/ which are true schema files (no wrapper / no "empty schema").
If your code did "schema"-key-extraction then change your code and access schema directly at root level.
Loading