summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-30 21:09:41 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-30 21:09:41 +0000
commit6377fb774cd6bf76ea235c9e07d88cdb014ee1ad (patch)
tree83c89564ed1a9c24c258f9bcc8b136fa6d57dfcb /scripts
parent6619ed911ffab93b90756bf392d2925fdc0c1ee2 (diff)
downloadgitlab-ce-6377fb774cd6bf76ea235c9e07d88cdb014ee1ad.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/glfm/run-snapshot-tests.sh6
-rw-r--r--scripts/lib/glfm/constants.rb8
-rw-r--r--scripts/lib/glfm/render_static_html.rb27
-rw-r--r--scripts/lib/glfm/update_example_snapshots.rb54
4 files changed, 47 insertions, 48 deletions
diff --git a/scripts/glfm/run-snapshot-tests.sh b/scripts/glfm/run-snapshot-tests.sh
index 59a7c8f06b0..6a66d8fbd9a 100755
--- a/scripts/glfm/run-snapshot-tests.sh
+++ b/scripts/glfm/run-snapshot-tests.sh
@@ -28,8 +28,12 @@ printf "\n${BBlue}Running frontend 'yarn jest spec/frontend/content_editor/markd
yarn jest spec/frontend/content_editor/markdown_snapshot_spec.js
printf "\n${BBlue}'yarn jest spec/frontend/content_editor/markdown_snapshot_spec.js' passed!${Color_Off}\n\n"
-printf "\n${BBlue}Running backend 'bundle exec rspec spec/requests/api/markdown_snapshot_spec.rb'...${Color_Off}\n\n"
+printf "\n${BBlue}Running CE backend 'bundle exec rspec spec/requests/api/markdown_snapshot_spec.rb'...${Color_Off}\n\n"
bundle exec rspec spec/requests/api/markdown_snapshot_spec.rb
printf "\n${BBlue}'bundle exec rspec spec/requests/api/markdown_snapshot_spec.rb' passed!${Color_Off}\n\n"
+printf "\n${BBlue}Running EE backend 'bundle exec rspec ee/spec/requests/api/markdown_snapshot_spec.rb'...${Color_Off}\n\n"
+bundle exec rspec ee/spec/requests/api/markdown_snapshot_spec.rb
+printf "\n${BBlue}'bundle exec rspec ee/spec/requests/api/markdown_snapshot_spec.rb' passed!${Color_Off}\n\n"
+
printf "\n✅✅✅ ${BGreen}All GLFM snapshot example tests passed successfully!${Color_Off} ✅✅✅\n"
diff --git a/scripts/lib/glfm/constants.rb b/scripts/lib/glfm/constants.rb
index 42977248c0d..e5790bbdd88 100644
--- a/scripts/lib/glfm/constants.rb
+++ b/scripts/lib/glfm/constants.rb
@@ -18,6 +18,9 @@ module Glfm
GLFM_INTRO_TXT_PATH = specification_input_glfm_path.join('glfm_intro.txt')
GLFM_EXAMPLES_TXT_PATH = specification_input_glfm_path.join('glfm_canonical_examples.txt')
GLFM_EXAMPLE_STATUS_YML_PATH = specification_input_glfm_path.join('glfm_example_status.yml')
+ GLFM_EXAMPLE_METADATA_YML_PATH =
+ specification_input_glfm_path.join('glfm_example_metadata.yml')
+ GLFM_EXAMPLE_NORMALIZATIONS_YML_PATH = specification_input_glfm_path.join('glfm_example_normalizations.yml')
GLFM_SPEC_TXT_PATH = specification_path.join('output/spec.txt')
# Example Snapshot (ES) files
@@ -28,15 +31,16 @@ module Glfm
ES_PROSEMIRROR_JSON_YML_PATH = File.join(es_fixtures_path, 'prosemirror_json.yml')
# Other constants used for processing files
- GLFM_SPEC_TXT_HEADER = <<~GLFM_SPEC_TXT_HEADER
+ GLFM_SPEC_TXT_HEADER = <<~MARKDOWN
---
title: GitLab Flavored Markdown (GLFM) Spec
version: alpha
...
- GLFM_SPEC_TXT_HEADER
+ MARKDOWN
INTRODUCTION_HEADER_LINE_TEXT = /\A# Introduction\Z/.freeze
END_TESTS_COMMENT_LINE_TEXT = /\A<!-- END TESTS -->\Z/.freeze
MARKDOWN_TEMPFILE_BASENAME = %w[MARKDOWN_TEMPFILE_ .yml].freeze
+ METADATA_TEMPFILE_BASENAME = %w[METADATA_TEMPFILE_ .yml].freeze
STATIC_HTML_TEMPFILE_BASENAME = %w[STATIC_HTML_TEMPFILE_ .yml].freeze
WYSIWYG_HTML_AND_JSON_TEMPFILE_BASENAME = %w[WYSIWYG_HTML_AND_JSON_TEMPFILE_ .yml].freeze
end
diff --git a/scripts/lib/glfm/render_static_html.rb b/scripts/lib/glfm/render_static_html.rb
index 25abc75e270..8d72aec7c3b 100644
--- a/scripts/lib/glfm/render_static_html.rb
+++ b/scripts/lib/glfm/render_static_html.rb
@@ -29,34 +29,19 @@ RSpec.describe 'Render Static HTML', :api, type: :request do # rubocop:disable R
include Glfm::Constants
include Glfm::Shared
- # TODO: Remove duplication of fixtures & logic with spec/support/shared_contexts/markdown_snapshot_shared_examples.rb
-
- let_it_be(:user) { create(:user) }
- let_it_be(:group) { create(:group, name: 'glfm_group').tap { |group| group.add_owner(user) } }
-
- let_it_be(:project) do
- # NOTE: We hardcode the IDs on all fixtures to prevent variability in the
- # rendered HTML/Prosemirror JSON, and to minimize the need for normalization:
- # https://docs.gitlab.com/ee/development/gitlab_flavored_markdown/specification_guide/#normalization
- create(:project, :repository, creator: user, group: group, name: 'glfm_project', id: 77777)
- end
-
- let_it_be(:project_snippet) { create(:project_snippet, id: 88888, project: project) }
- let_it_be(:personal_snippet) { create(:snippet, id: 99999) }
-
- before do
- stub_licensed_features(group_wikis: true)
- sign_in(user)
- end
+ # noinspection RailsParamDefResolve (RubyMine can't find the shared context from this file location)
+ include_context 'with GLFM example snapshot fixtures'
it 'can create a project dependency graph using factories' do
markdown_hash = YAML.safe_load(File.open(ENV.fetch('INPUT_MARKDOWN_YML_PATH')), symbolize_names: true)
+ metadata_hash = YAML.safe_load(File.open(ENV.fetch('INPUT_METADATA_YML_PATH')), symbolize_names: true)
# NOTE: We cannot parallelize this loop like the Javascript WYSIWYG example generation does,
# because the rspec `post` API cannot be parallized (it is not thread-safe, it can't find
# the controller).
- static_html_hash = markdown_hash.transform_values do |markdown|
- api_url = api "/markdown"
+ static_html_hash = markdown_hash.transform_values.with_index do |markdown, index|
+ name = markdown_hash.keys[index]
+ api_url = metadata_hash.dig(name, :api_request_override_path) || (api "/markdown")
post api_url, params: { text: markdown, gfm: true }
# noinspection RubyResolve
diff --git a/scripts/lib/glfm/update_example_snapshots.rb b/scripts/lib/glfm/update_example_snapshots.rb
index 6ff063c1690..7dc0d0f7c4b 100644
--- a/scripts/lib/glfm/update_example_snapshots.rb
+++ b/scripts/lib/glfm/update_example_snapshots.rb
@@ -29,8 +29,6 @@ module Glfm
def process(skip_static_and_wysiwyg: false)
output('Updating example snapshots...')
- setup_environment
-
output('(Skipping static HTML generation)') if skip_static_and_wysiwyg
output("Reading #{GLFM_SPEC_TXT_PATH}...")
@@ -49,14 +47,6 @@ module Glfm
private
- def setup_environment
- # Set 'GITLAB_TEST_FOOTNOTE_ID' in order to override random number generation in
- # Banzai::Filter::FootnoteFilter#random_number, and thus avoid the need to
- # perform normalization on the value. See:
- # https://docs.gitlab.com/ee/development/gitlab_flavored_markdown/specification_guide/#normalization
- ENV['GITLAB_TEST_FOOTNOTE_ID'] = '42'
- end
-
def add_example_names(all_examples)
# NOTE: This method and the parse_examples method assume:
# 1. Section 2 is the first section which contains examples
@@ -137,11 +127,11 @@ module Glfm
return
end
- # NOTE: We pass the INPUT_MARKDOWN_YML_PATH via
- # environment variable to the static/wysiwyg HTML generation scripts. This is because it
- # is implemented as a subprocess which invokes rspec/jest scripts, and rspec/jest do not make
+ # NOTE: We pass the INPUT_MARKDOWN_YML_PATH and INPUT_METADATA_YML_PATH via
+ # environment variables to the static/wysiwyg HTML generation scripts. This is because they
+ # are implemented as subprocesses which invoke rspec/jest scripts, and rspec/jest do not make
# it straightforward to pass arguments via the command line.
- ENV['INPUT_MARKDOWN_YML_PATH'] = copy_tempfiles_for_subprocesses
+ ENV['INPUT_MARKDOWN_YML_PATH'], ENV['INPUT_METADATA_YML_PATH'] = copy_tempfiles_for_subprocesses
static_html_hash = generate_static_html
wysiwyg_html_and_json_hash = generate_wysiwyg_html_and_json
@@ -168,18 +158,31 @@ module Glfm
name = example.fetch(:name).to_sym
hash[name] = {
'spec_txt_example_position' => example.fetch(:example),
- 'source_specification' =>
- if example[:extensions].empty?
- 'commonmark'
- elsif example[:extensions].include?('gitlab')
- 'gitlab'
- else
- 'github'
- end
+ 'source_specification' => source_specification_for_extensions(example.fetch(:extensions))
}
end
end
+ def source_specification_for_extensions(extensions)
+ unprocessed_extensions = extensions.map(&:to_sym)
+ unprocessed_extensions.delete(:disabled)
+
+ source_specification =
+ if unprocessed_extensions.empty?
+ 'commonmark'
+ elsif unprocessed_extensions.include?(:gitlab)
+ unprocessed_extensions.delete(:gitlab)
+ 'gitlab'
+ else
+ 'github'
+ end
+
+ # We should only be left with at most one extension, which is an optional name for the example
+ raise "Error: Invalid extension(s) found: #{unprocessed_extensions.join(', ')}" if unprocessed_extensions.size > 1
+
+ source_specification
+ end
+
def write_markdown_yml(all_examples)
generate_and_write_for_all_examples(all_examples, ES_MARKDOWN_YML_PATH) do |example, hash|
name = example.fetch(:name).to_sym
@@ -193,14 +196,17 @@ module Glfm
# the scripts to read them, because the scripts are run in
# separate subprocesses, and during unit testing we are unable to substitute the mock
# StringIO when reading the input files in the subprocess.
- { ES_MARKDOWN_YML_PATH => MARKDOWN_TEMPFILE_BASENAME }.map do |original_file_path, tempfile_basename|
+ {
+ ES_MARKDOWN_YML_PATH => MARKDOWN_TEMPFILE_BASENAME,
+ GLFM_EXAMPLE_METADATA_YML_PATH => METADATA_TEMPFILE_BASENAME
+ }.map do |original_file_path, tempfile_basename|
Dir::Tmpname.create(tempfile_basename) do |path|
io = File.open(original_file_path)
io.seek(0) # rewind the file. This is necessary when testing with a mock StringIO
contents = io.read
write_file(path, contents)
end
- end.first
+ end
end
def generate_static_html