Skip to content

Commit 80ab411

Browse files
Merge pull request #3 from invalidusrname/test-2021-workflow
shared action improvements
2 parents 6eaa712 + 48ab8fd commit 80ab411

File tree

13 files changed

+144
-101
lines changed

13 files changed

+144
-101
lines changed

.github/shared/setup/action.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
name: "setup ruby"
2-
description: "setup ruby"
3-
1+
name: setup ruby
2+
description: setup ruby
3+
inputs:
4+
working-directory:
5+
description: directory to use
6+
required: true
47
runs:
5-
using: "composite"
8+
using: composite
69
steps:
710
- name: Set up Ruby
811
uses: ruby/setup-ruby@v1
912
with:
1013
bundler-cache: true
11-
working-directory: ./2024/ruby
14+
working-directory: ${{ inputs.working-directory }}

.github/workflows/2021-ruby.yaml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,25 @@ defaults:
1212
working-directory: ./2021/ruby
1313

1414
jobs:
15+
lint:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: debug
20+
run: pwd
21+
- name: Setup Ruby
22+
uses: ./.github/shared/setup
23+
with:
24+
working-directory: ./2021/ruby
25+
- name: Run rubocop
26+
run: bundle exec rubocop
1527
tests:
1628
runs-on: ubuntu-latest
1729
steps:
18-
- uses: actions/checkout@v3
19-
- name: Determine ruby version
20-
id: determine-ruby-version
21-
run: |
22-
VERSION=$(cat .ruby-version)
23-
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT"
24-
- name: Set up Ruby
25-
uses: ruby/setup-ruby@v1
26-
with:
27-
ruby-version: ${{ steps.determine-ruby-version.outputs.VERSION }}
28-
bundler-cache: true
29-
working-directory: ./2021/ruby
30-
- name: Run tests
31-
run: bundle exec rspec
30+
- uses: actions/checkout@v3
31+
- name: Setup Ruby
32+
uses: ./.github/shared/setup
33+
with:
34+
working-directory: ./2021/ruby
35+
- name: Run tests
36+
run: bundle exec rspec

.github/workflows/2024-ruby.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ jobs:
1717
- uses: actions/checkout@v3
1818
- name: Setup Ruby
1919
uses: ./.github/shared/setup
20+
with:
21+
working-directory: ./2024/ruby
2022
- name: Run rubocop
2123
run: bundle exec rubocop
2224
tests:
@@ -25,5 +27,7 @@ jobs:
2527
- uses: actions/checkout@v3
2628
- name: Setup Ruby
2729
uses: ./.github/shared/setup
30+
with:
31+
working-directory: ./2024/ruby
2832
- name: Run tests
2933
run: bundle exec rspec

2021/ruby/.rubocop.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
require:
2+
- rubocop-rspec
3+
- rubocop-rake
4+
15
AllCops:
26
Exclude:
37
- bin/**/*
@@ -8,13 +12,18 @@ Style/Documentation:
812
Style/FrozenStringLiteralComment:
913
Enabled: false
1014
Style/StringLiterals:
11-
Enabled: false
15+
Enabled: true
16+
EnforcedStyle: double_quotes
1217
Style/TrailingCommaInHashLiteral:
1318
Enabled: false
1419
Style/NumericPredicate:
1520
Enabled: false
1621
Metrics/BlockLength:
1722
Exclude:
1823
- spec/**/*
24+
RSpec/ExampleLength:
25+
Max: 20
26+
RSpec/MultipleExpectations:
27+
Enabled: false
1928

2029
inherit_from: .rubocop_todo.yml

2021/ruby/.rubocop_todo.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2024-12-16 16:59:11 UTC using RuboCop version 1.69.2.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 1
10+
RSpec/MultipleDescribes:
11+
Exclude:
12+
- 'spec/advent_02_spec.rb'
13+
14+
# Offense count: 1
15+
# This cop supports safe autocorrection (--autocorrect).
16+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
17+
# URISchemes: http, https
18+
Layout/LineLength:
19+
Max: 122

2021/ruby/.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.2
1+
3.3.6

2021/ruby/Gemfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

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

7-
gem 'awesome_print'
8-
gem 'pry', '~> 0.12.0'
9-
gem 'rspec', '~> 3.8.0'
10-
gem 'rubocop', '~> 0.60'
7+
gem "awesome_print"
8+
gem "pry", "~> 0.12.0"
9+
gem "rspec", "~> 3.8.0"
10+
gem "rubocop", "~> 1.69.2"
11+
gem "rubocop-rake", "~> 0.6.0"
12+
gem "rubocop-rspec", "~> 3.2.0"

