Skip to content

shared action improvements #3

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 5 commits into from
Dec 16, 2024
Merged
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
13 changes: 8 additions & 5 deletions .github/shared/setup/action.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: "setup ruby"
description: "setup ruby"

name: setup ruby
description: setup ruby
inputs:
working-directory:
description: directory to use
required: true
runs:
using: "composite"
using: composite
steps:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
working-directory: ./2024/ruby
working-directory: ${{ inputs.working-directory }}
33 changes: 19 additions & 14 deletions .github/workflows/2021-ruby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ defaults:
working-directory: ./2021/ruby

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: debug
run: pwd
- name: Setup Ruby
uses: ./.github/shared/setup
with:
working-directory: ./2021/ruby
- name: Run rubocop
run: bundle exec rubocop
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Determine ruby version
id: determine-ruby-version
run: |
VERSION=$(cat .ruby-version)
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ steps.determine-ruby-version.outputs.VERSION }}
bundler-cache: true
working-directory: ./2021/ruby
- name: Run tests
run: bundle exec rspec
- uses: actions/checkout@v3
- name: Setup Ruby
uses: ./.github/shared/setup
with:
working-directory: ./2021/ruby
- name: Run tests
run: bundle exec rspec
4 changes: 4 additions & 0 deletions .github/workflows/2024-ruby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Ruby
uses: ./.github/shared/setup
with:
working-directory: ./2024/ruby
- name: Run rubocop
run: bundle exec rubocop
tests:
Expand All @@ -25,5 +27,7 @@ jobs:
- uses: actions/checkout@v3
- name: Setup Ruby
uses: ./.github/shared/setup
with:
working-directory: ./2024/ruby
- name: Run tests
run: bundle exec rspec
11 changes: 10 additions & 1 deletion 2021/ruby/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require:
- rubocop-rspec
- rubocop-rake

AllCops:
Exclude:
- bin/**/*
Expand All @@ -8,13 +12,18 @@ Style/Documentation:
Style/FrozenStringLiteralComment:
Enabled: false
Style/StringLiterals:
Enabled: false
Enabled: true
EnforcedStyle: double_quotes
Style/TrailingCommaInHashLiteral:
Enabled: false
Style/NumericPredicate:
Enabled: false
Metrics/BlockLength:
Exclude:
- spec/**/*
RSpec/ExampleLength:
Max: 20
RSpec/MultipleExpectations:
Enabled: false

inherit_from: .rubocop_todo.yml
19 changes: 19 additions & 0 deletions 2021/ruby/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-12-16 16:59:11 UTC using RuboCop version 1.69.2.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
RSpec/MultipleDescribes:
Exclude:
- 'spec/advent_02_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 122
2 changes: 1 addition & 1 deletion 2021/ruby/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.2
3.3.6
14 changes: 8 additions & 6 deletions 2021/ruby/Gemfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

ruby File.open('.ruby-version', 'rb') { |f| f.read.chomp }
ruby File.open(".ruby-version", "rb") { |f| f.read.chomp }

