-
Notifications
You must be signed in to change notification settings - Fork 169
Add Ruby workflow for embedded ruby code #707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
96f6b52
Add standardrb and fix issues in embeded ruby file
aramprice 5cb8402
Introduce minimal spec for embedded ruby script
aramprice 3db29db
Add minimal spec for ERBRenderer#render
aramprice fc25fdc
ERBRenderer: ignore failures when ruby > v3.4
aramprice b387a21
Avoid `JSON.load_file`
aramprice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| name: Run Specs | ||
| on: [push, pull_request] | ||
|
|
||
| jobs: | ||
| test_embedded_ruby: | ||
| strategy: | ||
| matrix: | ||
| os: [ubuntu-latest, macos-latest] | ||
| ruby: [ '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4', head] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: ${{ matrix.ruby }} | ||
| - run: bundle install | ||
aramprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| working-directory: templatescompiler/erbrenderer/ | ||
| - run: bundle exec rake | ||
| working-directory: templatescompiler/erbrenderer/ | ||
| continue-on-error: ${{ matrix.ruby == 'head' }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Gemfile.lock |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| source "https://rubygems.org" | ||
|
|
||
| group :test do | ||
| gem "rake" | ||
| gem "rspec" | ||
| gem "standardrb" | ||
| end | ||
rkoster marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| require "rspec/core/rake_task" | ||
| require "standard/rake" | ||
|
|
||
| RSpec::Core::RakeTask.new(:spec) | ||
|
|
||
| task default: [:standard, :spec] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| require "spec_helper" | ||
| require "erb_renderer" | ||
|
|
||
| RSpec.describe "erb_renderer" do | ||
| describe "ERBRenderer" do | ||
| let(:test_tmpdir) { Dir.tmpdir } | ||
| let(:json_context_path) { File.join(test_tmpdir, "context.json") } | ||
|
|
||
aramprice marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| before do | ||
| File.write(json_context_path, context_hash.to_json) | ||
| end | ||
|
|
||
| after do | ||
| File.unlink(json_context_path) if File.exist?(json_context_path) | ||
| end | ||
|
|
||
| describe "#initialize" do | ||
| let(:context_hash) { {} } | ||
|
|
||
| it "does not raise an error" do | ||
| expect { ERBRenderer.new(json_context_path) }.not_to raise_error | ||
| end | ||
| end | ||
|
|
||
| describe "#render" do | ||
| let(:context_hash) do | ||
| { | ||
| index: 867_5309, | ||
| global_properties: { | ||
| property1: "global_value1" | ||
| }, | ||
| cluster_properties: { | ||
| property2: "cluster_value1" | ||
| }, | ||
| default_properties: { | ||
| property1: "default_value1", | ||
| property2: "default_value2", | ||
| property3: "default_value3" | ||
| } | ||
| } | ||
| end | ||
|
|
||
| let(:erb_template_path) { File.join(test_tmpdir, "template.yml.erb") } | ||
| let(:erb_content) do | ||
| <<~TEST_TEMPLATE | ||
| --- | ||
| property1: <%= p('property1') %> | ||
| property2: <%= p('property2') %> | ||
| property3: <%= p('property3') %> | ||
| TEST_TEMPLATE | ||
| end | ||
|
|
||
| let(:rendered_template_path) { File.join(test_tmpdir, "template.yml") } | ||
| let(:expected_template_content) do | ||
| <<~EXPECTED_TEMPLATE | ||
| --- | ||
| property1: global_value1 | ||
| property2: cluster_value1 | ||
| property3: default_value3 | ||
| EXPECTED_TEMPLATE | ||
| end | ||
|
|
||
| let(:erb_renderer) { ERBRenderer.new(json_context_path) } | ||
|
|
||
| before do | ||
| File.write(erb_template_path, erb_content) | ||
| end | ||
|
|
||
| it "does not raise an error" do | ||
| expect { erb_renderer.render(erb_template_path, rendered_template_path) }.not_to raise_error | ||
| end | ||
|
|
||
| it "renders the expected content" do | ||
| erb_renderer.render(erb_template_path, rendered_template_path) | ||
| expect(File.read(rendered_template_path)).to eq(expected_template_content) | ||
| end | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| require "rspec" | ||
| require "json" | ||
| require "tmpdir" | ||
|
|
||
| ERB_RENDERER_ROOT = File.expand_path("..", File.dirname(__FILE__)) | ||
|
|
||
| $LOAD_PATH.unshift(ERB_RENDERER_ROOT) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.