Skip to content

Commit

Permalink
Merge pull request #31 from razeware/development
Browse files Browse the repository at this point in the history
v1.0.4: 🐌 Shell
  • Loading branch information
sammyd authored Aug 9, 2020
2 parents 20bd8c1 + 6710956 commit 48441b3
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 16 deletions.
32 changes: 20 additions & 12 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,21 @@ jobs:
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Prefix tags with 'release'
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=release-$VERSION
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
TAGS=$(echo "${VERSION}" | sed -E "s/v?([0-9]+)\.([0-9]+)\.([0-9]+)/release-\1.\2.\3 release-\1.\2 release-\1/g")
fi
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
[ "$VERSION" == "development" ] && VERSION=staging
[ "$VERSION" == "master" ] && TAGS=latest
[ "$VERSION" == "development" ] && TAGS=staging
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo TAGS=$TAGS
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
for TAG in ${TAGS}; do
docker tag image "${IMAGE_ID}:${TAG}"
docker push "${IMAGE_ID}:${TAG}"
done
- name: Push image to GitHub
run: |
Expand All @@ -107,17 +111,21 @@ jobs:
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Prefix tags with 'release'
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=release-$VERSION
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then
TAGS=$(echo "${VERSION}" | sed -E "s/v?([0-9]+)\.([0-9]+)\.([0-9]+)/release-\1.\2.\3 release-\1.\2 release-\1/g")
fi
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
[ "$VERSION" == "development" ] && VERSION=staging
[ "$VERSION" == "master" ] && TAGS=latest
[ "$VERSION" == "development" ] && TAGS=staging
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
echo TAGS=$TAGS
docker tag image $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION
for TAG in ${TAGS}; do
docker tag image "${IMAGE_ID}:${TAG}"
docker push "${IMAGE_ID}:${TAG}"
done
- name: Logout of DockerHub Registry
if: ${{ always() }}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/linting/image/attachable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def lint_attachments
end
end

def locate_errors(image)
def locate_errors(_image)
[{
start_line: 1,
end_line: 1
Expand Down
25 changes: 23 additions & 2 deletions app/lib/linting/linter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def lint(options: {})
output
end

def lint_with_ui(options:, show_ui: true) # rubocop:disable Metrics/MethodLength
def lint_with_ui(options:, show_ui: true) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
with_spinner(title: 'Checking {{bold:publish.yaml}} exists', show: show_ui) do
check_publish_file_exists
end
Expand All @@ -31,6 +31,15 @@ def lint_with_ui(options:, show_ui: true) # rubocop:disable Metrics/MethodLength
end
return unless annotations.blank?

with_spinner(title: 'Attempting to parse book', show: show_ui) do
book
end
return unless annotations.blank?

with_spinner(title: 'Validating markdown', show: show_ui) do
annotations.concat(Linting::MarkdownLinter.new(book: book).lint)
end

with_spinner(title: 'Validating image references', show: show_ui) do
annotations.concat(Linting::ImageLinter.new(book: book).lint)
end
Expand Down Expand Up @@ -78,11 +87,23 @@ def check_publish_file_exists
false
end

def book
def book # rubocop:disable Metrics/MethodLength
@book ||= begin
parser = Parser::Publish.new(file: file)
parser.parse
end
rescue Parser::Error => e
line_number = (e.message.match(/at line (\d+)/)&.captures&.first&.to_i || 0) + 1
annotations.push(
Annotation.new(
absolute_path: e.file,
annotation_level: 'failure',
start_line: line_number,
end_line: line_number,
message: e.message,
title: 'Unable to parse book.'
)
)
end
end
end
23 changes: 23 additions & 0 deletions app/lib/linting/markdown/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Linting
module Markdown
# Lint the markdown associated with a book
class Book
include Linting::Markdown::Renderable

def self.lint(book)
new(book).lint
end

def lint
[].tap do |annotations|
annotations.concat(lint_markdown_attributes)
object.sections.each do |section|
annotations.concat(Linting::Markdown::Section.lint(section))
end
end
end
end
end
end
20 changes: 20 additions & 0 deletions app/lib/linting/markdown/chapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Linting
module Markdown
# Lint the markdown associated with a chapter
class Chapter
include Linting::Markdown::Renderable

def self.lint(chapter)
new(chapter).lint
end

def lint
[].tap do |annotations|
annotations.concat(lint_markdown_attributes)
end
end
end
end
end
25 changes: 25 additions & 0 deletions app/lib/linting/markdown/renderable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Linting
module Markdown
# Check that the attributes marked as markdown renderable are valid
module Renderable
include Linting::FileExistenceChecker

attr_reader :object

def initialize(object)
@object = object
end

def lint_markdown_attributes
object.markdown_render_loop do |content, is_file|
markdown = is_file ? File.read(content) : content
# TODO: Do some checking here
content
end
[]
end
end
end
end
23 changes: 23 additions & 0 deletions app/lib/linting/markdown/section.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

module Linting
module Markdown
# Lint the markdown associated with a section
class Section
include Linting::Markdown::Renderable

def self.lint(section)
new(section).lint
end

def lint
[].tap do |annotations|
annotations.concat(lint_markdown_attributes)
object.chapters.each do |chapter|
annotations.concat(Linting::Markdown::Chapter.lint(chapter))
end
end
end
end
end
end
16 changes: 16 additions & 0 deletions app/lib/linting/markdown_linter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module Linting
# Lints the markdown in a book
class MarkdownLinter
attr_reader :book

def initialize(book:)
@book = book
end

def lint
Linting::Markdown::Book.lint(book)
end
end
end
17 changes: 17 additions & 0 deletions app/lib/parser/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module Parser
# An error for capturing parsing issues
class Error < StandardError
attr_reader :file

def initialize(file:, error: nil, msg: nil)
message = "There was a problem parsing #{file}"
message += "\n#{error.class.name}\n#{error.message}" if error.present?
message += "\n#{msg}" if msg.present?

super(message)
@file = file
end
end
end
8 changes: 7 additions & 1 deletion app/lib/parser/markdown_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ def extract_metadata
end

def metadata
@metadata ||= Psych.load(extract_metadata).deep_symbolize_keys
@metadata ||= begin
Psych.load(extract_metadata, symbolize_names: true).tap do |metadata|
raise Parser::Error.new(file: path, msg: 'Unable to locate metadata at the top of the markdown') unless metadata.present?
end
end
rescue Psych::SyntaxError => e
raise Parser::Error.new(file: path, error: e)
end

def simple_attributes
Expand Down

0 comments on commit 48441b3

Please sign in to comment.