Commit f25f4e2d authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '30019-warn-about-stale-graphql-docs' into 'master'

Add test for stale GraphQL docs to CI

Closes #30019

See merge request gitlab-org/gitlab!18549
parents 7f378abc 348ed9e2
...@@ -67,3 +67,18 @@ docs lint: ...@@ -67,3 +67,18 @@ docs lint:
- bundle exec nanoc check internal_links - bundle exec nanoc check internal_links
# Check the internal anchor links # Check the internal anchor links
- bundle exec nanoc check internal_anchors - bundle exec nanoc check internal_anchors
graphql-docs-verify:
extends:
- .default-tags
- .default-retry
- .default-cache
- .default-only
- .default-before_script
- .only-graphql-changes
variables:
SETUP_DB: "false"
stage: test
needs: ["setup-test-env"]
script:
- bundle exec rake gitlab:graphql:check_docs
...@@ -71,6 +71,12 @@ ...@@ -71,6 +71,12 @@
- "doc/**/*" - "doc/**/*"
- ".markdownlint.json" - ".markdownlint.json"
.only-graphql-changes:
only:
changes:
- "{,ee/}app/graphql/**/*"
- "{,ee/}lib/gitlab/graphql/**/*"
.only-code-qa-changes: .only-code-qa-changes:
only: only:
changes: changes:
......
This diff is collapsed.
...@@ -115,6 +115,7 @@ from a commit or MR by extending from the following CI definitions: ...@@ -115,6 +115,7 @@ from a commit or MR by extending from the following CI definitions:
- `.only-qa-changes`: Allows a job to only be created upon QA-related changes. - `.only-qa-changes`: Allows a job to only be created upon QA-related changes.
- `.only-docs-changes`: Allows a job to only be created upon docs-related changes. - `.only-docs-changes`: Allows a job to only be created upon docs-related changes.
- `.only-code-qa-changes`: Allows a job to only be created upon code-related or QA-related changes. - `.only-code-qa-changes`: Allows a job to only be created upon code-related or QA-related changes.
- `.only-graphql-changes`: Allows a job to only be created upon graphql-related changes.
**See <https://gitlab.com/gitlab-org/gitlab/blob/master/.gitlab/ci/global.gitlab-ci.yml> **See <https://gitlab.com/gitlab-org/gitlab/blob/master/.gitlab/ci/global.gitlab-ci.yml>
for the list of exact patterns.** for the list of exact patterns.**
...@@ -175,6 +176,7 @@ subgraph "`test` stage" ...@@ -175,6 +176,7 @@ subgraph "`test` stage"
db:* --> |needs| A; db:* --> |needs| A;
gitlab:setup --> |needs| A; gitlab:setup --> |needs| A;
downtime_check --> |needs and depends on| A; downtime_check --> |needs and depends on| A;
graphql-docs-verify --> |needs| A;
end end
subgraph "`review-prepare` stage" subgraph "`review-prepare` stage"
......
...@@ -23,15 +23,12 @@ module Gitlab ...@@ -23,15 +23,12 @@ module Gitlab
@parsed_schema = GraphQLDocs::Parser.new(schema, {}).parse @parsed_schema = GraphQLDocs::Parser.new(schema, {}).parse
end end
def render def contents
contents = @layout.render(self) # Render and remove an extra trailing new line
@contents ||= @layout.render(self).sub!(/\n(?=\Z)/, '')
write_file(contents)
end end
private def write
def write_file(contents)
filename = File.join(@output_dir, 'index.md') filename = File.join(@output_dir, 'index.md')
FileUtils.mkdir_p(@output_dir) FileUtils.mkdir_p(@output_dir)
......
...@@ -20,6 +20,3 @@ ...@@ -20,6 +20,3 @@
- type[:fields].each do |field| - type[:fields].each do |field|
= "| `#{field[:name]}` | #{render_field_type(field[:type][:info])} | #{field[:description]} |" = "| `#{field[:name]}` | #{render_field_type(field[:type][:info])} | #{field[:description]} |"
\ \
...@@ -11,10 +11,28 @@ namespace :gitlab do ...@@ -11,10 +11,28 @@ namespace :gitlab do
task compile_docs: :environment do task compile_docs: :environment do
renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema.graphql_definition, render_options) renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema.graphql_definition, render_options)
renderer.render renderer.write
puts "Documentation compiled." puts "Documentation compiled."
end end
desc 'GitLab | Check if GraphQL docs are up to date'
task check_docs: :environment do
renderer = Gitlab::Graphql::Docs::Renderer.new(GitlabSchema.graphql_definition, render_options)
doc = File.read(Rails.root.join(OUTPUT_DIR, 'index.md'))
if doc == renderer.contents
puts "GraphQL documentation is up to date"
else
puts '#' * 10
puts '#'
puts '# GraphQL documentation is outdated! Please update it by running `bundle exec rake gitlab:graphql:compile_docs`.'
puts '#'
puts '#' * 10
abort
end
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment