Skip to content
Draft
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
47 changes: 47 additions & 0 deletions .github/workflows/_test-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CLI Test

on:
workflow_call:
workflow_dispatch:

env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}

jobs:
test:
name: Run Tests
timeout-minutes: 30
strategy:
max-parallel: 4
matrix:
os_config:
- os: "ubuntu-24.04"
rid: "linux-x64"
- os: "macos-latest"
rid: "osx-x64"
- os: "windows-latest"
rid: "win-x64"
ruby:
- "3.0"
- "4.0"
runs-on: ${{ matrix.os_config.os }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Tests V2 CLI
run: |
./spec/test_v2_cli.sh ./spec/data/file_types/pdf/blank_1.pdf ${{ matrix.os_config.rid }}

- name: Tests V1 CLI
run: |
./spec/test_v1_cli.sh ./spec/data/file_types/pdf/blank_1.pdf ${{ matrix.os_config.rid }}
24 changes: 13 additions & 11 deletions .github/workflows/_test-integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ on:
workflow_call:
workflow_dispatch:

env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_LOG_LEVEL: DEBUG

jobs:
integration-tests:
name: Run Integration Tests
Expand Down Expand Up @@ -50,17 +63,6 @@ jobs:
sudo sed -i "s/$SRC/$RPL/" /etc/ImageMagick-6/policy.xml

- name: Run Rspec for integration tests
env:
MINDEE_API_KEY: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
WORKFLOW_ID: ${{ secrets.WORKFLOW_ID_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_LOG_LEVEL: DEBUG
run: |
bundle exec rake integration

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Test Code Samples
name: Smoke Test

on:
workflow_call:
Expand All @@ -9,12 +9,13 @@ env:
MINDEE_ACCOUNT_SE_TESTS: ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }}
MINDEE_API_KEY_SE_TESTS: ${{ secrets.MINDEE_API_KEY_SE_TESTS }}
MINDEE_V2_API_KEY: ${{ secrets.MINDEE_V2_SE_TESTS_API_KEY }}
MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID }}
MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_SE_TESTS_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_SE_TESTS_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}
MINDEE_V2_FINDOC_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FINDOC_MODEL_ID }}
MINDEE_V2_SE_TESTS_BLANK_PDF_URL: ${{ secrets.MINDEE_V2_SE_TESTS_BLANK_PDF_URL }}
MINDEE_V2_CLASSIFICATION_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CLASSIFICATION_MODEL_ID }}
MINDEE_V2_CROP_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_CROP_MODEL_ID }}
MINDEE_V2_FAILURE_WEBHOOK_ID: ${{ secrets.MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID }}
MINDEE_V2_OCR_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_OCR_MODEL_ID }}
MINDEE_V2_SPLIT_MODEL_ID: ${{ secrets.MINDEE_V2_SE_TESTS_SPLIT_MODEL_ID }}

jobs:
test:
Expand All @@ -40,14 +41,15 @@ jobs:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Tests V1 code samples
- name: Tests V2 code samples
env:
MINDEE_LOG_LEVEL: DEBUG
run: |
./spec/test_code_samples_v1.sh
./spec/test_v2_code_samples.sh

- name: Tests V2 code samples
- name: Tests V1 code samples
env:
MINDEE_LOG_LEVEL: DEBUG
run: |
./spec/test_code_samples_v2.sh
./spec/test_v1_code_samples.sh ${{ secrets.MINDEE_ACCOUNT_SE_TESTS }} ${{ secrets.MINDEE_ENDPOINT_SE_TESTS }}

7 changes: 5 additions & 2 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
- cron: '0 0 * * *'

jobs:
test_code_samples:
uses: mindee/mindee-api-ruby/.github/workflows/_test-code-samples.yml@main
test-smoke:
uses: mindee/mindee-api-ruby/.github/workflows/_test-smoke.yml@main
secrets: inherit
test-cli:
uses: mindee/mindee-api-ruby/.github/workflows/_test-cli.yml@main
secrets: inherit
8 changes: 4 additions & 4 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ on:
types: [ published ]

jobs:
publish_docs:
publish-docs:
uses: mindee/mindee-api-ruby/.github/workflows/_publish-docs.yml@main
secrets: inherit
publish_guide:
publish-guide:
uses: mindee/mindee-api-ruby/.github/workflows/_publish-guide.yml@main
needs: publish_docs
needs: publish-docs
secrets: inherit
publish_code:
publish-code:
uses: mindee/mindee-api-ruby/.github/workflows/_publish-code.yml@main
secrets: inherit
20 changes: 12 additions & 8 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ permissions:
pull-requests: read

jobs:
static_analysis:
static-analysis:
uses: ./.github/workflows/_static-analysis.yml
test_units:
test-units:
uses: ./.github/workflows/_test-units.yml
needs: static_analysis
needs: static-analysis
secrets: inherit
test_integrations:
test-integrations:
uses: ./.github/workflows/_test-integrations.yml
needs: test_units
needs: test-units
secrets: inherit
test_code_samples:
uses: ./.github/workflows/_test-code-samples.yml
needs: test_units
test-smoke:
uses: ./.github/workflows/_test-smoke.yml
needs: test-units
secrets: inherit
test-cli:
uses: ./.github/workflows/_test-cli.yml
needs: test-units
secrets: inherit
8 changes: 4 additions & 4 deletions .github/workflows/push-main-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:
- main

jobs:
static_analysis:
static-analysis:
uses: mindee/mindee-api-ruby/.github/workflows/_static-analysis.yml@main
test_units:
test-units:
uses: mindee/mindee-api-ruby/.github/workflows/_test-units.yml@main
needs: static_analysis
needs: static-analysis
secrets: inherit
tag:
uses: mindee/client-lib-actions/.github/workflows/tag-version.yml@main
needs: test_units
needs: test-units
release:
uses: mindee/client-lib-actions/.github/workflows/create-release.yml@main
needs: tag
Expand Down
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Metrics/MethodLength:

Metrics/ClassLength:
Max: 200

Metrics/ModuleLength:
Max: 200
Metrics/ParameterLists:
Max: 8

Expand Down
137 changes: 19 additions & 118 deletions bin/mindee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,127 +3,28 @@

require 'bundler/setup'
require 'optparse'
require 'mindee'

require_relative 'cli_products'

options = {}

# Initializes universal-specific options
# @param cli_parser [OptionParser]
def custom_subcommand(cli_parser, options)
cli_parser.on('-v [VERSION]', '--version [VERSION]', 'Model version for the API') do |v|
options[:endpoint_version] = v
end
cli_parser.on('-a ACCOUNT_NAME', '--account ACCOUNT_NAME', 'API account name for the endpoint') do |v|
options[:account_name] = v
end
end

product_parser = {}
PRODUCTS.each do |doc_key, doc_value|
product_parser[doc_key] = OptionParser.new do |opts|
opts.on('-w', '--all-words', 'Include words in response') do |v|
options[:all_words] = v
end
opts.on('-c', '--cut-pages', "Cut document pages") do |v|
options[:cut_pages] = v
end
opts.on('-k [KEY]', '--key [KEY]', 'API key for the endpoint') do |v|
options[:api_key] = v
end
opts.on('-f', '--full', "Print the full data, including pages") do |v|
options[:print_full] = true
end
opts.on('-F', '--fix-pdf', "Attempts to fix broken PDF files before sending them to the server.") do |v|
options[:repair_pdf] = true
end
if doc_key != 'universal'
opts.banner = "#{doc_value[:description]}. \nUsage: \nmindee.rb universal [options] endpoint_name file\nor\nmindee.rb universal [options] endpoint_name file"
custom_subcommand(opts, options)
end
if doc_value[:async]
if doc_value[:sync]
opts.on("-A", "--async", "Call asynchronously") do |v|
options[:parse_async] = v
end
end
end
require_relative 'v1/parser'
require_relative 'v2/parser'

def setup_main_parser
v1_parser = MindeeCLI::V1Parser.new(ARGV)
v2_parser = MindeeCLI::V2Parser.new(ARGV)
main_parser = OptionParser.new do |opts|
opts.banner = "Usage: mindee [command]"
opts.separator "Commands:"
opts.separator " v1 Use Version 1 of the Mindee API"
opts.separator " v2 Use Version 2 of the Mindee API"
end
end

global_parser = OptionParser.new do |opts|
opts.banner = "Usage: mindee.rb product [options] file"
opts.separator "Available products:"
opts.separator " #{PRODUCTS.keys.join("\n ")}"
end

command = ARGV.shift
unless PRODUCTS.include?(command)
abort(global_parser.help)
end
doc_class = PRODUCTS[command][:doc_class]
product_parser[command].parse!
main_command = ARGV.shift

if command == 'universal'
if ARGV.length < 2
$stderr.puts "The '#{command}' command requires both ENDPOINT_NAME and file arguments."
abort(product_parser[command].help)
end
endpoint_name = ARGV[0]
options[:file_path] = ARGV[1]
else
if ARGV.length < 1
$stderr.puts "file missing"
abort(product_parser[command].help)
end
endpoint_name = nil
options[:file_path] = ARGV[0]
end

mindee_client = Mindee::Client.new(api_key: options[:api_key])
if options[:file_path].start_with?("https://")
input_source = mindee_client.source_from_url(options[:file_path])
else
input_source = mindee_client.source_from_path(options[:file_path], repair_pdf: options[:repair_pdf])
end

if command == 'universal'
custom_endpoint = mindee_client.create_endpoint(
endpoint_name: endpoint_name,
account_name: options[:account_name],
version: options[:endpoint_version].nil? ? "1" : options[:endpoint_version]
)
else
custom_endpoint = nil
end

if options[:cut_pages].nil? || !options[:cut_pages].is_a?(Integer) || options[:cut_pages] < 0
page_options = nil
else
page_options = Mindee::PageOptions.new(params: {
page_indexes: (0..options[:cut_pages].to_i).to_a,
operation: :KEEP_ONLY,
on_min_pages: 0,
})
end

if options[:parse_async].nil?
if !PRODUCTS[command][:sync]
options[:parse_async] = true
case main_command
when 'v1'
v1_parser.execute
when 'v2'
v2_parser.execute
else
options[:parse_async] = false
abort(main_parser.help)
end
end
result = mindee_client.parse(
input_source,
doc_class,
options: { endpoint: custom_endpoint,
options: Mindee::ParseOptions.new(params: { page_options: page_options }), enqueue: options[:parse_async] }
)

if options[:print_full]
puts result.document
else
puts result.document.inference.prediction
end
setup_main_parser
Loading
Loading