From 6ccb82d326d9c47e1e9414da765a6f9b80065733 Mon Sep 17 00:00:00 2001 From: Miguel Prada Date: Tue, 5 Nov 2019 15:31:31 -0500 Subject: [PATCH 1/7] updated readme file --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c3f5268..c6be208 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # Snake! This is a Ruby adapted version of the Snake classic game, using [Ruby2d](https://www.ruby2d.com) gem -[Imgur](https://i.imgur.com/wC6W4VH.png) + +![](https://i.imgur.com/wC6W4VH.png) # Requisites * Ruby - Version 2.x From 47341d506d25c8d10d1096e0634b57dca5ac0ece Mon Sep 17 00:00:00 2001 From: Miguel Prada Date: Sat, 15 Apr 2023 21:00:34 -0500 Subject: [PATCH 2/7] bundle gem --- .github/workflows/main.yml | 27 ++++++++++++ .gitignore | 13 ++++++ .rspec | 3 ++ .rubocop.yml | 41 ++++--------------- CHANGELOG.md | 5 +++ CODE_OF_CONDUCT.md | 84 ++++++++++++++++++++++++++++++++++++++ Gemfile | 9 ++-- Gemfile.lock | 18 -------- LICENSE.txt | 21 ++++++++++ README.md | 69 ++++++++++++++++--------------- Rakefile | 12 ++++++ bin/console | 15 +++++++ bin/setup | 8 ++++ lib/rb_snake.rb | 8 ++++ lib/rb_snake/version.rb | 5 +++ rb-snake.gemspec | 40 ++++++++++++++++++ sig/rb/snake.rbs | 6 +++ spec/rb/snake_spec.rb | 11 +++++ spec/spec_helper.rb | 15 +++++++ 19 files changed, 322 insertions(+), 88 deletions(-) create mode 100644 .github/workflows/main.yml create mode 100644 .gitignore create mode 100644 .rspec create mode 100644 CHANGELOG.md create mode 100644 CODE_OF_CONDUCT.md delete mode 100644 Gemfile.lock create mode 100644 LICENSE.txt create mode 100644 Rakefile create mode 100755 bin/console create mode 100755 bin/setup create mode 100644 lib/rb_snake.rb create mode 100644 lib/rb_snake/version.rb create mode 100644 rb-snake.gemspec create mode 100644 sig/rb/snake.rbs create mode 100644 spec/rb/snake_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..5884acf --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: Ruby + +on: + push: + branches: + - master + + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: + - '2.7.2' + + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run the default task + run: bundle exec rake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f2a372a --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ + +# rspec failure tracking +.rspec_status +Gemfile.lock +.ruby-version diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..34c5164 --- /dev/null +++ b/.rspec @@ -0,0 +1,3 @@ +--format documentation +--color +--require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml index c3fc013..e3462a7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,36 +1,13 @@ AllCops: - Exclude: - - "bin/*" - - "db/**/*" - - "config/**/*" - - "Guardfile" - - "Rakefile" - DisplayCopNames: true + TargetRubyVersion: 2.6 -Metrics/LineLength: - Max: 120 -Metrics/MethodLength: - Include: ["app/controllers/*"] - Max: 20 -Metrics/AbcSize: - Include: ["app/controllers/*"] - Max: 30 -Metrics/ClassLength: - Max: 150 -Metrics/BlockLength: - ExcludedMethods: ['describe'] - -Style/Documentation: - Enabled: false -Style/ClassAndModuleChildren: - Enabled: false +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes -Layout/AlignHash: - EnforcedColonStyle: key -Layout/ExtraSpacing: - AllowForAlignment: false -Layout/MultilineMethodCallIndentation: +Style/StringLiteralsInInterpolation: Enabled: true - EnforcedStyle: indented -Layout/EndOfLine: - EnforcedStyle: lf \ No newline at end of file + EnforcedStyle: double_quotes + +Layout/LineLength: + Max: 120 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e4e256e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## [Unreleased] + +## [0.1.0] - 2023-04-15 + +- Initial release diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..9a84f86 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,84 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mapra99@gmail.com. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, +available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. diff --git a/Gemfile b/Gemfile index 4772955..6fc972d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,6 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" -git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } - -gem 'byebug' -gem 'minitest' -gem 'ruby2d', '~> 0.9.2' +# Specify your gem's dependencies in rb-snake.gemspec +gemspec diff --git a/Gemfile.lock b/Gemfile.lock deleted file mode 100644 index 8c7a726..0000000 --- a/Gemfile.lock +++ /dev/null @@ -1,18 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - byebug (11.0.1) - minitest (5.13.0) - ruby2d (0.9.2) - -PLATFORMS - ruby - x64-mingw32 - -DEPENDENCIES - byebug - minitest - ruby2d (~> 0.9.2) - -BUNDLED WITH - 2.0.2 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..02faef5 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2023 Miguel Prada + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index c6be208..79d83f0 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,37 @@ -# Snake! - -This is a Ruby adapted version of the Snake classic game, using [Ruby2d](https://www.ruby2d.com) gem - -![](https://i.imgur.com/wC6W4VH.png) - -# Requisites -* Ruby - Version 2.x -* Bundler - Version 2.0.x - -# Dependencies -* [Ruby2d](https://www.ruby2d.com) - Version 0.9.x - -# Installation -1. Clone this project - ``` - git clone git@github.com:mapra99/rb-snake.git - ``` -2. Go to Project Folder and Install Dependencies - ``` - cd rb-snake - bundle install - ``` -3. Run the game - ``` - bundle exec ruby src/app.rb - ``` -# How To Play -Move the snake with your keyboard arrows, and try to eat as much food as possible. Avoid crashing against the window limits or against the snake's body. - -# Contributing -This project is 100% open source. If you like it, feel free to contribute :) \ No newline at end of file +# Rb::Snake + +Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rb/snake`. To experiment with that code, run `bin/console` for an interactive prompt. + +TODO: Delete this and the text above, and describe your gem + +## Installation + +Install the gem and add to the application's Gemfile by executing: + + $ bundle add rb-snake + +If bundler is not being used to manage dependencies, install the gem by executing: + + $ gem install rb-snake + +## Usage + +TODO: Write usage instructions here + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/rb-snake. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/rb-snake/blob/master/CODE_OF_CONDUCT.md). + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). + +## Code of Conduct + +Everyone interacting in the Rb::Snake project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/rb-snake/blob/master/CODE_OF_CONDUCT.md). diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..cca7175 --- /dev/null +++ b/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "rspec/core/rake_task" + +RSpec::Core::RakeTask.new(:spec) + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[spec rubocop] diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..6ba7f7c --- /dev/null +++ b/bin/console @@ -0,0 +1,15 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "rb/snake" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +# (If you use this, don't forget to add pry to your Gemfile!) +# require "pry" +# Pry.start + +require "irb" +IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/lib/rb_snake.rb b/lib/rb_snake.rb new file mode 100644 index 0000000..dac4854 --- /dev/null +++ b/lib/rb_snake.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require_relative "rb_snake/version" + +module RbSnake + class Error < StandardError; end + # Your code goes here... +end diff --git a/lib/rb_snake/version.rb b/lib/rb_snake/version.rb new file mode 100644 index 0000000..5feaa0e --- /dev/null +++ b/lib/rb_snake/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module RbSnake + VERSION = "0.1.0" +end diff --git a/rb-snake.gemspec b/rb-snake.gemspec new file mode 100644 index 0000000..41bf7a1 --- /dev/null +++ b/rb-snake.gemspec @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require_relative "lib/rb_snake/version" + +Gem::Specification.new do |spec| + spec.name = "rb-snake" + spec.version = RbSnake::VERSION + spec.authors = ["Miguel Prada"] + spec.email = ["mapra99@gmail.com"] + + spec.summary = "The classic snake game recreated using ruby" + spec.description = "The classic snake game recreated using ruby" + spec.homepage = "https://github.com/mapra99/rb-snake" + spec.license = "MIT" + spec.required_ruby_version = ">= 2.6.0" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(__dir__) do + `git ls-files -z`.split("\x0").reject do |f| + (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)}) + end + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] + + # Uncomment to register a new dependency of your gem + spec.add_dependency 'ruby2d', '~> 0.12.0' + + spec.add_development_dependency 'rake', '~> 13.0' + spec.add_development_dependency 'rspec', '~> 3.0' + spec.add_development_dependency 'rubocop', '~> 1.21' + + # For more information and examples about making a new gem, check out our + # guide at: https://bundler.io/guides/creating_gem.html +end diff --git a/sig/rb/snake.rbs b/sig/rb/snake.rbs new file mode 100644 index 0000000..60015c8 --- /dev/null +++ b/sig/rb/snake.rbs @@ -0,0 +1,6 @@ +module Rb + module Snake + VERSION: String + # See the writing guide of rbs: https://github.com/ruby/rbs#guides + end +end diff --git a/spec/rb/snake_spec.rb b/spec/rb/snake_spec.rb new file mode 100644 index 0000000..faca9f7 --- /dev/null +++ b/spec/rb/snake_spec.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +RSpec.describe Rb::Snake do + it "has a version number" do + expect(Rb::Snake::VERSION).not_to be nil + end + + it "does something useful" do + expect(false).to eq(true) + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..01770b7 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require "rb/snake" + +RSpec.configure do |config| + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end +end From f9f62082bd31821da4c3f8177446cdbf49854165 Mon Sep 17 00:00:00 2001 From: Miguel Prada Date: Sat, 15 Apr 2023 22:52:12 -0500 Subject: [PATCH 3/7] wip --- {src => lib/rb_snake}/actions/actions.rb | 0 {src => lib/rb_snake}/app.rb | 0 {src => lib/rb_snake}/model/state.rb | 0 {src => lib/rb_snake}/view/ruby2d.rb | 0 spec/{rb/snake_spec.rb => rb_snake_spec.rb} | 4 +- test/actions_test.rb | 86 --------------------- 6 files changed, 2 insertions(+), 88 deletions(-) rename {src => lib/rb_snake}/actions/actions.rb (100%) rename {src => lib/rb_snake}/app.rb (100%) rename {src => lib/rb_snake}/model/state.rb (100%) rename {src => lib/rb_snake}/view/ruby2d.rb (100%) rename spec/{rb/snake_spec.rb => rb_snake_spec.rb} (65%) delete mode 100644 test/actions_test.rb diff --git a/src/actions/actions.rb b/lib/rb_snake/actions/actions.rb similarity index 100% rename from src/actions/actions.rb rename to lib/rb_snake/actions/actions.rb diff --git a/src/app.rb b/lib/rb_snake/app.rb similarity index 100% rename from src/app.rb rename to lib/rb_snake/app.rb diff --git a/src/model/state.rb b/lib/rb_snake/model/state.rb similarity index 100% rename from src/model/state.rb rename to lib/rb_snake/model/state.rb diff --git a/src/view/ruby2d.rb b/lib/rb_snake/view/ruby2d.rb similarity index 100% rename from src/view/ruby2d.rb rename to lib/rb_snake/view/ruby2d.rb diff --git a/spec/rb/snake_spec.rb b/spec/rb_snake_spec.rb similarity index 65% rename from spec/rb/snake_spec.rb rename to spec/rb_snake_spec.rb index faca9f7..a3838a2 100644 --- a/spec/rb/snake_spec.rb +++ b/spec/rb_snake_spec.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -RSpec.describe Rb::Snake do +RSpec.describe RbSnake do it "has a version number" do - expect(Rb::Snake::VERSION).not_to be nil + expect(RbSnake::VERSION).not_to be nil end it "does something useful" do diff --git a/test/actions_test.rb b/test/actions_test.rb deleted file mode 100644 index a6d42b8..0000000 --- a/test/actions_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -# frozen_string_literal: true - -require 'minitest/autorun' -require 'minitest/mock' -require_relative '../src/actions/actions' -require_relative '../src/model/state' -require 'byebug' - -class ActionsTest < Minitest::Test - def setup - @initial_state = Model::State.new( - Model::Snake.new([Model::Coord.new(1, 1), - Model::Coord.new(0, 1)]), - Model::Food.new(4, 4), - Model::Grid.new(8, 12), - Model::Direction::DOWN, - false - ) - end - - def test_move_snake - expected_state = Model::State.new( - Model::Snake.new([Model::Coord.new(2, 1), - Model::Coord.new(1, 1)]), - Model::Food.new(4, 4), - Model::Grid.new(8, 12), - Model::Direction::DOWN, - false - ) - actual_state = Actions::move_snake(@initial_state) - assert_equal actual_state, expected_state - end - - def test_invalid_change_direction - expected_state = Model::State.new( - Model::Snake.new([Model::Coord.new(1, 1), - Model::Coord.new(0, 1)]), - Model::Food.new(4, 4), - Model::Grid.new(8, 12), - Model::Direction::DOWN, - false - ) - actual_state = Actions::change_direction(@initial_state, Model::Direction::UP) - assert_equal actual_state, expected_state - end - - def test_valid_change_direction - expected_state = Model::State.new( - Model::Snake.new([Model::Coord.new(1, 1), - Model::Coord.new(0, 1)]), - Model::Food.new(4, 4), - Model::Grid.new(8, 12), - Model::Direction::LEFT, - false - ) - actual_state = Actions::change_direction(@initial_state, Model::Direction::LEFT) - assert_equal actual_state, expected_state - end - - def test_snake_grow - @initial_state.food = Model::Food.new(2, 1) - - expected_state = Model::Snake.new([Model::Coord.new(2, 1), - Model::Coord.new(1, 1), - Model::Coord.new(0, 1)]) - actual_state = Actions::move_snake(@initial_state) - assert_equal actual_state.snake, expected_state - end - - def test_generate_food - @initial_state.food = Model::Food.new(2, 1) - expected_state = Model::State.new( - Model::Snake.new([Model::Coord.new(2, 1), - Model::Coord.new(1, 1)]), - Model::Food.new(0, 0), - Model::Grid.new(8, 12), - Model::Direction::DOWN, - false - ) - - Actions::stub(:rand, 0) do - actual_state = Actions::move_snake(@initial_state) - assert_equal actual_state.food, expected_state.food - end - end -end From c1f45e8a2dfc7078a750d644e835f8cd3eb5c1ee Mon Sep 17 00:00:00 2001 From: Miguel Prada Date: Sun, 16 Apr 2023 21:34:35 -0500 Subject: [PATCH 4/7] fix spec helper --- .github/workflows/gem_push.yml | 46 ++++++++++++++++++++++++++++++++++ .github/workflows/linter.yml | 19 ++++++++++++++ .github/workflows/main.yml | 27 -------------------- .github/workflows/tests.yml | 21 ++++++++++++++++ .rubocop.yml | 5 +++- rb-snake.gemspec | 1 + spec/rb_snake_spec.rb | 3 +-- spec/spec_helper.rb | 2 +- 8 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/gem_push.yml create mode 100644 .github/workflows/linter.yml delete mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/gem_push.yml b/.github/workflows/gem_push.yml new file mode 100644 index 0000000..1ff77bc --- /dev/null +++ b/.github/workflows/gem_push.yml @@ -0,0 +1,46 @@ +name: Ruby Gem + +on: + release: + types: [created] + +jobs: + build: + name: build + publish + runs-on: ubuntu-latest + permissions: + contents: write + packages: write + + steps: + - uses: actions/checkout@v3 + - name: set up ruby 3.1.x + uses: actions/setup-ruby@v1 + with: + ruby-version: 3.1.x + + - name: update version file + run: | + echo "# frozen_string_literal: true + + module RbSnake + VERSION = '${{ github.event.release.name }}' + end" > lib/rb_snake/version.rb + + - uses: stefanzweifel/git-auto-commit-action@v4 + name: auto commit action + with: + skip_fetch: false + branch: main + commit_message: Bump version to ${{ github.event.release.name }} + + - name: Publish to RubyGems + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push *.gem + env: + GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..30e27f9 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,19 @@ +name: Linter +on: [pull_request] +jobs: + rubocop: + runs-on: ubuntu-latest + steps: + - name: checkout repo + uses: actions/checkout@v1 + + - name: install ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1.2 + + - name: run rubocop + uses: reviewdog/action-rubocop@v2 + with: + rubocop_version: gemfile + rubocop_extensions: rubocop-rspec:gemfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 5884acf..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Ruby - -on: - push: - branches: - - master - - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - name: Ruby ${{ matrix.ruby }} - strategy: - matrix: - ruby: - - '2.7.2' - - steps: - - uses: actions/checkout@v3 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true - - name: Run the default task - run: bundle exec rake diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..86aa243 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,21 @@ +name: Tests +on: [pull_request] +jobs: + rspec: + runs-on: ubuntu-latest + + steps: + - name: checkout repo + uses: actions/checkout@v2 + + - name: install ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1.2 + + - name: bundle install + run: | + gem install bundler + bundle + - name: run rspec + run: rspec diff --git a/.rubocop.yml b/.rubocop.yml index e3462a7..30a3a16 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ +require: + - rubocop-rspec + AllCops: - TargetRubyVersion: 2.6 + TargetRubyVersion: 3.1.2 Style/StringLiterals: Enabled: true diff --git a/rb-snake.gemspec b/rb-snake.gemspec index 41bf7a1..cc846ef 100644 --- a/rb-snake.gemspec +++ b/rb-snake.gemspec @@ -34,6 +34,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency 'rake', '~> 13.0' spec.add_development_dependency 'rspec', '~> 3.0' spec.add_development_dependency 'rubocop', '~> 1.21' + spec.add_development_dependency 'rubocop-rspec', '~> 2.16.0' # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html diff --git a/spec/rb_snake_spec.rb b/spec/rb_snake_spec.rb index a3838a2..39e897c 100644 --- a/spec/rb_snake_spec.rb +++ b/spec/rb_snake_spec.rb @@ -5,7 +5,6 @@ expect(RbSnake::VERSION).not_to be nil end - it "does something useful" do - expect(false).to eq(true) + xit "does something useful" do end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 01770b7..2062a5d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "rb/snake" +require "rb_snake" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure From d8db9d1f0e22c54fae158f1df334c7940f7118c3 Mon Sep 17 00:00:00 2001 From: Miguel Prada Date: Sun, 16 Apr 2023 21:35:24 -0500 Subject: [PATCH 5/7] fix version --- lib/rb_snake/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rb_snake/version.rb b/lib/rb_snake/version.rb index 5feaa0e..e04f992 100644 --- a/lib/rb_snake/version.rb +++ b/lib/rb_snake/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RbSnake - VERSION = "0.1.0" + VERSION = "0.0.1" end From b483ece5cb44e049ac63e739370c79f32505e5c8 Mon Sep 17 00:00:00 2001 From: Miguel Prada Date: Sun, 16 Apr 2023 22:14:06 -0500 Subject: [PATCH 6/7] install system dependencies --- .github/workflows/gem_push.yml | 4 ++++ .github/workflows/tests.yml | 3 +++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/gem_push.yml b/.github/workflows/gem_push.yml index 1ff77bc..b479708 100644 --- a/.github/workflows/gem_push.yml +++ b/.github/workflows/gem_push.yml @@ -14,11 +14,15 @@ jobs: steps: - uses: actions/checkout@v3 + - name: set up ruby 3.1.x uses: actions/setup-ruby@v1 with: ruby-version: 3.1.x + - name: install system dependencies + run: sudo apt install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev + - name: update version file run: | echo "# frozen_string_literal: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 86aa243..a39c654 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,9 @@ jobs: with: ruby-version: 3.1.2 + - name: install system dependencies + run: sudo apt install -y libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev + - name: bundle install run: | gem install bundler From b0d91b40987c8a16bd909efc16ff3796dff741de Mon Sep 17 00:00:00 2001 From: Miguel Prada Date: Sun, 16 Apr 2023 22:41:55 -0500 Subject: [PATCH 7/7] fix rubocop issues --- .rubocop.yml | 2 +- rb-snake.gemspec | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 30a3a16..0d4420a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ require: - rubocop-rspec AllCops: - TargetRubyVersion: 3.1.2 + TargetRubyVersion: 2.6.0 Style/StringLiterals: Enabled: true diff --git a/rb-snake.gemspec b/rb-snake.gemspec index cc846ef..0700d49 100644 --- a/rb-snake.gemspec +++ b/rb-snake.gemspec @@ -29,12 +29,12 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] # Uncomment to register a new dependency of your gem - spec.add_dependency 'ruby2d', '~> 0.12.0' + spec.add_dependency "ruby2d", "~> 0.12.0" - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_development_dependency 'rubocop', '~> 1.21' - spec.add_development_dependency 'rubocop-rspec', '~> 2.16.0' + spec.add_development_dependency "rake", "~> 13.0" + spec.add_development_dependency "rspec", "~> 3.0" + spec.add_development_dependency "rubocop", "~> 1.21" + spec.add_development_dependency "rubocop-rspec", "~> 2.16.0" # For more information and examples about making a new gem, check out our # guide at: https://bundler.io/guides/creating_gem.html