2021/ruby/Gemfile.lock

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,20 @@ GEM
44
ast (2.4.2)
55
awesome_print (1.9.2)
66
coderay (1.1.3)
7-
diff-lcs (1.4.4)
7+
diff-lcs (1.5.1)
8+
json (2.9.0)
9+
language_server-protocol (3.17.0.3)
810
method_source (0.9.2)
9-
parallel (1.21.0)
10-
parser (3.0.3.1)
11+
parallel (1.26.3)
12+
parser (3.3.6.0)
1113
ast (~> 2.4.1)
14+
racc
1215
pry (0.12.2)
1316
coderay (~> 1.1.0)
1417
method_source (~> 0.9.0)
15-
rainbow (3.0.0)
16-
regexp_parser (2.1.1)
17-
rexml (3.2.5)
18+
racc (1.8.1)
19+
rainbow (3.1.1)
20+
regexp_parser (2.9.3)
1821
rspec (3.8.0)
1922
rspec-core (~> 3.8.0)
2023
rspec-expectations (~> 3.8.0)
@@ -28,31 +31,41 @@ GEM
2831
diff-lcs (>= 1.2.0, < 2.0)
2932
rspec-support (~> 3.8.0)
3033
rspec-support (3.8.3)
31-
rubocop (0.93.1)
34+
rubocop (1.69.2)
35+
json (~> 2.3)
36+
language_server-protocol (>= 3.17.0)
3237
parallel (~> 1.10)
33-
parser (>= 2.7.1.5)
38+
parser (>= 3.3.0.2)
3439
rainbow (>= 2.2.2, < 4.0)
35-
regexp_parser (>= 1.8)
36-
rexml
37-
rubocop-ast (>= 0.6.0)
40+
regexp_parser (>= 2.9.3, < 3.0)
41+
rubocop-ast (>= 1.36.2, < 2.0)
3842
ruby-progressbar (~> 1.7)
39-
unicode-display_width (>= 1.4.0, < 2.0)
40-
rubocop-ast (1.14.0)
41-
parser (>= 3.0.1.1)
42-
ruby-progressbar (1.11.0)
43-
unicode-display_width (1.8.0)
43+
unicode-display_width (>= 2.4.0, < 4.0)
44+
rubocop-ast (1.37.0)
45+
parser (>= 3.3.1.0)
46+
rubocop-rake (0.6.0)
47+
rubocop (~> 1.0)
48+
rubocop-rspec (3.2.0)
49+
rubocop (~> 1.61)
50+
ruby-progressbar (1.13.0)
51+
unicode-display_width (3.1.2)
52+
unicode-emoji (~> 4.0, >= 4.0.4)
53+
unicode-emoji (4.0.4)
4454

4555
PLATFORMS
56+
arm64-darwin-24
4657
x86_64-linux
4758

4859
DEPENDENCIES
4960
awesome_print
5061
pry (~> 0.12.0)
5162
rspec (~> 3.8.0)
52-
rubocop (~> 0.60)
63+
rubocop (~> 1.69.2)
64+
rubocop-rake (~> 0.6.0)
65+
rubocop-rspec (~> 3.2.0)
5366

5467
RUBY VERSION
55-
ruby 3.0.2p107
68+
ruby 3.3.6p108
5669

5770
BUNDLED WITH
5871
2.2.22

2021/ruby/lib/advent_02.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
class DepthCalculator
32
def initialize(data)
43
@data = data
@@ -8,18 +7,18 @@ def initialize(data)
87

98
def process_action(action, amount)
109
case action
11-
when 'forward'
10+
when "forward"
1211
@horizontal_position += amount
13-
when 'down'
12+
when "down"
1413
@depth += amount
15-
when 'up'
14+
when "up"
1615
@depth -= amount
1716
end
1817
end
1918

2019
def process
2120
@data.each do |line|
22-
action, amount = line.split(' ')
21+
action, amount = line.split(" ")
2322
amount = amount.to_i
2423
process_action(action, amount)
2524
end
@@ -30,7 +29,6 @@ def product
3029
end
3130
end
3231

33-
3432
class AimCalculator
3533
def initialize(data)
3634
@data = data
@@ -41,19 +39,19 @@ def initialize(data)
4139

4240
def process_action(action, amount)
4341
case action
44-
when 'forward'
42+
when "forward"
4543
@horizontal_position += amount
4644
@depth += (@aim * amount)
47-
when 'down'
45+
when "down"
4846
@aim += amount
49-
when 'up'
47+
when "up"
5048
@aim -= amount
5149
end
5250
end
5351

5452
def process
5553
@data.each do |line|
56-
action, amount = line.split(' ')
54+
action, amount = line.split(" ")
5755
amount = amount.to_i
5856
process_action(action, amount)
5957
end

2021/ruby/lib/advent_03.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ def least_common_bit(data, index)
3131

3232
def episolon_rate
3333
result = (0...@word_length).map { |index| least_common_bit(@data, index) }
34-
result.join('').to_i(2)
34+
result.join("").to_i(2)
3535
end
3636

3737
def gamma_rate
3838
result = (0...@word_length).map { |index| most_common_bit(@data, index) }
39-
result.join('').to_i(2)
39+
result.join("").to_i(2)
4040
end
4141

4242
def power_consumption
4343
episolon_rate * gamma_rate
4444
end
4545

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

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

54-
determine_rating(data, use_most_common_bit, index)
54+
determine_rating(data, use_most_common_bit: use_most_common_bit, index: index)
5555
end
5656

5757
def oxygen_generator_rating
@@ -61,7 +61,7 @@ def oxygen_generator_rating
6161

6262
def co2_scubber_rating
6363
to_process = @data.map(&:clone)
64-
determine_rating(to_process, false)
64+
determine_rating(to_process, use_most_common_bit: false)
6565
end
6666

6767
def life_support_rating

0 commit comments

Comments
 (0)