Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAchilleas Pipinellis <axil@gitlab.com>2023-03-09 01:29:37 +0300
committerEvan Read <eread@gitlab.com>2023-03-09 01:29:37 +0300
commit16cbd61ffd8649c4960420341a7b21ab0cfc19de (patch)
tree9d13da94c8cb4bdf12e7c46abdf841ce9e7a8e86
parent23c3a8d8d9ee0d4aedde2515c9a60763c097be69 (diff)
Add test for navigation SCHEMA validation
-rw-r--r--.gitlab/ci/test.gitlab-ci.yml2
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock10
-rwxr-xr-xbin/json_schemer27
-rwxr-xr-xscripts/check-navigation.sh17
-rw-r--r--spec/lib/gitlab/navigation/navigation_schema.json78
6 files changed, 135 insertions, 0 deletions
diff --git a/.gitlab/ci/test.gitlab-ci.yml b/.gitlab/ci/test.gitlab-ci.yml
index dea9dcd8..3749162b 100644
--- a/.gitlab/ci/test.gitlab-ci.yml
+++ b/.gitlab/ci/test.gitlab-ci.yml
@@ -36,6 +36,7 @@ check_duplicate_redirects:
#
# - Identical duplicate entries.
# - index.html in the entries.
+# - Entries that don't conform to the schema.
#
check_global_nav_entries:
extends:
@@ -43,6 +44,7 @@ check_global_nav_entries:
needs: []
stage: test
script:
+ - bundle install
- make check-global-navigation
#
diff --git a/Gemfile b/Gemfile
index 16cd16cc..9ab4aed1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -28,6 +28,7 @@ group :test, :development do
gem 'pry-byebug', '~> 3.10.1', require: false
gem 'gitlab-styles', '~> 10.0.0', require: false
gem "webrick", "~> 1.8", ">= 1.8.1"
+ gem 'json_schemer', '~> 0.2', require: false
end
group :development, :danger do
diff --git a/Gemfile.lock b/Gemfile.lock
index c657de7c..72f88c86 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -57,6 +57,8 @@ GEM
debug_inspector (1.1.0)
diff-lcs (1.5.0)
docile (1.4.0)
+ ecma-re-validator (0.4.0)
+ regexp_parser (~> 2.2)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
@@ -91,6 +93,7 @@ GEM
rouge (~> 4.0.0)
hamster (3.0.0)
concurrent-ruby (~> 1.0)
+ hana (1.3.7)
highline (2.1.0)
http_parser.rb (0.8.0)
httparty (0.21.0)
@@ -100,6 +103,11 @@ GEM
concurrent-ruby (~> 1.0)
json (2.6.3)
json_schema (0.21.0)
+ json_schemer (0.2.24)
+ ecma-re-validator (~> 0.3)
+ hana (~> 1.3)
+ regexp_parser (~> 2.0)
+ uri_template (~> 0.7)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
@@ -277,6 +285,7 @@ GEM
unparser (0.6.7)
diff-lcs (~> 1.3)
parser (>= 3.2.0)
+ uri_template (0.7.0)
webrick (1.8.1)
zeitwerk (2.6.6)
@@ -289,6 +298,7 @@ DEPENDENCIES
gitlab-styles (~> 10.0.0)
gitlab_kramdown (~> 0.25.0)
highline (~> 2.1.0)
+ json_schemer (~> 0.2)
nanoc (~> 4.12.15)
nanoc-live
pry-byebug (~> 3.10.1)
diff --git a/bin/json_schemer b/bin/json_schemer
new file mode 100755
index 00000000..701e45ec
--- /dev/null
+++ b/bin/json_schemer
@@ -0,0 +1,27 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+#
+# This file was generated by Bundler.
+#
+# The application 'json_schemer' is installed as part of a gem, and
+# this file is here to facilitate running it.
+#
+
+ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
+
+bundle_binstub = File.expand_path("bundle", __dir__)
+
+if File.file?(bundle_binstub)
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
+ load(bundle_binstub)
+ else
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
+Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
+ end
+end
+
+require "rubygems"
+require "bundler/setup"
+
+load Gem.bin_path("json_schemer", "json_schemer")
diff --git a/scripts/check-navigation.sh b/scripts/check-navigation.sh
index 9274e576..5180fa0f 100755
--- a/scripts/check-navigation.sh
+++ b/scripts/check-navigation.sh
@@ -36,4 +36,21 @@ else
printf "${COLOR_GREEN}INFO: No entries with index.html found!${COLOR_RESET}\n"
fi
+# shellcheck disable=2059
+printf "${COLOR_GREEN}INFO: Checking global navigation against schema...${COLOR_RESET}\n"
+JSON_NAVIGATION=$(ruby -ryaml -rjson -e "puts YAML.load_file('content/_data/navigation.yaml').to_json")
+echo "$JSON_NAVIGATION" | bin/json_schemer spec/lib/gitlab/navigation/navigation_schema.json - > /dev/null
+RETURN_CODE="$?"
+if [[ $RETURN_CODE == 0 ]]; then
+ # shellcheck disable=2059
+ printf "${COLOR_GREEN}INFO: Global navigation matches schema!${COLOR_RESET}\n"
+else
+ # shellcheck disable=2059
+ printf "${COLOR_RED}ERROR: Global navigation doesn't match schema${COLOR_RESET}\n"
+ echo "$JSON_NAVIGATION" | bin/json_schemer spec/lib/gitlab/navigation/navigation_schema.json - > error.log
+ # shellcheck disable=2002
+ cat error.log | while IFS= read -r error; do echo "$error" | jq; done
+ RETURN_CODE=1
+fi
+
if [[ $RETURN_CODE == 1 ]]; then exit 1; else exit 0; fi
diff --git a/spec/lib/gitlab/navigation/navigation_schema.json b/spec/lib/gitlab/navigation/navigation_schema.json
new file mode 100644
index 00000000..186e9eea
--- /dev/null
+++ b/spec/lib/gitlab/navigation/navigation_schema.json
@@ -0,0 +1,78 @@
+{
+ "$schema": "http://json-schema.org/draft-07/schema#",
+ "description": "Global navigation for GitLab Docs",
+ "type": "object",
+ "properties": {
+ "sections": {
+ "description": "GitLab Docs site sections (first level)",
+ "type": "array",
+ "uniqueItems": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "section_title": {
+ "description": "GitLab Docs section (first level) title",
+ "type": "string"
+ },
+ "section_url": {
+ "description": "GitLab Docs section (first level) URL",
+ "type": "string"
+ },
+ "section_categories": {
+ "description": "GitLab Docs site categories (second level)",
+ "type": "array",
+ "uniqueItems": true,
+ "items": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {
+ "category_title": {
+ "description": "GitLab Docs category (second level) title",
+ "type": "string"
+ },
+ "category_url": {
+ "description": "GitLab Docs category (second level) URL",
+ "type": "string"
+ },
+ "docs": {
+ "$ref": "#/definitions/docs"
+ }
+ },
+ "required": ["category_title", "category_url"]
+ }
+ }
+ },
+ "required": ["section_title", "section_url"]
+ }
+ }
+ },
+ "required": ["sections"],
+ "definitions": {
+ "docs": {
+ "description": "GitLab Docs category documentation",
+ "type": "array",
+ "uniqueItems": true,
+ "items": {
+ "type": "object",
+ "properties": {
+ "doc_title": {
+ "description": "GitLab Docs documentation title",
+ "type": "string"
+ },
+ "doc_url": {
+ "description": "GitLab Docs documentation URL",
+ "type": "string"
+ },
+ "external_url": {
+ "description": "Link to a URL outside of GitLab docs",
+ "type": "boolean"
+ },
+ "docs": {
+ "$ref": "#/definitions/docs"
+ }
+ },
+ "required": ["doc_title", "doc_url"]
+ }
+ }
+ }
+}