gem 'awesome_print'
gem 'pry', '~> 0.12.0'
gem 'rspec', '~> 3.8.0'
gem 'rubocop', '~> 0.60'
gem "awesome_print"
gem "pry", "~> 0.12.0"
gem "rspec", "~> 3.8.0"
gem "rubocop", "~> 1.69.2"
gem "rubocop-rake", "~> 0.6.0"
gem "rubocop-rspec", "~> 3.2.0"
49 changes: 31 additions & 18 deletions 2021/ruby/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ GEM
ast (2.4.2)
awesome_print (1.9.2)
coderay (1.1.3)
diff-lcs (1.4.4)
diff-lcs (1.5.1)
json (2.9.0)
language_server-protocol (3.17.0.3)
method_source (0.9.2)
parallel (1.21.0)
parser (3.0.3.1)
parallel (1.26.3)
parser (3.3.6.0)
ast (~> 2.4.1)
racc
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rainbow (3.0.0)
regexp_parser (2.1.1)
rexml (3.2.5)
racc (1.8.1)
rainbow (3.1.1)
regexp_parser (2.9.3)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
Expand All @@ -28,31 +31,41 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.3)
rubocop (0.93.1)
rubocop (1.69.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 2.7.1.5)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8)
rexml
rubocop-ast (>= 0.6.0)
regexp_parser (>= 2.9.3, < 3.0)
rubocop-ast (>= 1.36.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (1.14.0)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
unicode-display_width (1.8.0)
unicode-display_width (>= 2.4.0, < 4.0)
rubocop-ast (1.37.0)
parser (>= 3.3.1.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (3.2.0)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
unicode-display_width (3.1.2)
unicode-emoji (~> 4.0, >= 4.0.4)
unicode-emoji (4.0.4)

PLATFORMS
arm64-darwin-24
x86_64-linux

DEPENDENCIES
awesome_print
pry (~> 0.12.0)
rspec (~> 3.8.0)
rubocop (~> 0.60)
rubocop (~> 1.69.2)
rubocop-rake (~> 0.6.0)
rubocop-rspec (~> 3.2.0)

RUBY VERSION
ruby 3.0.2p107
ruby 3.3.6p108

BUNDLED WITH
2.2.22
18 changes: 8 additions & 10 deletions 2021/ruby/lib/advent_02.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class DepthCalculator
def initialize(data)
@data = data
Expand All @@ -8,18 +7,18 @@ def initialize(data)

def process_action(action, amount)
case action
when 'forward'
when "forward"
@horizontal_position += amount
when 'down'
when "down"
@depth += amount
when 'up'
when "up"
@depth -= amount
end
end

def process
@data.each do |line|
action, amount = line.split(' ')
action, amount = line.split(" ")
amount = amount.to_i
process_action(action, amount)
end
Expand All @@ -30,7 +29,6 @@ def product
end
end


class AimCalculator
def initialize(data)
@data = data
Expand All @@ -41,19 +39,19 @@ def initialize(data)

def process_action(action, amount)
case action
when 'forward'
when "forward"
@horizontal_position += amount
@depth += (@aim * amount)
when 'down'
when "down"
@aim += amount
when 'up'
when "up"
@aim -= amount
end
end

def process
@data.each do |line|
action, amount = line.split(' ')
action, amount = line.split(" ")
amount = amount.to_i
process_action(action, amount)
end
Expand Down
12 changes: 6 additions & 6 deletions 2021/ruby/lib/advent_03.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@ def least_common_bit(data, index)

def episolon_rate
result = (0...@word_length).map { |index| least_common_bit(@data, index) }
result.join('').to_i(2)
result.join("").to_i(2)
end

def gamma_rate
result = (0...@word_length).map { |index| most_common_bit(@data, index) }
result.join('').to_i(2)
result.join("").to_i(2)
end

def power_consumption
episolon_rate * gamma_rate
end

def determine_rating(data, use_most_common_bit = true, index = 0)
return 0 if data.length.zero?
def determine_rating(data, use_most_common_bit: true, index: 0)
return 0 if data.empty?
return data[0].to_i(2) if data.length == 1

bit = use_most_common_bit ? most_common_bit(data, index) : least_common_bit(data, index)
data.select! { |e| e[index] == bit.to_s }
index += 1

determine_rating(data, use_most_common_bit, index)
determine_rating(data, use_most_common_bit: use_most_common_bit, index: index)
end

def oxygen_generator_rating
Expand All @@ -61,7 +61,7 @@ def oxygen_generator_rating

def co2_scubber_rating
to_process = @data.map(&:clone)
determine_rating(to_process, false)
determine_rating(to_process, use_most_common_bit: false)
end

def life_support_rating
Expand Down
12 changes: 6 additions & 6 deletions 2021/ruby/spec/advent_01_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require 'spec_helper'
require 'advent_01'
require "spec_helper"
require "advent_01"

describe 'DepthCounter' do
describe "DepthCounter" do
let(:puzzle_input) do
File.readlines('./spec/fixtures/advent-01.txt').map(&:to_i)
File.readlines("./spec/fixtures/advent-01.txt").map(&:to_i)
end

it 'counts the number of increased measurements' do
it "counts the number of increased measurements" do
count = DepthCounter.new(puzzle_input).total_increments
expect(count).to be(1754)
end

it 'counts using window measurement' do
it "counts using window measurement" do
count = DepthCounter.new(puzzle_input).total_window_measurement_increments

expect(count).to be(1789)
Expand Down
Loading
Loading